javascript - Firefox SDK access preferences from content script -
About
I work on Firefox add-on using Firefox add-ons SDK I am here. The add-on site will be unique and will hide some elements based on user preferences.
I have already made this add-on a few years ago, but the new SDK works a little differently with things.
code
Because the add-on is a site specific and I need to modify the content of the site I ' PageMod < / B> 'use the module
[ main. JS ]
PageMode Pagemode ({include: "* .ipvisie.com", content script file: [data.url ('jquery-1.11.1.min.js'), data.equal ('script.js')]});
This works great, jQuery is implemented and I can add javascript from script.js and
I ' package.json < / B> 'And this works great I can get it from' main.js '
problem
My problem is that content script '
How can I access existing preferences in my content script' script.js '?
Tried the endeavor
Effort 1
The attempt that I made was only the content of the script Prioritization was requested
if necessary ('SDK / simple-prefus'). Pref [['somePreference'] == true) {Warning ('prefix') ; }
attempt 2
I have read in the documentation that some parameters can be read only for content It seemed to work with the script, but when I changed my preferences, the prices were already set. Only if I restart the browser will the correct settings be passed. contentScriptOptions: {advertLink: Required ('SDK / Simple-Prefs') Pref [[advertTop]], advertDay: required ('Sdk / simple-prefs'). Prefuss ['advertDay'], advertAdmart: is required ('SDK / Simple-Prefs'). Pref [[advertAdmart]], advertLink: ('sdk / simple-prefs') is required. Prefs ['advertlink']}
"" post-text "itemprop =" text "> You should send new preferences to content scripts every time The priorities have been changed and not only on Script initiality.
You can communicate with the content script through messages:
Create a function that gets changed priority name and value, and a script:
PageMod.PageMod ({// ... onAttach: function (worker) {worker.port.on ("prefChange", function (prefName, prefValue) {// update page ...}); Forfor variable (prefanem) {Self.port.emit ("prefChange", prefName, is required ("sdk / simple-prefs"). Prefs [prefName]);} ("Sdk / simple-prefs"). (" ", OnPrefChange);}});
Comments
Post a Comment