mirror of
https://github.com/anticensority/runet-censorship-bypass.git
synced 2024-11-24 02:13:43 +03:00
Restyle, scope vars/names out of window
This commit is contained in:
parent
05c6deadf8
commit
1ef480acd1
|
@ -13,6 +13,7 @@
|
|||
use chrome.runtime.getBackgroundPage(..),
|
||||
extension.getBackgroundPage is deprecated
|
||||
*/
|
||||
{ // Private namespace starts.
|
||||
|
||||
window.antiCensorRu = {
|
||||
|
||||
|
@ -165,8 +166,9 @@ window.antiCensorRu = {
|
|||
|
||||
let nextUpdateMoment = this.lastPacUpdateStamp + this._pacUpdatePeriodInMinutes*60*1000;
|
||||
const now = Date.now();
|
||||
if (nextUpdateMoment < now)
|
||||
if (nextUpdateMoment < now) {
|
||||
nextUpdateMoment = now;
|
||||
}
|
||||
|
||||
console.log( 'Next PAC update is scheduled on', new Date(nextUpdateMoment).toLocaleString('ru-RU') );
|
||||
|
||||
|
@ -179,6 +181,7 @@ window.antiCensorRu = {
|
|||
);
|
||||
|
||||
return nextUpdateMoment === now; // ifAlarmTriggered. May be changed in the future.
|
||||
|
||||
},
|
||||
|
||||
installPac(key, cb) {
|
||||
|
@ -239,6 +242,7 @@ chrome.storage.local.get(null, (oldStorage) => {
|
|||
console.log('Periodic PAC update triggered:', new Date().toLocaleString('ru-RU'));
|
||||
antiCensorRu.syncWithPacProvider(/* Swallows errors. */);
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
console.log('Alarm listener installed. We won\'t miss any PAC update.');
|
||||
|
@ -258,6 +262,11 @@ chrome.storage.local.get(null, (oldStorage) => {
|
|||
|
||||
if (!antiCensorRu.pacProvider) {
|
||||
return console.log('No PAC provider set. Do nothing.');
|
||||
/*
|
||||
In case of UPDATE:
|
||||
1. new providers will still be shown.
|
||||
2. new version won't be pushed to storage
|
||||
*/
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -278,10 +287,7 @@ chrome.storage.local.get(null, (oldStorage) => {
|
|||
// UPDATE & MIGRATION
|
||||
console.log('Extension updated.');
|
||||
if (!ifAlarmTriggered) {
|
||||
updatePacProxyIps(
|
||||
antiCensorRu.pacProvider,
|
||||
(ipsError) => ipsError ? console.error('Error updating IPs:', ipsError) : antiCensorRu.pushToStorage(/* Swallows errors. */)
|
||||
);
|
||||
antiCensorRu.pushToStorage(/* Swallows errors. */);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -527,6 +533,8 @@ function setPacScriptFromProvider(provider, cb) {
|
|||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
window.addEventListener('error', (err) => {
|
||||
|
||||
console.error('Global error');
|
||||
|
|
|
@ -18,9 +18,9 @@ window.chrome.browserAction.setBadgeBackgroundColor({
|
|||
|
||||
window.tabWithError2ip = {}; // For errors only: Error? -> Check this IP!
|
||||
|
||||
+function() {
|
||||
{
|
||||
|
||||
var _tabCallbacks = {};
|
||||
const _tabCallbacks = {};
|
||||
|
||||
function afterTabUpdated(tabId, cb) {
|
||||
if (_tabCallbacks[tabId])
|
||||
|
@ -42,7 +42,7 @@ window.tabWithError2ip = {}; // For errors only: Error? -> Check this IP!
|
|||
}
|
||||
|
||||
chrome.webRequest.onErrorOccurred.addListener(
|
||||
requestDetails =>
|
||||
(requestDetails) =>
|
||||
isInsideTabWithIp(requestDetails) &&
|
||||
(
|
||||
isProxiedAndInformed(requestDetails) || requestDetails.type === 'main_frame' && ( window.tabWithError2ip[requestDetails.tabId] = requestDetails.ip )
|
||||
|
@ -50,9 +50,9 @@ window.tabWithError2ip = {}; // For errors only: Error? -> Check this IP!
|
|||
{ urls: ['<all_urls>'] }
|
||||
);
|
||||
|
||||
chrome.tabs.onRemoved.addListener( tabId => { onTabUpdate(tabId); delete window.tabWithError2ip[tabId] } );
|
||||
chrome.tabs.onRemoved.addListener( (tabId) => { onTabUpdate(tabId); delete window.tabWithError2ip[tabId] } );
|
||||
|
||||
var previousUpdateTitleFinished = Promise.resolve();
|
||||
let previousUpdateTitleFinished = Promise.resolve();
|
||||
|
||||
function isProxiedAndInformed(requestDetails) {
|
||||
|
||||
|
@ -62,12 +62,12 @@ window.tabWithError2ip = {}; // For errors only: Error? -> Check this IP!
|
|||
return false;
|
||||
}
|
||||
|
||||
var ifMainFrame = requestDetails.type === 'main_frame';
|
||||
const ifMainFrame = requestDetails.type === 'main_frame';
|
||||
|
||||
previousUpdateTitleFinished = previousUpdateTitleFinished.then(
|
||||
() => new Promise(
|
||||
resolve => {
|
||||
var cb = () => updateTitle( requestDetails, resolve );
|
||||
(resolve) => {
|
||||
const cb = () => updateTitle( requestDetails, resolve );
|
||||
return ifMainFrame ? afterTabUpdated(requestDetails.tabId, cb) : cb();
|
||||
}
|
||||
)
|
||||
|
@ -79,15 +79,16 @@ window.tabWithError2ip = {}; // For errors only: Error? -> Check this IP!
|
|||
|
||||
chrome.browserAction.getTitle(
|
||||
{ tabId: requestDetails.tabId },
|
||||
title => {
|
||||
var ifTitleSetAlready = /\n/.test(title);
|
||||
var proxyHost = window.antiCensorRu.pacProvider.proxyIps[ requestDetails.ip ];
|
||||
(title) => {
|
||||
|
||||
var hostname = new URL( requestDetails.url ).hostname;
|
||||
const ifTitleSetAlready = /\n/.test(title);
|
||||
const proxyHost = window.antiCensorRu.pacProvider.proxyIps[ requestDetails.ip ];
|
||||
|
||||
var ifShouldUpdateTitle = false;
|
||||
var indent = ' ';
|
||||
var proxyTitle = 'Прокси:';
|
||||
const hostname = new URL( requestDetails.url ).hostname;
|
||||
|
||||
let ifShouldUpdateTitle = false;
|
||||
const indent = ' ';
|
||||
const proxyTitle = 'Прокси:';
|
||||
|
||||
if (!ifTitleSetAlready) {
|
||||
title = 'Разблокированы:\n'+ indent + hostname +'\n'+ proxyTitle +'\n'+ indent + proxyHost;
|
||||
|
@ -98,7 +99,8 @@ window.tabWithError2ip = {}; // For errors only: Error? -> Check this IP!
|
|||
text: ifMainFrame ? '1' : '%1'
|
||||
});
|
||||
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
const hostsProxiesPair = title.split(proxyTitle);
|
||||
|
||||
if (hostsProxiesPair[1].indexOf(proxyHost) === -1) {
|
||||
|
@ -110,10 +112,11 @@ window.tabWithError2ip = {}; // For errors only: Error? -> Check this IP!
|
|||
title = title.replace(proxyTitle, indent + hostname +'\n'+ proxyTitle);
|
||||
ifShouldUpdateTitle = true;
|
||||
|
||||
var _cb = cb;
|
||||
const _cb = cb;
|
||||
cb = () => chrome.browserAction.getBadgeText(
|
||||
{tabId: requestDetails.tabId},
|
||||
result => {
|
||||
(result) => {
|
||||
|
||||
chrome.browserAction.setBadgeText(
|
||||
{
|
||||
tabId: requestDetails.tabId,
|
||||
|
@ -121,27 +124,30 @@ window.tabWithError2ip = {}; // For errors only: Error? -> Check this IP!
|
|||
}
|
||||
);
|
||||
return _cb();
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (ifShouldUpdateTitle)
|
||||
if (ifShouldUpdateTitle) {
|
||||
chrome.browserAction.setTitle({
|
||||
title: title,
|
||||
tabId: requestDetails.tabId
|
||||
});
|
||||
}
|
||||
|
||||
return cb();
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
chrome.webRequest.onResponseStarted.addListener(
|
||||
requestDetails => isInsideTabWithIp(requestDetails) && isProxiedAndInformed(requestDetails),
|
||||
(requestDetails) => isInsideTabWithIp(requestDetails) && isProxiedAndInformed(requestDetails),
|
||||
{ urls: ['<all_urls>'] }
|
||||
);
|
||||
|
||||
}();
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
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}) )
|
||||
onclick: (menuInfo, tab) => Promise.resolve( tab2url( tab ) ).then( (url) => chrome.tabs.create({url: url}) )
|
||||
});
|
||||
|
||||
createMenuLinkEntry( 'Сайт доступен из-за границы? Is up?', (tab) => 'http://isup.me/'+ new URL(tab.url).hostname );
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"manifest_version": 2,
|
||||
|
||||
"name": "Обход блокировок Рунета",
|
||||
"name": "Обход блокировок Рунета 0.15",
|
||||
"description": "Аргументы против цензуры: https://git.io/vEkI9",
|
||||
"version": "0.0.0.15",
|
||||
"icons": {
|
||||
|
|
Loading…
Reference in New Issue
Block a user