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