Exert all pac urls, be robust on errors, fix typos, add light version (broken)

This commit is contained in:
Ilya Ig. Petrov 2017-01-03 18:03:03 +00:00
parent 88ef40da5e
commit 797ef68397
13 changed files with 356 additions and 17 deletions

View File

@ -0,0 +1 @@
Blue Ribbon Icon: http://www.iconsdb.com/icon-sets/cardboard-blue-icons/ribbon-12-icon.html

View File

@ -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') +
` <a href="${ this.searchSettingsForUrl('proxy') }">
${ chrome.i18n.getMessage('which') }
</a>`;
},
},
};
window.apis = {};

View File

@ -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);
}
}
);

View File

@ -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,<title>Запрашиваю...</title>
<form class='tracker-form' method='POST'
action='https://www.host-tracker.com/ru/InstantCheck/Create'>
<input name='InstantCheckUrl' value='${new URL(tab.url).hostname}'
type='hidden'>
</form>
<script>document.querySelector('.tracker-form').submit()<\/script>`
);
createMenuLinkEntry(
'Сайт в реестре блокировок?',
(tab) => 'https://antizapret.info/index.php?search=' + new URL(tab.url).hostname
);
createMenuLinkEntry(
'Из архива archive.org',
(tab) => 'https://web.archive.org/web/*/' + tab.url
);
createMenuLinkEntry(
'Через Google Translate',
(tab) => 'https://translate.google.com/translate?hl=&sl=en&tl=ru&anno=2&sandbox=1&u=' + tab.url
);
createMenuLinkEntry(
'Другие варианты разблокировки',
(tab) => 'https://rebrand.ly/ac-unblock#' + tab.url
);
createMenuLinkEntry(
'У меня проблемы с расширением!',
(tab) => 'https://rebrand.ly/ac-support'
);
}

View File

@ -0,0 +1,17 @@
{
"extName": {
"message": "Light Runet Censorship Bypass"
},
"extDesc": {
"message": "Circumvent Russian Internet Censorship: https://rebrand.ly/ac-wiki"
},
"proxy": {
"message": "proxy"
},
"noControl": {
"message": "Other extension controls proxy!"
},
"which": {
"message": "Which?"
}
}

View File

@ -0,0 +1,17 @@
{
"extName": {
"message": "Облегчённый обход блокировок Рунета"
},
"extDesc": {
"message": "Обход интернет-цензуры в России: https://rebrand.ly/ac-wiki"
},
"proxy": {
"message": "прокси"
},
"noControl": {
"message": "Другое расширение контролирует настройки прокси!"
},
"which": {
"message": "Какое?"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

View File

@ -0,0 +1,39 @@
{
"manifest_version": 2,
"name": "__MSG_extName__ 0.17",
"default_locale": "ru",
"description": "__MSG_extDesc__",
"version": "0.0.0.17",
"icons": {
"128": "/icons/default-128.png"
},
"author": "ilyaigpetrov@gmail.com",
"homepage_url": "https://github.com/anticensorship-russia/chromium-extension",
"permissions": [
"proxy",
"alarms",
"storage",
"<all_urls>",
"tabs",
"contextMenus",
"notifications"
],
"background": {
"persistent": true,
"scripts": [
"00-init-apis.js",
"12-set-pac-url.js"
]
},
"browser_action": {
"default_title": "Этот сайт благословлён 0.17",
"default_popup": "pages/show-state/index.html"
},
"options_ui": {
"page": "pages/show-state/index.html",
"chrome_style": true
}
}

View File

@ -0,0 +1,43 @@
<!DOCTYPE html>
<html style="display: none">
<head>
<title>Выбор провайдера PAC</title>
<style>
footer {
display: block;
white-space: nowrap;
word-break: keep-all;
}
footer {
margin: 2em 1em 1em;
}
hr {
border-width: 1px 0 0 0;
margin: 0.6em 0;
padding: 0;
}
.if-not-controlled {
display: none;
color: red;
}
</style>
</head>
<body>
<header>
Обход блокировок Рунета облегчённый
</header>
<span class="if-not-controlled">
<span id="which-extension"></span>
<hr style="border-color: red; border-style: solid;"/>
</span>
<span class="if-error">
<span id="last-error"></span>
<hr style="border-color: red; border-style: solid;"/>
</span>
<hr/>
<footer>
<input type="button" value="Готово" class="close-button">&nbsp;<a href="../debug/index.html" style="text-decoration: none; margin-left: 1em;">Полная версия расширения</a>
</footer>
<script src="./index.js"></script>
</body>
</html>

View File

@ -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();
});

View File

@ -217,7 +217,7 @@
chrome.proxy.onProxyError.addListener((details) => {
if (handlers.ifNoControl) {
if (handlers.ifNotControlled) {
return;
}
/*

View File

@ -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);
}
);
})
});
}