mirror of
https://github.com/anticensority/runet-censorship-bypass.git
synced 2024-11-27 11:53:44 +03:00
Fix chrome.proxy.settings shims for FireFox
Yet it still downloads pac-script twice
This commit is contained in:
parent
53571f6228
commit
aa727d9329
|
@ -41,15 +41,18 @@ console.log('Extension started.');
|
|||
|
||||
},
|
||||
|
||||
lastError: undefined,
|
||||
|
||||
checkChromeError() {
|
||||
|
||||
// Chrome API calls your cb in a context different from the point of API
|
||||
// method invokation.
|
||||
const err = chrome.runtime.lastError || chrome.extension.lastError;
|
||||
const err = chrome.runtime.lastError || chrome.extension.lastError || self.lastError;
|
||||
if (!err) {
|
||||
return;
|
||||
}
|
||||
console.warn('API returned error:', err);
|
||||
delete self.lastError;
|
||||
return new Error(err.message); // Add stack.
|
||||
|
||||
},
|
||||
|
|
|
@ -5,11 +5,11 @@ if (window.apis.platform.ifFirefox) {
|
|||
const prefix = 'firefox-only';
|
||||
|
||||
const ffxStorage = {
|
||||
get(keys) {
|
||||
get(key) {
|
||||
return new Promise((resolve) => (
|
||||
chrome.storage.local.get(
|
||||
keys,
|
||||
window.utils.getOrDie(resolve),
|
||||
key,
|
||||
window.utils.getOrDie((obj) => resolve(obj[key])),
|
||||
)
|
||||
));
|
||||
},
|
||||
|
@ -41,9 +41,13 @@ if (window.apis.platform.ifFirefox) {
|
|||
},
|
||||
}, window.utils.chromified( async (err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
window.utils.lastError = err;
|
||||
cb();
|
||||
return;
|
||||
}
|
||||
await ffxStorage.set({ [`${prefix}-pacData`]: pac.data });
|
||||
window.pacData = pac.data;
|
||||
window.ffxStorage = ffxStorage;
|
||||
await ffxStorage.set({ [`${prefix}-pac-data`]: pac.data });
|
||||
cb();
|
||||
}));
|
||||
};
|
||||
|
@ -52,7 +56,9 @@ if (window.apis.platform.ifFirefox) {
|
|||
chrome.proxy.settings.get = function(details, cb) {
|
||||
originalGet(details, window.utils.chromified((err, originalDetails) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
window.utils.lastError = err;
|
||||
cb(originalDetails);
|
||||
return;
|
||||
}
|
||||
const autoConfigUrl = window.utils.getProp(originalDetails, 'value.autoConfigUrl');
|
||||
if (!autoConfigUrl) {
|
||||
|
@ -60,7 +66,12 @@ if (window.apis.platform.ifFirefox) {
|
|||
}
|
||||
window.apis.httpLib.get(autoConfigUrl, async (err, pacData) => {
|
||||
if (err) {
|
||||
pacData = await ffxStorage.get(`${prefix}-pacData`);
|
||||
pacData = await ffxStorage.get(`${prefix}-pac-data`);
|
||||
if (!pacData || !Object.keys(pacData).length) {
|
||||
window.utils.lastError = err;
|
||||
cb(originalDetails);
|
||||
return;
|
||||
}
|
||||
}
|
||||
cb(Object.assign(
|
||||
originalDetails,
|
||||
|
@ -79,7 +90,7 @@ if (window.apis.platform.ifFirefox) {
|
|||
|
||||
const originalClear = chrome.proxy.settings.clear.bind( chrome.proxy.settings );
|
||||
chrome.proxy.settings.clear = async function(details, cb) {
|
||||
await ffxStorage.remove(`${prefix}-pacData`);
|
||||
await ffxStorage.remove(`${prefix}-pac-data`);
|
||||
originalClear(details, cb);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -626,16 +626,16 @@ ${
|
|||
chrome.proxy.settings.set = function(details, cb) {
|
||||
const pac = window.utils.getProp(details, 'value.pacScript');
|
||||
if (!(pac && pac.data)) {
|
||||
return originalSet(details, cb);
|
||||
return originalSet(details, window.utils.timeouted(cb));
|
||||
}
|
||||
const pacMods = getCurrentConfigs();
|
||||
pac.data = pacKitchen.cook( pac.data, pacMods );
|
||||
originalSet({value: details.value}, window.utils.chromified((err) => {
|
||||
|
||||
if (err) {
|
||||
throw err;
|
||||
if (!err) {
|
||||
kitchenState(ifIncontinence, null);
|
||||
}
|
||||
kitchenState(ifIncontinence, null);
|
||||
window.utils.lastError = err;
|
||||
cb && cb();
|
||||
|
||||
}));
|
||||
|
|
|
@ -380,12 +380,10 @@
|
|||
}
|
||||
}
|
||||
|
||||
chrome.storage.local.clear(
|
||||
() => chrome.storage.local.set(
|
||||
onlySettable,
|
||||
chromified(cb),
|
||||
)
|
||||
);
|
||||
chrome.storage.local.set(
|
||||
onlySettable,
|
||||
chromified(cb),
|
||||
)
|
||||
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user