From 7947a01d73072e8db28c7f3f922178429d3c5e30 Mon Sep 17 00:00:00 2001 From: "Ilya Ig. Petrov" Date: Mon, 18 Jan 2016 00:27:54 +0500 Subject: [PATCH] pac-setter hits 0.0.0.4 --- .../extnesion/block-informer.js | 2 +- .../extnesion/manifest.json | 4 +- .../pages/choose-pac-provider/index.js | 29 +++++-- .../sync-pac-script-with-pac-provider.js | 76 ++++++++++++------- 4 files changed, 71 insertions(+), 40 deletions(-) diff --git a/extensions/chromium/minimalistic-pac-setter/extnesion/block-informer.js b/extensions/chromium/minimalistic-pac-setter/extnesion/block-informer.js index 05bdd2e..66a9d07 100755 --- a/extensions/chromium/minimalistic-pac-setter/extnesion/block-informer.js +++ b/extensions/chromium/minimalistic-pac-setter/extnesion/block-informer.js @@ -9,7 +9,7 @@ function getHostname(url) { } 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({ path: '/icons/rkn-empty.png', diff --git a/extensions/chromium/minimalistic-pac-setter/extnesion/manifest.json b/extensions/chromium/minimalistic-pac-setter/extnesion/manifest.json index d46dc08..e4a20c5 100755 --- a/extensions/chromium/minimalistic-pac-setter/extnesion/manifest.json +++ b/extensions/chromium/minimalistic-pac-setter/extnesion/manifest.json @@ -2,8 +2,8 @@ "manifest_version": 2, "name": "Ненавязчивый РосКомНадзор", - "description": "Потому что хорошее ценрзурирование -- это слишком сложно.y", - "version": "0.0.0.3", + "description": "Аргументы против цензуры: https://git.io/vEkI9", + "version": "0.0.0.4", "icons": { "128": "/icons/rkn-empty.png" }, diff --git a/extensions/chromium/minimalistic-pac-setter/extnesion/pages/choose-pac-provider/index.js b/extensions/chromium/minimalistic-pac-setter/extnesion/pages/choose-pac-provider/index.js index 07882a6..3f990c6 100755 --- a/extensions/chromium/minimalistic-pac-setter/extnesion/pages/choose-pac-provider/index.js +++ b/extensions/chromium/minimalistic-pac-setter/extnesion/pages/choose-pac-provider/index.js @@ -19,28 +19,41 @@ chrome.runtime.getBackgroundPage( backgroundPage => { ul.insertBefore( li, _firstChild ); } - var checkChosenProvider = () => { + var targetRadio = () => { var id = antiCensorRu.currentPacProviderKey || 'none'; - var checkedRadio = document.querySelector('#'+id); - checkedRadio.checked = true; + return document.querySelector('#'+id); + } + var checkChosenProvider = () => { + targetRadio().checked = true; + } + var triggerChosenProvider = () => { var event = document.createEvent('HTMLEvents'); event.initEvent('change', false, true); - checkedRadio.dispatchEvent(event); + targetRadio().dispatchEvent(event); } - checkChosenProvider(); - setStatusTo(''); - var radios = [].slice.apply( document.querySelectorAll('[name=pacProvider]') ); for(var radio of radios) { radio.onchange = function(event) { - setStatusTo(''); var pacKey = event.target.id; if (pacKey === 'none') 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('Установка...'); antiCensorRu.installPac(pacKey, () => { setStatusTo('PAC-скрипт установлен.'); if(window) window.close(); }); } } + setStatusTo(''); + checkChosenProvider(); + if (antiCensorRu.ifNotInstalled) + triggerChosenProvider(); + }); diff --git a/extensions/chromium/minimalistic-pac-setter/extnesion/sync-pac-script-with-pac-provider.js b/extensions/chromium/minimalistic-pac-setter/extnesion/sync-pac-script-with-pac-provider.js index c1fbc6d..11f0f8f 100755 --- a/extensions/chromium/minimalistic-pac-setter/extnesion/sync-pac-script-with-pac-provider.js +++ b/extensions/chromium/minimalistic-pac-setter/extnesion/sync-pac-script-with-pac-provider.js @@ -23,16 +23,20 @@ window.antiCensorRu = { pacProviders: { Антизапрет: { pacUrl: 'http://antizapret.prostovpn.org/proxy.pac', - proxyHost: 'proxy.antizapret.prostovpn.org', - proxyIp: '195.154.110.37' + proxyHosts: ['proxy.antizapret.prostovpn.org'], + proxyIps: {'195.154.110.37': true} }, Антиценз: { 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 }, set currentPacProviderKey(newKey) { @@ -71,7 +75,7 @@ window.antiCensorRu = { setPacScriptFromProvider( this.pacProvider, () => { - updatePacProxyIp( + updatePacProxyIps( this.pacProvider, () => { this.ifNotInstalled = false; @@ -82,6 +86,7 @@ window.antiCensorRu = { }, installPac(key, cb) { + if(typeof(key) === 'function') { cb = key; key = undefined; @@ -101,7 +106,7 @@ window.antiCensorRu = { ); chrome.alarms.create(reason, { - periodInMinutes: 2*60 + periodInMinutes: 4*60 }); this.syncWithPacProvider(cb); @@ -120,22 +125,23 @@ window.antiCensorRu = { }; -window.antiCensorRu.pullFromStorage( - () => - chrome.storage.onChanged.addListener( () => window.antiCensorRu.pullFromStorage() ) -) +chrome.runtime.onStartup.addListener( () => { + console.log('Starting...'); + window.antiCensorRu.pullFromStorage( + () => + chrome.storage.onChanged.addListener( () => window.antiCensorRu.pullFromStorage() ) + ) +}); chrome.runtime.onInstalled.addListener( details => { + console.log('Installing...'); switch(details.reason) { + case 'update': + window.antiCensorRu.installPac(); + break; case 'install': - case 'update': - window.antiCensorRu.pullFromStorage( - () => { - window.antiCensorRu.ifNotInstalled = true; - window.antiCensorRu.installPac(); - //chrome.runtime.openOptionsPage(); - } - ) + window.antiCensorRu.ifNotInstalled = true; + chrome.runtime.openOptionsPage(); } }); @@ -159,7 +165,7 @@ function httpGet(url, cb) { var ifAsync = true; req.open('GET', url, ifAsync); req.onload = event => { - if (req.status === 404) + if (req.status !== 200) return cb(event); console.log('GETed with success.'); return cb(null, req.responseText) @@ -168,20 +174,32 @@ function httpGet(url, cb) { req.send(); } -function updatePacProxyIp(provider, cb) { - var cb = asyncLogGroup('Getting IP for '+ provider.proxyHost +'...', cb); - httpGet( - 'http://www.dns-lg.com/google1/'+ provider.proxyHost +'/A', - (err, res) => { - if (!err) - provider.proxyIp = JSON.parse(res).answer[0].rdata; - return cb(err, res); - } - ); +function updatePacProxyIps(provider, cb) { + if (!provider.proxyHosts) { + console.log(provider+' has no proxies defined.'); + return cb(null, null); + } + var cb = asyncLogGroup('Getting IP for '+ provider.proxyHosts.join(', ') +'...', cb); + var i = 0; + 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) { var cb = asyncLogGroup('Getting pac script from provider...', provider.pacUrl, cb); + httpGet( provider.pacUrl, (err, res) => {