mirror of
https://github.com/anticensority/runet-censorship-bypass.git
synced 2024-11-27 20:03:45 +03:00
Add FireFox 60 support (for testing, part 1)
Some error notifications are broken. Not thoroughly tested.
This commit is contained in:
parent
8145f5f04a
commit
7037af70ca
|
@ -76,7 +76,7 @@
|
||||||
const json = JSON.stringify(errors, errorJsonReplacer, 0);
|
const json = JSON.stringify(errors, errorJsonReplacer, 0);
|
||||||
|
|
||||||
openAndFocus(
|
openAndFocus(
|
||||||
'http://rebrand.ly/ac-error/?json=' + encodeURIComponent(json) +
|
'https://rebrand.ly/ac-error/?json=' + encodeURIComponent(json) +
|
||||||
(type ? '&type=' + encodeURIComponent(type) : '') +
|
(type ? '&type=' + encodeURIComponent(type) : '') +
|
||||||
'&version=' + chrome.runtime.getManifest().version +
|
'&version=' + chrome.runtime.getManifest().version +
|
||||||
'&useragent=' + encodeURIComponent(navigator.userAgent) +
|
'&useragent=' + encodeURIComponent(navigator.userAgent) +
|
||||||
|
@ -252,7 +252,7 @@
|
||||||
|
|
||||||
handlers.installListenersOn(window, 'BG');
|
handlers.installListenersOn(window, 'BG');
|
||||||
|
|
||||||
chrome.proxy.onProxyError.addListener( timeouted( (details) => {
|
(chrome.proxy.onProxyError || chrome.proxy.onError).addListener( timeouted( (details) => {
|
||||||
|
|
||||||
if (!handlers.ifControlled) {
|
if (!handlers.ifControlled) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -541,9 +541,11 @@ ${
|
||||||
|
|
||||||
).then((details) => {
|
).then((details) => {
|
||||||
|
|
||||||
|
console.log('DEEETAILS:', details); // TODO:
|
||||||
if (
|
if (
|
||||||
details && details.levelOfControl === 'controlled_by_this_extension'
|
details && details.levelOfControl === 'controlled_by_this_extension'
|
||||||
) {
|
) {
|
||||||
|
console.log('TODODOODODODOD:', details); // TODO:
|
||||||
const pac = window.utils.getProp(details, 'value.pacScript');
|
const pac = window.utils.getProp(details, 'value.pacScript');
|
||||||
if (pac && pac.data) {
|
if (pac && pac.data) {
|
||||||
return chrome.proxy.settings.set(details, chromified(cb));
|
return chrome.proxy.settings.set(details, chromified(cb));
|
||||||
|
@ -551,6 +553,7 @@ ${
|
||||||
}
|
}
|
||||||
|
|
||||||
kitchenState(ifIncontinence, true);
|
kitchenState(ifIncontinence, true);
|
||||||
|
console.log('TYYYYPE ERRROR');
|
||||||
cb(null, null, new TypeError(
|
cb(null, null, new TypeError(
|
||||||
'Не найдено активного PAC-скрипта! Изменения будут применены при возвращении контроля настроек прокси или установке нового PAC-скрипта.'
|
'Не найдено активного PAC-скрипта! Изменения будут применены при возвращении контроля настроек прокси или установке нового PAC-скрипта.'
|
||||||
));
|
));
|
||||||
|
@ -562,7 +565,7 @@ ${
|
||||||
checkIncontinence(details) {
|
checkIncontinence(details) {
|
||||||
|
|
||||||
if ( kitchenState(ifIncontinence) ) {
|
if ( kitchenState(ifIncontinence) ) {
|
||||||
this.setNowAsync(details, () => {/* Swallow. */});
|
this.setNowAsync(details, (err) => { if (err) { throw err; } }); // TODO: suppress?
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
@ -625,19 +628,44 @@ ${
|
||||||
|
|
||||||
chrome.proxy.settings.set = function(details, cb) {
|
chrome.proxy.settings.set = function(details, cb) {
|
||||||
|
|
||||||
const pac = window.utils.getProp(details, 'value.pacScript');
|
const pac = window.utils.getProp(details, 'value.pacScript') || {};
|
||||||
if (!(pac && pac.data)) {
|
const autoConfigUrl = window.utils.getProp(details, 'value.autoConfigUrl');
|
||||||
|
const ifNothingToCook = !(pac && pac.data || autoConfigUrl);
|
||||||
|
if (ifNothingToCook) {
|
||||||
return originalSet(details, cb);
|
return originalSet(details, cb);
|
||||||
}
|
}
|
||||||
const pacMods = getCurrentConfigs();
|
const getPacData = (cb) =>
|
||||||
pac.data = pacKitchen.cook( pac.data, pacMods );
|
pac.data ? cb(null, pac.data) : window.apis.httpLib.get(autoConfigUrl, cb);
|
||||||
originalSet({value: details.value}, (/* No args. */) => {
|
|
||||||
|
|
||||||
kitchenState(ifIncontinence, null);
|
getPacData((err, pacData) => {
|
||||||
cb && cb();
|
if (err) {
|
||||||
|
cb(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const pacMods = getCurrentConfigs();
|
||||||
|
const cookedData = pacKitchen.cook( pacData, pacMods );
|
||||||
|
|
||||||
|
if (window.apis.platform.ifFirefox) {
|
||||||
|
const autoConfigUrl = URL.createObjectURL(new Blob([cookedData], {
|
||||||
|
type: 'application/x-ns-proxy-autoconfig',
|
||||||
|
}));
|
||||||
|
originalSet({
|
||||||
|
value: {
|
||||||
|
proxyType: 'autoConfig',
|
||||||
|
autoConfigUrl,
|
||||||
|
},
|
||||||
|
}, chromified(cb));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
details.value.pacScript.data = cookedData;
|
||||||
|
originalSet({value: details.value}, (/* No args. */) => {
|
||||||
|
|
||||||
|
kitchenState(ifIncontinence, null);
|
||||||
|
cb && cb();
|
||||||
|
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pacKitchen.checkIncontinence();
|
pacKitchen.checkIncontinence();
|
||||||
|
|
|
@ -59,40 +59,69 @@
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const doWithoutProxyAsync = (createPromise) => new Promise((resolve, reject) => {
|
||||||
|
chrome.proxy.settings.get({}, chromified((getErr, settings) => {
|
||||||
|
if (getErr) {
|
||||||
|
reject(getErr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
delete settings.levelOfControl;
|
||||||
|
const setProxyAsync = () => new Promise((setResolve, setReject) =>
|
||||||
|
chrome.proxy.settings.set(
|
||||||
|
settings,
|
||||||
|
chromified((err) => err ? setReject(err) : setResolve()),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
chrome.proxy.settings.clear({}, chromified((clearErr) => {
|
||||||
|
if (clearErr) {
|
||||||
|
reject(clearErr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return createPromise().then((actionResult) => setProxyAsync().then(() => resolve(actionResult)));
|
||||||
|
}));
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
const setPacAsync = function setPacAsync(
|
const setPacAsync = function setPacAsync(
|
||||||
pacData = mandatory(), cb = throwIfError,
|
pacData = mandatory(), cb = throwIfError,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
const config = {
|
console.log('Clearing chrome proxy settings...');
|
||||||
mode: 'pac_script',
|
chrome.proxy.settings.clear({}, chromified((clearErr) => {
|
||||||
pacScript: {
|
|
||||||
mandatory: false,
|
|
||||||
data: pacData,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
console.log('Setting chrome proxy settings...');
|
|
||||||
chrome.proxy.settings.set( {value: config}, chromified((err) => {
|
|
||||||
|
|
||||||
if (err) {
|
if (clearErr) {
|
||||||
return cb(err);
|
return cb(clearErr);
|
||||||
}
|
}
|
||||||
handlers.updateControlState( () => {
|
const config = {
|
||||||
|
mode: 'pac_script',
|
||||||
if ( !handlers.ifControlled ) {
|
pacScript: {
|
||||||
|
mandatory: false,
|
||||||
console.warn('Failed, other extension is in control.');
|
data: pacData,
|
||||||
return cb(
|
},
|
||||||
new Error( window.utils.messages.whichExtensionHtml() ),
|
};
|
||||||
);
|
console.log('Setting chrome proxy settings...');
|
||||||
|
chrome.proxy.settings.set( { value: config }, chromified((err) => {
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
return cb(err);
|
||||||
}
|
}
|
||||||
console.log('Successfuly set PAC in proxy settings..');
|
handlers.updateControlState( () => {
|
||||||
cb();
|
|
||||||
|
|
||||||
});
|
if ( !handlers.ifControlled ) {
|
||||||
|
|
||||||
|
console.warn('Failed, other extension is in control.');
|
||||||
|
return cb(
|
||||||
|
new Error( window.utils.messages.whichExtensionHtml() ),
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
console.log('Successfuly set PAC in proxy settings..');
|
||||||
|
cb();
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}));
|
||||||
}));
|
}));
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const updatePacProxyIps = function updatePacProxyIps(
|
const updatePacProxyIps = function updatePacProxyIps(
|
||||||
|
@ -143,68 +172,44 @@
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
httpLib.ifModifiedSince(pacUrl, lastModifiedStr, (err, newLastModifiedStr) => {
|
console.log('Clearing chrome proxy settings...');
|
||||||
|
const pacDataPromise = doWithoutProxyAsync(
|
||||||
/*
|
|
||||||
TODO: Get rid of this dirty hack
|
|
||||||
IPFS used by AntiZapret always returns last-modified date as new Date(1000) which is 1 sec since unix epoch.
|
|
||||||
Last-modified isn't changed but target redireciton URL is and this URL should be compared to the last cached URL.
|
|
||||||
Hack here is to consider 5 seconds since epoch time the same way as the unix epoch start.
|
|
||||||
If you think etags are the solution then know that etags can't be read from the fetch API, see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Expose-Headers.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
TODO: I turn off caching for now because I see no easy way out.
|
|
||||||
|
|
||||||
const ifWasEverModified = new Date(lastModifiedStr) - new Date(0) > 5000;
|
|
||||||
if (!newLastModifiedStr && ifWasEverModified) {
|
|
||||||
addWarning(
|
|
||||||
(ifRu
|
|
||||||
? 'Ваш PAC-скрипт не нуждается в обновлении. Его дата: '
|
|
||||||
: 'Your PAC-script doesn\\'t need to be updated. It\\'s date: '
|
|
||||||
) + lastModifiedStr,
|
|
||||||
);
|
|
||||||
const res = {lastModified: lastModifiedStr};
|
|
||||||
return cb(null, res);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Employ all urls, the latter are fallbacks for the former.
|
// Employ all urls, the latter are fallbacks for the former.
|
||||||
const pacDataPromise = provider.pacUrls.reduce(
|
() =>
|
||||||
(promise, url) => promise.catch(
|
provider.pacUrls.reduce(
|
||||||
() => new Promise(
|
(promise, url) => promise.catch(
|
||||||
(resolve, reject) => httpLib.get(
|
() => new Promise(
|
||||||
url,
|
(resolve, reject) => httpLib.get(
|
||||||
(newErr, pacData) => newErr ? reject(newErr) : resolve(pacData),
|
url,
|
||||||
|
(newErr, pacData) => newErr ? reject(newErr) : resolve(pacData),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
Promise.reject(),
|
||||||
),
|
),
|
||||||
Promise.reject(),
|
);
|
||||||
);
|
|
||||||
|
|
||||||
pacDataPromise.then(
|
pacDataPromise.then(
|
||||||
|
|
||||||
(pacData) => {
|
(pacData) => {
|
||||||
|
|
||||||
setPacAsync(
|
setPacAsync(
|
||||||
pacData,
|
pacData,
|
||||||
(err, res) => cb(
|
(err, res) => cb(
|
||||||
err,
|
err,
|
||||||
Object.assign(res || {}, {lastModified: newLastModifiedStr}),
|
Object.assign(res || {}, {lastModified: lastModifiedStr}),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
clarifyThen(
|
clarifyThen(
|
||||||
chrome.i18n.getMessage('FailedToDownloadPacScriptFromAddresses') + ': [ '
|
chrome.i18n.getMessage('FailedToDownloadPacScriptFromAddresses') + ': [ '
|
||||||
+ provider.pacUrls.join(' , ') + ' ].',
|
+ provider.pacUrls.join(' , ') + ' ].',
|
||||||
cb,
|
cb,
|
||||||
),
|
),
|
||||||
|
|
||||||
);
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
window.apis.antiCensorRu = {
|
window.apis.antiCensorRu = {
|
||||||
|
|
|
@ -40,7 +40,7 @@ chrome.runtime.getBackgroundPage( (bgWindow) =>
|
||||||
([tab]) => resolve(tab),
|
([tab]) => resolve(tab),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
winChrome.runtime.sendMessage({ currentTab, eventName: 'POPUP_OPENED' });
|
// winChrome.runtime.sendMessage({ currentTab, eventName: 'POPUP_OPENED' });
|
||||||
|
|
||||||
theState.flags.ifInsideOptionsPage = !currentTab || /.*:\/\/extensions\/\?options=/g.test(currentTab.url) || currentTab.url.startsWith('about:addons');
|
theState.flags.ifInsideOptionsPage = !currentTab || /.*:\/\/extensions\/\?options=/g.test(currentTab.url) || currentTab.url.startsWith('about:addons');
|
||||||
theState.flags.ifInsideEdgeOptionsPage = theState.flags.ifInsideOptionsPage && currentTab.url.startsWith('edge://');
|
theState.flags.ifInsideEdgeOptionsPage = theState.flags.ifInsideOptionsPage && currentTab.url.startsWith('edge://');
|
||||||
|
|
Loading…
Reference in New Issue
Block a user