i have a simple pagemod which applies on every domain:
var list = [];
var p = require("sdk/page-mod");
var pm = p.PageMod({include:"*", exclude:list, ... });
i created a context menu item where i add current domain to the exclude list and then i destroy the pagemod with pm.destroy(); and want to create it again, but that doesn’t work.
how can i instantly apply my updated exclude list?
here it is, simplified… i tried once again from scratch and it stil doesn’t do anything after destroy() - the pagemod doesn’t exist and isn’t applied to any website anymore.
part 1:
var global_settings = {
include:"*",
exclude:[],
contentStyleFile:d.url("css/common.css")
};
var global_mod = p.PageMod(global_settings);
part 2, context menu:
cm.Item({
label:"Exclude this domain",
context:cm.SelectorContext("*"),
contentScript: 'self.on("click", function (node, data) {' +
' self.postMessage(document.location.hostname);' +
'});',
onMessage: function (domain) {
console.log(domain);
global_settings.exclude[global_settings.exclude.length] = domain;
global_mod.destroy();
global_mod = p.PageMod(global_settings);
}
});
Two things I can think of (didn’t test), does global_mod exist after it’s destroyed? If not, then even if you did var global_mod it wouldn’t exist after the block it’s in is closed on the next line. Second, is p.PageMod itself changing?