0

I've got a content script that should be added on page if I select this preference in addon settings. I can add bool setting, but I absolutely can't understand how to operate with it on main.js file. The setting is

  "preferences": [{
        "description": "",
        "name": "tagHide",
        "type": "bool",
        "value": false,
        "title": "Hide something"}]

And in the main file I added this

var data = require("sdk/self").data;
var pageMod = require("sdk/page-mod");
var prefs = require("sdk/simple-prefs").prefs;
function onPrefChange(prefName) {
    if (prefs.tagHide) {
        console.log(prefs.tagHide);
        pageMod.PageMod({
            include: "*.corbina.net",
            contentScriptFile: data.url("cutter.js")
        });
    };
}

This code logs "true" of "false" in the console, but pagemod seems not working. Any errors I've got here?

1 Answer 1

2

There are a few issues with this code as-is:

  • you don't bind onPrefChange anywhere in this code, eg require("sdk/simple-prefs").on("", onPrefChange);, see the docs
  • you don't apply the page-mod to existing tabs, see the docs here specifically the attachTo option.
  • even if your page-mod attached, there is no way I can see that you unload the content script's effects?
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks alot, added onPrefChange and it works like a charm. Still sarching about how to remove contentscript though

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.