pac-setter hits 0.0.0.4

This commit is contained in:
Ilya Ig. Petrov 2016-01-18 00:27:54 +05:00
parent c8fd652ab4
commit 7947a01d73
4 changed files with 71 additions and 40 deletions

View File

@ -9,7 +9,7 @@ function getHostname(url) {
} }
function blockInform(details) { function blockInform(details) {
if (details.tabId !== -1 && window.antiCensorRu.pacProvider && window.antiCensorRu.pacProvider.proxyIp && details.ip === window.antiCensorRu.pacProvider.proxyIp) { if (details.tabId !== -1 && window.antiCensorRu.pacProvider && window.antiCensorRu.pacProvider.proxyIps && window.antiCensorRu.pacProvider.proxyIps[ details.ip ]) {
chrome.pageAction.setIcon({ chrome.pageAction.setIcon({
path: '/icons/rkn-empty.png', path: '/icons/rkn-empty.png',

View File

@ -2,8 +2,8 @@
"manifest_version": 2, "manifest_version": 2,
"name": "Ненавязчивый РосКомНадзор", "name": "Ненавязчивый РосКомНадзор",
"description": "Потому что хорошее ценрзурирование -- это слишком сложно.y", "description": "Аргументы против цензуры: https://git.io/vEkI9",
"version": "0.0.0.3", "version": "0.0.0.4",
"icons": { "icons": {
"128": "/icons/rkn-empty.png" "128": "/icons/rkn-empty.png"
}, },

View File

@ -19,28 +19,41 @@ chrome.runtime.getBackgroundPage( backgroundPage => {
ul.insertBefore( li, _firstChild ); ul.insertBefore( li, _firstChild );
} }
var checkChosenProvider = () => { var targetRadio = () => {
var id = antiCensorRu.currentPacProviderKey || 'none'; var id = antiCensorRu.currentPacProviderKey || 'none';
var checkedRadio = document.querySelector('#'+id); return document.querySelector('#'+id);
checkedRadio.checked = true; }
var checkChosenProvider = () => {
targetRadio().checked = true;
}
var triggerChosenProvider = () => {
var event = document.createEvent('HTMLEvents'); var event = document.createEvent('HTMLEvents');
event.initEvent('change', false, true); event.initEvent('change', false, true);
checkedRadio.dispatchEvent(event); targetRadio().dispatchEvent(event);
} }
checkChosenProvider();
setStatusTo('');
var radios = [].slice.apply( document.querySelectorAll('[name=pacProvider]') ); var radios = [].slice.apply( document.querySelectorAll('[name=pacProvider]') );
for(var radio of radios) { for(var radio of radios) {
radio.onchange = function(event) { radio.onchange = function(event) {
setStatusTo('');
var pacKey = event.target.id; var pacKey = event.target.id;
if (pacKey === 'none') if (pacKey === 'none')
return antiCensorRu.clearPac( () => window && window.close() ); return antiCensorRu.clearPac( () => window && window.close() );
function switchInputs() {
var inputs = document.querySelectorAll('[name="pacProvider"]');
for (var i = 0; i < inputs.length; i++)
inputs[i].disabled = !inputs[i].disabled;
}
switchInputs();
setStatusTo('Установка...'); setStatusTo('Установка...');
antiCensorRu.installPac(pacKey, () => { setStatusTo('PAC-скрипт установлен.'); if(window) window.close(); }); antiCensorRu.installPac(pacKey, () => { setStatusTo('PAC-скрипт установлен.'); if(window) window.close(); });
} }
} }
setStatusTo('');
checkChosenProvider();
if (antiCensorRu.ifNotInstalled)
triggerChosenProvider();
}); });

View File

@ -23,16 +23,20 @@ window.antiCensorRu = {
pacProviders: { pacProviders: {
Антизапрет: { Антизапрет: {
pacUrl: 'http://antizapret.prostovpn.org/proxy.pac', pacUrl: 'http://antizapret.prostovpn.org/proxy.pac',
proxyHost: 'proxy.antizapret.prostovpn.org', proxyHosts: ['proxy.antizapret.prostovpn.org'],
proxyIp: '195.154.110.37' proxyIps: {'195.154.110.37': true}
}, },
Антиценз: { Антиценз: {
pacUrl: 'https://config.anticenz.org/proxy.pac', pacUrl: 'https://config.anticenz.org/proxy.pac',
proxyHost: 'gw2.anticenz.org' proxyHosts: ['gw2.anticenz.org']
},
Обаа_свитчах: {
pacUrl: 'https://drive.google.com/uc?export=download&id=0B-ZCVSvuNWf0akpCOURNS2VCTmc',
proxyHosts: ['gw2.anticenz.org', 'proxy.antizapret.prostovpn.org']
} }
}, },
_currentPacProviderKey: 'Антиценз', _currentPacProviderKey: 'Оба_и_на_свитчах',
get currentPacProviderKey() { return this._currentPacProviderKey }, get currentPacProviderKey() { return this._currentPacProviderKey },
set currentPacProviderKey(newKey) { set currentPacProviderKey(newKey) {
@ -71,7 +75,7 @@ window.antiCensorRu = {
setPacScriptFromProvider( setPacScriptFromProvider(
this.pacProvider, this.pacProvider,
() => { () => {
updatePacProxyIp( updatePacProxyIps(
this.pacProvider, this.pacProvider,
() => { () => {
this.ifNotInstalled = false; this.ifNotInstalled = false;
@ -82,6 +86,7 @@ window.antiCensorRu = {
}, },
installPac(key, cb) { installPac(key, cb) {
if(typeof(key) === 'function') { if(typeof(key) === 'function') {
cb = key; cb = key;
key = undefined; key = undefined;
@ -101,7 +106,7 @@ window.antiCensorRu = {
); );
chrome.alarms.create(reason, { chrome.alarms.create(reason, {
periodInMinutes: 2*60 periodInMinutes: 4*60
}); });
this.syncWithPacProvider(cb); this.syncWithPacProvider(cb);
@ -120,22 +125,23 @@ window.antiCensorRu = {
}; };
window.antiCensorRu.pullFromStorage( chrome.runtime.onStartup.addListener( () => {
() => console.log('Starting...');
chrome.storage.onChanged.addListener( () => window.antiCensorRu.pullFromStorage() ) window.antiCensorRu.pullFromStorage(
) () =>
chrome.storage.onChanged.addListener( () => window.antiCensorRu.pullFromStorage() )
)
});
chrome.runtime.onInstalled.addListener( details => { chrome.runtime.onInstalled.addListener( details => {
console.log('Installing...');
switch(details.reason) { switch(details.reason) {
case 'update':
window.antiCensorRu.installPac();
break;
case 'install': case 'install':
case 'update': window.antiCensorRu.ifNotInstalled = true;
window.antiCensorRu.pullFromStorage( chrome.runtime.openOptionsPage();
() => {
window.antiCensorRu.ifNotInstalled = true;
window.antiCensorRu.installPac();
//chrome.runtime.openOptionsPage();
}
)
} }
}); });
@ -159,7 +165,7 @@ function httpGet(url, cb) {
var ifAsync = true; var ifAsync = true;
req.open('GET', url, ifAsync); req.open('GET', url, ifAsync);
req.onload = event => { req.onload = event => {
if (req.status === 404) if (req.status !== 200)
return cb(event); return cb(event);
console.log('GETed with success.'); console.log('GETed with success.');
return cb(null, req.responseText) return cb(null, req.responseText)
@ -168,20 +174,32 @@ function httpGet(url, cb) {
req.send(); req.send();
} }
function updatePacProxyIp(provider, cb) { function updatePacProxyIps(provider, cb) {
var cb = asyncLogGroup('Getting IP for '+ provider.proxyHost +'...', cb); if (!provider.proxyHosts) {
httpGet( console.log(provider+' has no proxies defined.');
'http://www.dns-lg.com/google1/'+ provider.proxyHost +'/A', return cb(null, null);
(err, res) => { }
if (!err) var cb = asyncLogGroup('Getting IP for '+ provider.proxyHosts.join(', ') +'...', cb);
provider.proxyIp = JSON.parse(res).answer[0].rdata; var i = 0;
return cb(err, res); for (var proxyHost of provider.proxyHosts) {
} httpGet(
); 'http://www.dns-lg.com/google1/'+ proxyHost +'/A',
(err, res) => {
if (!err) {
provider.proxyIps = provider.proxyIps || {};
provider.proxyIps[ JSON.parse(res).answer[0].rdata ] = true;
}
++i;
if ( i == provider.proxyHosts.length )
return cb(err, 'Complete.');
}
);
}
} }
function setPacScriptFromProvider(provider, cb) { function setPacScriptFromProvider(provider, cb) {
var cb = asyncLogGroup('Getting pac script from provider...', provider.pacUrl, cb); var cb = asyncLogGroup('Getting pac script from provider...', provider.pacUrl, cb);
httpGet( httpGet(
provider.pacUrl, provider.pacUrl,
(err, res) => { (err, res) => {