mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-07-04 20:46:39 +02:00
Added clear interval
Also ensures that the persistent data is loaded correctly in ESR. Fixes #139 and #143
This commit is contained in:
parent
ec1c5ae7d8
commit
3cb1974b18
14 changed files with 283 additions and 43 deletions
49
lib/main.js
49
lib/main.js
|
@ -9,33 +9,13 @@
|
|||
const {error, warning, message, notice, verbose, } = logging;
|
||||
const lists = require("./lists");
|
||||
logging.setPrefix("main script");
|
||||
const persistentRndStorage = require("./persistentRndStorage");
|
||||
|
||||
message("start of background script");
|
||||
message("waiting for settings to be loaded");
|
||||
settings.onloaded(function(){
|
||||
notice("everything loaded");
|
||||
|
||||
notice("build persistent storage");
|
||||
var persistentRnd = Object.create(null);
|
||||
try {
|
||||
let storedData = JSON.parse(settings.persistentRndStorage);
|
||||
for (var domain in storedData){
|
||||
var value = storedData[domain];
|
||||
if (
|
||||
Array.isArray(value) &&
|
||||
value.length === 128 &&
|
||||
value.every(function(value){
|
||||
return typeof value === "number" && value >= 0 && value < 256;
|
||||
})
|
||||
){
|
||||
persistentRnd[domain] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(e){
|
||||
// JSON is not valid -> ignore it
|
||||
}
|
||||
|
||||
function updateContentScripts(){
|
||||
message("update content scripts");
|
||||
notice("build settings blob");
|
||||
|
@ -51,24 +31,26 @@
|
|||
warning("TODO: register content scripts -> have to wait for the API to be released");
|
||||
}
|
||||
updateContentScripts();
|
||||
persistentRndStorage.init();
|
||||
|
||||
message("register non port message listener");
|
||||
browser.runtime.onMessage.addListener(function(data){
|
||||
notice("got data without port", data);
|
||||
var keys = Object.keys(data);
|
||||
if (data["canvasBlocker-new-domain-rnd"]){
|
||||
verbose("got new domain rnd", data["canvasBlocker-new-domain-rnd"]);
|
||||
data["canvasBlocker-set-domain-rnd"] = data["canvasBlocker-new-domain-rnd"];
|
||||
persistentRnd[data["canvasBlocker-new-domain-rnd"].domain] = data["canvasBlocker-new-domain-rnd"].rnd;
|
||||
if (settings.storePersistentRnd){
|
||||
settings.persistentRndStorage = JSON.stringify(persistentRnd);
|
||||
persistentRndStorage.setDomainData(
|
||||
data["canvasBlocker-new-domain-rnd"].domain,
|
||||
data["canvasBlocker-new-domain-rnd"].rnd
|
||||
);
|
||||
if (keys.length === 1){
|
||||
return;
|
||||
}
|
||||
updateContentScripts();
|
||||
}
|
||||
if (data["canvasBlocker-clear-domain-rnd"]){
|
||||
verbose("domain rnd cleared");
|
||||
persistentRnd = Object.create(null);
|
||||
if (settings.storePersistentRnd){
|
||||
settings.persistentRndStorage = JSON.stringify(persistentRnd);
|
||||
persistentRndStorage.clear();
|
||||
if (keys.length === 1){
|
||||
return;
|
||||
}
|
||||
updateContentScripts();
|
||||
}
|
||||
|
@ -84,10 +66,10 @@
|
|||
browser.runtime.onConnect.addListener(function(port){
|
||||
notice("got port", port);
|
||||
verbose("send back the tab id", port.sender.tab.id);
|
||||
verbose("send back the persistent random seeds", persistentRnd);
|
||||
verbose("send back the persistent random seeds", persistentRndStorage.persistentRnd);
|
||||
port.postMessage({
|
||||
tabId: port.sender.tab.id,
|
||||
persistentRnd: persistentRnd
|
||||
persistentRnd: persistentRndStorage.persistentRnd
|
||||
});
|
||||
var url = new URL(port.sender.url);
|
||||
port.onMessage.addListener(function(data){
|
||||
|
@ -116,9 +98,6 @@
|
|||
});
|
||||
}
|
||||
});
|
||||
settings.on("storePersistentRnd", function({newValue}){
|
||||
settings.persistentRndStorage = newValue? JSON.stringify(persistentRnd): "";
|
||||
});
|
||||
|
||||
// hide page action when a tab is refreshed
|
||||
browser.tabs.onUpdated.addListener(function(tabId, data){
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue