pac-setter hits 0.0.0.2: more transparent code

This commit is contained in:
Ilya Ig. Petrov 2015-12-12 16:54:33 +05:00
parent 64af23564b
commit 1cb31c79a5
9 changed files with 109 additions and 52 deletions

View File

@ -0,0 +1,11 @@
Обход Интернет-цензуры в России пока что не является нарушением закона.
Расширение позволяет обходить блокировки РосКомНадзора, давая вам доступ
к библиотекам, энциклопедиям и сайтам оппоцизионного движения в России.
Проксирует только заблокированные сайты, оставляя нетронутыми все остальные.
Известные недостатки: ресурсы с динамичным IP, попадающих под блокировку, некорректно проксируются. Непричастные к блокировкам сайты рушатся.
Неофициальное расширение на базе antizapret.prostovpn.org
Обновляет PAC-скрипт каждые два часа.

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

View File

@ -0,0 +1,54 @@
'use strict';
// Shows user PageAction icon if any part of the current site is being blocked and proxied.
function getHostname(url) {
var a = document.createElement('a');
a.href = url;
return a.hostname;
}
function blockInform(details) {
if (details.tabId !== -1 && details.ip === antizapret.proxyIp) {
chrome.pageAction.setIcon({
path: '/icons/rkn-empty.png',
tabId: details.tabId
});
chrome.pageAction.getTitle(
{ tabId: details.tabId },
result => {
if (!/\n/.test(result))
result = 'Разблокированы:';
var hostname = getHostname(details.url).trim();
var ifListed = result.split(/\r?\n/g).some(
line => line.trim() === hostname
);
if (!ifListed)
chrome.pageAction.setTitle({
title: result +'\n'+ hostname,
tabId: details.tabId
});
}
);
chrome.pageAction.show(details.tabId);
}
}
chrome.webRequest.onCompleted.addListener(
blockInform,
{ urls: ['<all_urls>'] }
);
chrome.webRequest.onErrorOccurred.addListener(
blockInform,
{ urls: ['<all_urls>'] }
);

View File

Before

Width:  |  Height:  |  Size: 7.7 KiB

After

Width:  |  Height:  |  Size: 7.7 KiB

View File

Before

Width:  |  Height:  |  Size: 7.1 KiB

After

Width:  |  Height:  |  Size: 7.1 KiB

View File

Before

Width:  |  Height:  |  Size: 7.8 KiB

After

Width:  |  Height:  |  Size: 7.8 KiB

View File

@ -3,7 +3,12 @@
"name": "Антизапрет",
"description": "Безопасный Интернет с возможностью отказаться",
"version": "0.0.0.1",
"version": "0.0.0.2",
"icons": {
"128": "/icons/rkn-empty.png"
},
"author": "ilyaigpetrov@gmail.com",
"homepage_url": "https://github.com/ilyaigpetrov/anti-censorship-russia",
"permissions": [
"proxy",
@ -11,15 +16,8 @@
"alarms",
"<all_urls>"
],
"icons": {
"128": "/icons/rkn-empty.png"
},
"background": {
"scripts": ["install.js", "proxy.js"]
"scripts": ["sync-pac-script-with-antizapret.js", "block-informer.js"]
},
"page_action": {},
"author": "ilyaigpetrov@gmail.com",
"homepage_url": "https://github.com/ilyaigpetrov/anti-censorship-russia",
"short_name": "Антизапрет"
"page_action": {}
}

View File

@ -1,5 +1,12 @@
'use strict';
/*
Task 1. Gets IP for host proxy.antizapret.prostovpn.org with dns-lg.com.
This IP is used in block-informer to inform user when proxy is ON.
Task 2. Downloads PAC proxy script from Antizapret and sets it in Chromium settings.
Task 3. Schedules tasks 1 & 2 for every 2 hours.
*/
var antizapret = {
pacUrl: 'http://antizapret.prostovpn.org/proxy.pac',
proxyHost: 'proxy.antizapret.prostovpn.org',
@ -20,15 +27,26 @@ function httpGet(url, cb) {
req.send();
}
function UpdatePac() {
function getIpForHost(host, cb) {
httpGet(
'http://www.dns-lg.com/google1/'+antizapret.proxyHost+'/A',
'http://www.dns-lg.com/google1/'+host+'/A',
cb
);
}
function updateAntizapretProxyIp() {
getIpForHost(
antizapret.proxyHost,
(err, res) => {
if (err)
console.log(err)
else
antizapret.proxyIp = JSON.parse(res).answer[0].rdata;
}
);
}
function setPacScriptFromAntizapret() {
httpGet(
antizapret.pacUrl,
(err, res) => {
@ -48,7 +66,11 @@ function UpdatePac() {
}
);
}
function syncWithAntizapret() {
updateAntizapretProxyIp();
setPacScriptFromAntizapret();
}
chrome.runtime.onInstalled.addListener( details => {
@ -56,14 +78,15 @@ chrome.runtime.onInstalled.addListener( details => {
case 'install':
case 'update':
UpdatePac();
syncWithAntizapret();
var reason = 'Периодичное обновление PAC-скрипта Антизапрет';
chrome.alarms.onAlarm.addListener(
alarm => {
if (alarm.name === reason)
UpdatePac();
if (alarm.name === reason) {
syncWithAntizapret();
}
}
);

View File

@ -1,29 +0,0 @@
'use strict';
function blockInform(details) {
if (details.tabId !== -1 && details.ip === antizapret.proxyIp) {
chrome.pageAction.setIcon({
path: '/icons/rkn-empty.png',
tabId: details.tabId
});
chrome.pageAction.setTitle({
title: 'Сайт блокирован!',
tabId: details.tabId
});
chrome.pageAction.show(details.tabId);
}
}
chrome.webRequest.onCompleted.addListener(
blockInform,
{ urls: ['<all_urls>'] }
);
chrome.webRequest.onErrorOccurred.addListener(
blockInform,
{ urls: ['<all_urls>'] }
);