Fix blocking Javascript for new (custom)sites

merge-requests/1/head
magnolia1234 5 years ago committed by GitHub
parent 7ef74559b2
commit c2135f7d1c

@ -234,6 +234,7 @@ ext_api.storage.sync.get({
block_js.push("*://" + domainVar + "/*"); // site without www.-prefix block_js.push("*://" + domainVar + "/*"); // site without www.-prefix
} }
} }
disableJavascriptOnListedSites();
}); });
// Listen for changes to options // Listen for changes to options
@ -247,6 +248,9 @@ ext_api.storage.onChanged.addListener(function (changes, namespace) {
}).map(function (key) { }).map(function (key) {
return sites[key]; return sites[key];
}); });
// reset disableJavascriptOnListedSites eventListener
ext_api.webRequest.onBeforeRequest.removeListener(disableJavascriptOnListedSites);
ext_api.webRequest.handlerBehaviorChanged();
} }
if (key === 'sites_custom') { if (key === 'sites_custom') {
var sites_custom = storageChange.newValue; var sites_custom = storageChange.newValue;
@ -277,6 +281,9 @@ ext_api.storage.onChanged.addListener(function (changes, namespace) {
block_js.push("*://" + domainVar + "/*"); // site without www.-prefix block_js.push("*://" + domainVar + "/*"); // site without www.-prefix
} }
} }
// reset disableJavascriptOnListedSites eventListener
ext_api.webRequest.onBeforeRequest.removeListener(disableJavascriptOnListedSites);
ext_api.webRequest.handlerBehaviorChanged();
} }
} }
}); });
@ -305,19 +312,22 @@ ext_api.webRequest.onBeforeRequest.addListener(function (details) {
var block_js_default = ["*://*.tinypass.com/*", "*://*.poool.fr/*", "*://*.piano.io/*", "*://*.outbrain.com/*"]; var block_js_default = ["*://*.tinypass.com/*", "*://*.poool.fr/*", "*://*.piano.io/*", "*://*.outbrain.com/*"];
var block_js_custom = []; var block_js_custom = [];
var block_js = block_js_default.concat(block_js_custom); var block_js = block_js_default.concat(block_js_custom);
// Disable javascript for these sites/general paywall-scripts // Disable javascript for these sites/general paywall-scripts
ext_api.webRequest.onBeforeRequest.addListener(function (details) { function disableJavascriptOnListedSites() {
if (!isSiteEnabled(details)) { ext_api.webRequest.onBeforeRequest.addListener(function (details) {
return; if (!isSiteEnabled(details)) {
} return;
return { }
cancel: true return {
}; cancel: true
}, { };
urls: block_js, }, {
types: ["script"] urls: block_js,
}, types: ["script"]
["blocking"]); },
["blocking"]);
}
var extraInfoSpec = ['blocking', 'requestHeaders']; var extraInfoSpec = ['blocking', 'requestHeaders'];
if (ext_api.webRequest.OnBeforeSendHeadersOptions.hasOwnProperty('EXTRA_HEADERS')) if (ext_api.webRequest.OnBeforeSendHeadersOptions.hasOwnProperty('EXTRA_HEADERS'))

Loading…
Cancel
Save