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);
|
||||
|
||||
openAndFocus(
|
||||
'http://rebrand.ly/ac-error/?json=' + encodeURIComponent(json) +
|
||||
'https://rebrand.ly/ac-error/?json=' + encodeURIComponent(json) +
|
||||
(type ? '&type=' + encodeURIComponent(type) : '') +
|
||||
'&version=' + chrome.runtime.getManifest().version +
|
||||
'&useragent=' + encodeURIComponent(navigator.userAgent) +
|
||||
|
@ -252,7 +252,7 @@
|
|||
|
||||
handlers.installListenersOn(window, 'BG');
|
||||
|
||||
chrome.proxy.onProxyError.addListener( timeouted( (details) => {
|
||||
(chrome.proxy.onProxyError || chrome.proxy.onError).addListener( timeouted( (details) => {
|
||||
|
||||
if (!handlers.ifControlled) {
|
||||
return;
|
||||
|
|
|
@ -541,9 +541,11 @@ ${
|
|||
|
||||
).then((details) => {
|
||||
|
||||
console.log('DEEETAILS:', details); // TODO:
|
||||
if (
|
||||
details && details.levelOfControl === 'controlled_by_this_extension'
|
||||
) {
|
||||
console.log('TODODOODODODOD:', details); // TODO:
|
||||
const pac = window.utils.getProp(details, 'value.pacScript');
|
||||
if (pac && pac.data) {
|
||||
return chrome.proxy.settings.set(details, chromified(cb));
|
||||
|
@ -551,6 +553,7 @@ ${
|
|||
}
|
||||
|
||||
kitchenState(ifIncontinence, true);
|
||||
console.log('TYYYYPE ERRROR');
|
||||
cb(null, null, new TypeError(
|
||||
'Не найдено активного PAC-скрипта! Изменения будут применены при возвращении контроля настроек прокси или установке нового PAC-скрипта.'
|
||||
));
|
||||
|
@ -562,7 +565,7 @@ ${
|
|||
checkIncontinence(details) {
|
||||
|
||||
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) {
|
||||
|
||||
const pac = window.utils.getProp(details, 'value.pacScript');
|
||||
if (!(pac && pac.data)) {
|
||||
const pac = window.utils.getProp(details, 'value.pacScript') || {};
|
||||
const autoConfigUrl = window.utils.getProp(details, 'value.autoConfigUrl');
|
||||
const ifNothingToCook = !(pac && pac.data || autoConfigUrl);
|
||||
if (ifNothingToCook) {
|
||||
return originalSet(details, cb);
|
||||
}
|
||||
const getPacData = (cb) =>
|
||||
pac.data ? cb(null, pac.data) : window.apis.httpLib.get(autoConfigUrl, cb);
|
||||
|
||||
getPacData((err, pacData) => {
|
||||
if (err) {
|
||||
cb(err);
|
||||
return;
|
||||
}
|
||||
const pacMods = getCurrentConfigs();
|
||||
pac.data = pacKitchen.cook( pac.data, pacMods );
|
||||
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();
|
||||
|
|
|
@ -59,10 +59,39 @@
|
|||
|
||||
};
|
||||
|
||||
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(
|
||||
pacData = mandatory(), cb = throwIfError,
|
||||
) {
|
||||
|
||||
console.log('Clearing chrome proxy settings...');
|
||||
chrome.proxy.settings.clear({}, chromified((clearErr) => {
|
||||
|
||||
if (clearErr) {
|
||||
return cb(clearErr);
|
||||
}
|
||||
const config = {
|
||||
mode: 'pac_script',
|
||||
pacScript: {
|
||||
|
@ -71,7 +100,7 @@
|
|||
},
|
||||
};
|
||||
console.log('Setting chrome proxy settings...');
|
||||
chrome.proxy.settings.set( {value: config}, chromified((err) => {
|
||||
chrome.proxy.settings.set( { value: config }, chromified((err) => {
|
||||
|
||||
if (err) {
|
||||
return cb(err);
|
||||
|
@ -92,7 +121,7 @@
|
|||
});
|
||||
|
||||
}));
|
||||
|
||||
}));
|
||||
};
|
||||
|
||||
const updatePacProxyIps = function updatePacProxyIps(
|
||||
|
@ -143,33 +172,11 @@
|
|||
|
||||
}
|
||||
|
||||
httpLib.ifModifiedSince(pacUrl, lastModifiedStr, (err, newLastModifiedStr) => {
|
||||
|
||||
/*
|
||||
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);
|
||||
}
|
||||
*/
|
||||
|
||||
console.log('Clearing chrome proxy settings...');
|
||||
const pacDataPromise = doWithoutProxyAsync(
|
||||
// Employ all urls, the latter are fallbacks for the former.
|
||||
const pacDataPromise = provider.pacUrls.reduce(
|
||||
() =>
|
||||
provider.pacUrls.reduce(
|
||||
(promise, url) => promise.catch(
|
||||
() => new Promise(
|
||||
(resolve, reject) => httpLib.get(
|
||||
|
@ -179,6 +186,7 @@
|
|||
),
|
||||
),
|
||||
Promise.reject(),
|
||||
),
|
||||
);
|
||||
|
||||
pacDataPromise.then(
|
||||
|
@ -189,7 +197,7 @@
|
|||
pacData,
|
||||
(err, res) => cb(
|
||||
err,
|
||||
Object.assign(res || {}, {lastModified: newLastModifiedStr}),
|
||||
Object.assign(res || {}, {lastModified: lastModifiedStr}),
|
||||
),
|
||||
);
|
||||
|
||||
|
@ -202,9 +210,6 @@
|
|||
),
|
||||
|
||||
);
|
||||
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
window.apis.antiCensorRu = {
|
||||
|
|
|
@ -40,7 +40,7 @@ chrome.runtime.getBackgroundPage( (bgWindow) =>
|
|||
([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.ifInsideEdgeOptionsPage = theState.flags.ifInsideOptionsPage && currentTab.url.startsWith('edge://');
|
||||
|
|
Loading…
Reference in New Issue
Block a user