Question

I'm currently trying to add some preferences to a Firefox add-on. To do so, I'm playing with the new "simple-prefs" module. (Simple-Prefs on the Mozilla Blog)

The documentation is not very detailed and I face some problems understanding how I can retrieve the value attached to an option and export it to a JS script present in my data folder.

Let's say that I have only one optional setting in my addon, a boolean one, then my packages.json will look like this:

{
  "name": "test",
  ...
  "preferences": [{
    "type": "bool",
    "name": "option1",
    "value": true,
    "title": "Desc Option 1" 
  }]
}

Here is my main.js file [UPDATED]:

var pageMod = require("page-mod");
const data = require("self").data;
const prefSet = require("simple-prefs");  //Simple-prefs module

var option1 = prefSet.prefs.option1;     //get the value for option1

function onPrefChange(prefName) {        //Listen for changes

   var prefName = prefSet.prefs[prefName];
                      }

prefSet.on("option1", onPrefChange);


exports.main = function() {
  pageMod.PageMod({ 
    include: ["https://mail.google.com/*","http://mail.google.com/*"],
    contentScriptWhen: 'ready',
    contentScriptFile: [data.url("jquery.js"),data.url("script.js")],
    onAttach: function(worker)
        {
      worker.postMessage( option1 );
        }
    });
}

How can I retrieve the value attached to "option1" and export it in order to call it in my "script.js" file?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top