Dzięki Wladimir Palant
za wskazanie kierunku, ale nadal zajęło mi trochę czasu, aby dowiedzieć się ostateczny kod. Osiągnąłem tutaj swój wynik, by móc w przyszłości nawiązać kontakt z innymi. (I uproszczony kod trochę tutaj dla celów opracowywania, ale podstawowa struktura powinna być prawidłowa.)
content.js: (Kliknij link, aby otworzyć stronę Opcje)
$("#options").click(function(){
self.port.emit("open_options", {});
});
background.js :
//regsiter the event
backgroundInit = function(worker) {
worker.port.on("open_options", function(request){
var tabs = require("sdk/tabs");
tabs.open({
//open a new tab to display options page
url: self.data.url("options.html"),
});
}
worker.port.on("pull_preferences", function(request){
var preferences = null;
//get preferences (from simple storage or API)
woker.emit("update_content_preferences", {preferences:preferences});
});
worker.port.on("push_preferences", function(request){
var preferences = request.preferences;
//write the preferences (to simple storage or API)
});
}
//register the page, note that you could register multiple ones
pageMod.PageMod({
include: self.data.url('options.html'),
contentScriptFile: [ self.data.url("lib/jquery-1.11.3.min.js"),
self.data.url("options.js")],
contentScriptWhen: 'end',
onAttach: backgroundInit
});
options.js: (ta strona jest również od kontekstu skryptu zawartość)
$(document).ready(function(){
self.port.on("update_content_preferences", function(request){
var preferences = request.preferences;
//update options page values using the preferences
});
$("#save").click(function(){
var preferences = null;
//get preferences from options page
self.port.emit("push_preferences", {preferences:preferences});
});
self.port.emit("pull_preferences", {}); //trigger the pull upon page start
});
Reference: https://developer.mozilla.org/en-US/Add-ons/SDK/High-Level_APIs/tabs
W porządku, użyłem modułu simple-prefs. Działa dobrze, dzięki za to! – dvcrn
dzięki @Wladimir .. fajny wpis .. – pratikabu
w końcu udało mi się zrealizować to, co powiedziałeś. Na pewno opublikuję roboczą próbkę tego, co zrobiłem .. dzięki za podpowiedzi .. – pratikabu