diff --git a/extensions/chromium/runet-censorship-bypass-light/assets-sources.txt b/extensions/chromium/runet-censorship-bypass-light/assets-sources.txt new file mode 100644 index 0000000..8d36938 --- /dev/null +++ b/extensions/chromium/runet-censorship-bypass-light/assets-sources.txt @@ -0,0 +1 @@ +Blue Ribbon Icon: http://www.iconsdb.com/icon-sets/cardboard-blue-icons/ribbon-12-icon.html \ No newline at end of file diff --git a/extensions/chromium/runet-censorship-bypass-light/extension/00-init-apis.js b/extensions/chromium/runet-censorship-bypass-light/extension/00-init-apis.js new file mode 100644 index 0000000..deeea8e --- /dev/null +++ b/extensions/chromium/runet-censorship-bypass-light/extension/00-init-apis.js @@ -0,0 +1,33 @@ +'use strict'; + +window.utils = { + + areSettingsNotControlledFor(details) { + + return ['controlled_by_other', 'not_controllable'] + .some( (prefix) => details.levelOfControl.startsWith(prefix) ); + + }, + + messages: { + + searchSettingsForUrl(niddle) { + + return 'chrome://settings/search#' + (chrome.i18n.getMessage(niddle) || niddle); + + }, + + whichExtensionHtml() { + + return chrome.i18n.getMessage('noControl') + + ` + ${ chrome.i18n.getMessage('which') } + `; + + }, + + }, + +}; + +window.apis = {}; diff --git a/extensions/chromium/runet-censorship-bypass-light/extension/12-set-pac-url.js b/extensions/chromium/runet-censorship-bypass-light/extension/12-set-pac-url.js new file mode 100644 index 0000000..42bb04b --- /dev/null +++ b/extensions/chromium/runet-censorship-bypass-light/extension/12-set-pac-url.js @@ -0,0 +1,91 @@ +'use strict'; + +window.state = { + lastError: null, + ifNotControlled: false +}; + +function redBadge(msg) { + + window.chrome.browserAction.setBadgeBackgroundColor({ + color: '#db4b2f', + }); + chrome.browserAction.setBadgeText({ + text: msg, + }); + +} + +let defaultColorPromise = new Promise( function (resolve) { + + chrome.browserAction.getBadgeBackgroundColor({}, resolve); + +}); + +function okBadge(msg) { + + defaultColorPromise.then( function (defaultColor) { + window.chrome.browserAction.setBadgeBackgroundColor({ + color: defaultColor, + }); + chrome.browserAction.setBadgeText({ + text: msg, + }); + }); + +} + +function checkControlFor(details) { + + state.ifNotControlled = utils.areSettingsNotControlledFor(details); + if (state.ifNotControlled) { + console.warn('Failed, other extension is in control.'); + redBadge('xCTRL'); + } else { + console.log('Successfuly set PAC in proxy settings..'); + okBadge('ok'); + } + +} + +chrome.proxy.settings.onChange.addListener( checkControlFor ); + +chrome.proxy.onProxyError.addListener((details) => { + + console.error(details); + //if (window.state.ifNotControlled) { + // return; + //} +}); + +chrome.proxy.settings.set( + { + value: { + mode: 'pac_script', + pacScript: { + /* + Don't use in system configs! Because Win does poor caching. + Url is encoded to counter abuse. + Source: CloudFlare + */ + //url: 'https://anticensorship-russia.tk/generated-pac-scripts/on-switches-0.17.pac', + //url: 'https://antizapret.prostovpn.org/proxy.pac', + url: 'http://localhost:8080/on-switches-0.17.pac', + mandatory: true + //url: '\x68\x74\x74\x70\x73\x3a\x2f\x2f\x61\x6e\x74\x69\x63\x65\x6e\x73\x6f\x72\x73\x68\x69\x70\x2d\x72\x75\x73\x73\x69\x61\x2e\x74\x6b\x2f\x67\x65\x6e\x65\x72\x61\x74\x65\x64\x2d\x70\x61\x63\x2d\x73\x63\x72\x69\x70\x74\x73\x2f\x6f\x6e\x2d\x73\x77\x69\x74\x63\x68\x65\x73\x2d\x30\x2e\x31\x37\x2e\x70\x61\x63', + }, + }, + }, + function() { + + const err = chrome.runtime.lastError || chrome.extension.lastError; + if(err) { + alert(333) + redBadge('ERR'); + } else { + alert(11); + chrome.proxy.settings.get({}, checkControlFor); + } + + } +); diff --git a/extensions/chromium/runet-censorship-bypass-light/extension/40-context-menus.js b/extensions/chromium/runet-censorship-bypass-light/extension/40-context-menus.js new file mode 100644 index 0000000..2db6a12 --- /dev/null +++ b/extensions/chromium/runet-censorship-bypass-light/extension/40-context-menus.js @@ -0,0 +1,49 @@ +'use strict'; + +{ + + const createMenuLinkEntry = (title, tab2url) => chrome.contextMenus.create({ + title: title, + contexts: ['browser_action'], + onclick: + (menuInfo, tab) => Promise.resolve( tab2url( tab ) ) + .then( (url) => chrome.tabs.create({url: url}) ), + }); + + createMenuLinkEntry( + 'Сайт доступен из-за границы? Is up?', + (tab) => `data:text/html;charset=utf8,Запрашиваю... +
+ +
+ + + diff --git a/extensions/chromium/runet-censorship-bypass-light/extension/pages/show-state/index.js b/extensions/chromium/runet-censorship-bypass-light/extension/pages/show-state/index.js new file mode 100644 index 0000000..0d55e8e --- /dev/null +++ b/extensions/chromium/runet-censorship-bypass-light/extension/pages/show-state/index.js @@ -0,0 +1,33 @@ +'use strict'; + +chrome.runtime.getBackgroundPage( (backgroundPage) => { + + const state = backgroundPage.state; + + if( state.ifNotControlled ) { + document.getElementById('which-extension').innerHTML + = backgroundPage.utils.messages.whichExtensionHtml(); + document.querySelectorAll('.if-not-controlled').forEach( (node) => { + + node.style.display = 'block'; + + }); + } + + if (state.lastError) { + + document.querySelectorAll('.if-error').forEach( (node) => { + + node.style.display = 'block'; + + }); + document.getElementById('last-error').innerHTML = state.lastError; + } + + document.documentElement.style.display = ''; + + // CLOSE BUTTON + + document.querySelector('.close-button').onclick = () => window.close(); + +}); diff --git a/extensions/chromium/runet-censorship-bypass/extension/11-api-error-handlers.js b/extensions/chromium/runet-censorship-bypass/extension/11-api-error-handlers.js index 05358a4..e523b0f 100644 --- a/extensions/chromium/runet-censorship-bypass/extension/11-api-error-handlers.js +++ b/extensions/chromium/runet-censorship-bypass/extension/11-api-error-handlers.js @@ -217,7 +217,7 @@ chrome.proxy.onProxyError.addListener((details) => { - if (handlers.ifNoControl) { + if (handlers.ifNotControlled) { return; } /* diff --git a/extensions/chromium/runet-censorship-bypass/extension/12-api-sync-pac-script-with-pac-provider.js b/extensions/chromium/runet-censorship-bypass/extension/12-api-sync-pac-script-with-pac-provider.js index c458cb3..399f198 100644 --- a/extensions/chromium/runet-censorship-bypass/extension/12-api-sync-pac-script-with-pac-provider.js +++ b/extensions/chromium/runet-censorship-bypass/extension/12-api-sync-pac-script-with-pac-provider.js @@ -546,6 +546,7 @@ function ifModifiedSince(url, lastModified = mandatory(), cb = mandatory()) { + const nowModified = new Date(0).toUTCString(); fetch(url, { method: 'HEAD', headers: new Headers({ @@ -553,11 +554,9 @@ }) }).then( (res) => { - console.log('HEAD', res); - window.R = res; - cb(null, res.status === 304 ? false : (res.headers.get('Last-Modified') || new Date(0).toUTCString()) ); + cb(null, res.status === 304 ? false : (res.headers.get('Last-Modified') || nowModified) ); }, - clarifyFetchErrorThen(cb) + clarifyFetchErrorThen((err) => cb(err, nowModified)) ); } @@ -709,26 +708,43 @@ ); } - httpGet( - pacUrl, - (err, pacData) => { + // Employ all urls, the latter are fallbacks for the former. + let pacDataPromise = Promise.reject(); + for(const url of provider.pacUrls) { + + pacDataPromise = pacDataPromise.catch( + (err) => new Promise( + (resolve, reject) => httpGet( + url, + (newErr, pacData) => newErr ? reject(newErr) : resolve(pacData) + ) + ) + ); + + } + + pacDataPromise.then( + (pacData) => { - if (err) { - err.clarification = { - message: 'Не удалось скачать PAC-скрипт с адреса: ' - + provider.pacUrl + '.', - prev: err.clarification, - }; - return cb(err); - } setPacAsync( {pacData, pacUrl}, (err, res) => cb( err, Object.assign(res || {}, {lastModified: newLastModified}) ) ); + }, + (err) => { + + err.clarification = { + message: 'Не удалось скачать PAC-скрипт с адресов: [ ' + + provider.pacUrls.join(' , ') + ' ].', + prev: err.clarification, + }; + return cb(err); + } ); - }) + + }); }