mirror of
https://github.com/anticensority/runet-censorship-bypass.git
synced 2024-11-27 20:03:45 +03:00
Swap events for requests
This commit is contained in:
parent
8c88d70398
commit
f20da20e48
1
extensions/chromium/runet-censorship-bypass/grep.txt
Normal file
1
extensions/chromium/runet-censorship-bypass/grep.txt
Normal file
|
@ -0,0 +1 @@
|
|||
grep -r addEvent ./ --exclude-dir=vendor --exclude-dir=node_modules
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
{
|
||||
|
||||
const IF_DEBUG = false;
|
||||
const IF_DEBUG = true;
|
||||
|
||||
if (!IF_DEBUG) {
|
||||
// I believe logging objects precludes them from being GCed.
|
||||
|
@ -18,6 +18,10 @@
|
|||
});
|
||||
}
|
||||
|
||||
const privates = {
|
||||
requestToResponder: {},
|
||||
};
|
||||
|
||||
const self = window.utils = {
|
||||
|
||||
mandatory() {
|
||||
|
@ -84,15 +88,34 @@
|
|||
|
||||
},
|
||||
|
||||
addEventHandler(type, handler) {
|
||||
assert(value) {
|
||||
|
||||
document.addEventListener(type, (event) => handler(...event.detail));
|
||||
if(!value) {
|
||||
console.assert(value);
|
||||
throw new Error('Assert failed for:' + value);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
fireEvent(type, ...args) {
|
||||
addRequestResponder(requestType, responder) {
|
||||
|
||||
document.dispatchEvent( new CustomEvent(type, {detail: args}) );
|
||||
if( privates.requestToResponder[requestType] ) {
|
||||
throw new TypeError(`Request ${requestType} already has responder!`);
|
||||
}
|
||||
privates.requestToResponder[requestType] = responder;
|
||||
|
||||
},
|
||||
|
||||
fireRequest(requestType, ...args) {
|
||||
|
||||
const cb = args.slice(-1)[0];
|
||||
self.assert(typeof(cb) === 'function');
|
||||
const responder = privates.requestToResponder[requestType];
|
||||
if(responder) {
|
||||
responder(...args);
|
||||
} else {
|
||||
cb();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
|
|
@ -295,7 +295,6 @@
|
|||
|
||||
keepCookedNowAsync(pacMods = mandatory(), cb = throwIfError) {
|
||||
|
||||
console.log('Keep cooked now...', pacMods);
|
||||
if (typeof(pacMods) === 'function') {
|
||||
cb = pacMods;
|
||||
pacMods = getCurrentConfigs();
|
||||
|
@ -307,10 +306,11 @@
|
|||
}
|
||||
kitchenState(modsKey, pacMods);
|
||||
}
|
||||
console.log('Keep cooked now...', pacMods);
|
||||
this._tryNowAsync(
|
||||
(err, res, ...warns) => {
|
||||
|
||||
console.log('Try now cb...', err);
|
||||
console.log('Try now err:', err);
|
||||
if (err) {
|
||||
return cb(err, res, ...warns);
|
||||
}
|
||||
|
@ -321,8 +321,7 @@
|
|||
}
|
||||
|
||||
const hosts = par.map( (ps) => ps.split(/\s+/)[1] );
|
||||
window.utils.fireEvent('ip-to-host-replace-all', hosts, throwIfError);
|
||||
cb(null, null, ...warns);
|
||||
window.utils.fireRequest('ip-to-host-replace-all', hosts, (err, res, ...moreWarns) => cb( err, res, ...warns.concat(moreWarns) ));
|
||||
|
||||
}
|
||||
);
|
||||
|
|
|
@ -93,8 +93,7 @@
|
|||
'Getting IPs for PAC hosts...',
|
||||
cb
|
||||
);
|
||||
window.utils.fireEvent('ip-to-host-update-all', () => {/* Swallow. */});
|
||||
cb();
|
||||
window.utils.fireRequest('ip-to-host-update-all', cb);
|
||||
|
||||
};
|
||||
|
||||
|
@ -261,7 +260,7 @@
|
|||
|
||||
},
|
||||
|
||||
_periodicUpdateAlarmReason: 'Периодичное обновление PAC-скрипта Антизапрет',
|
||||
_periodicUpdateAlarmReason: 'Периодичное обновление PAC-скрипта',
|
||||
|
||||
pushToStorageAsync(cb = throwIfError) {
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
],
|
||||
|
||||
"background": {
|
||||
${persistent}
|
||||
"scripts": [
|
||||
"00-init-apis.js"
|
||||
, "11-error-handlers-api.js"
|
||||
|
|
|
@ -599,9 +599,17 @@ HTTPS 11.22.33.44:8080;">${conf.value || localStorage.getItem(uiRaw) || ''}</tex
|
|||
if (!ifSure) {
|
||||
return false;
|
||||
}
|
||||
pacKitchen.resetToDefaults();
|
||||
backgroundPage.utils.fireEvent('ip-to-host-reset-to-defaults');
|
||||
window.close();
|
||||
conduct(
|
||||
'Сбрасываем...',
|
||||
(cb) => {
|
||||
|
||||
pacKitchen.resetToDefaults();
|
||||
backgroundPage.utils.fireRequest('ip-to-host-reset-to-defaults', cb);
|
||||
|
||||
},
|
||||
'Откройте окно заново для отображения эффекта.',
|
||||
() => window.close()
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -188,7 +188,7 @@
|
|||
|
||||
const self = window.apis.ipToHost = {
|
||||
|
||||
persist() {
|
||||
persistData() {
|
||||
|
||||
console.log('Persisting ipToHost...', privates);
|
||||
const ipToHost = {};
|
||||
|
@ -299,7 +299,7 @@
|
|||
this._updateAllAsync((err, ...args) => {
|
||||
|
||||
if (!err) {
|
||||
this.persist();
|
||||
this.persistData();
|
||||
}
|
||||
cb(err, ...args);
|
||||
|
||||
|
@ -320,7 +320,7 @@
|
|||
this._replaceAllAsync(hostArr, (allErr, ...args) => {
|
||||
|
||||
if (!allErr) {
|
||||
this.persist();
|
||||
this.persistData();
|
||||
}
|
||||
cb(allErr, ...args);
|
||||
|
||||
|
@ -337,14 +337,17 @@
|
|||
|
||||
};
|
||||
|
||||
window.utils.addEventHandler(
|
||||
window.utils.addRequestResponder(
|
||||
'ip-to-host-update-all', (...args) => self.updateAllAsync(...args)
|
||||
);
|
||||
window.utils.addEventHandler(
|
||||
window.utils.addRequestResponder(
|
||||
'ip-to-host-replace-all', (...args) => self.replaceAllAsync(...args)
|
||||
);
|
||||
window.utils.addEventHandler(
|
||||
'ip-to-host-reset-to-defaults', () => self.resetToDefaults()
|
||||
window.utils.addRequestResponder(
|
||||
'ip-to-host-reset-to-defaults', (cb) => {
|
||||
self.resetToDefaults();
|
||||
cb();
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ exports.contexts.full = Object.assign({}, commonContext, {
|
|||
nameSuffixEn: '',
|
||||
nameSuffixRu: '',
|
||||
extra_permissions: ', "webRequest"',
|
||||
persistent: '',
|
||||
scripts_2x: ', "20-ip-to-host-api.js"',
|
||||
scripts_7x: ', "70-block-informer.js"',
|
||||
});
|
||||
|
@ -20,6 +21,7 @@ exports.contexts.mini = Object.assign({}, commonContext, {
|
|||
nameSuffixEn: ' MINI',
|
||||
nameSuffixRu: ' МИНИ',
|
||||
extra_permissions: '',
|
||||
persistent: '"persistent": false,',
|
||||
scripts_2x: ', "20-for-mini-only.js"',
|
||||
scripts_7x: '',
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user