Index: gc_lang/fr/webext/background.js ================================================================== --- gc_lang/fr/webext/background.js +++ gc_lang/fr/webext/background.js @@ -116,10 +116,11 @@ console.log(oRequest); xGCEWorker.postMessage(oRequest); break; default: console.log("[background] Unknown command: " + oRequest.sCommand); + console.log(oRequest); } }); xPort.postMessage({sActionDone: "newId", result: iPortId}); } Index: gc_lang/fr/webext/content_scripts/content_modifier.js ================================================================== --- gc_lang/fr/webext/content_scripts/content_modifier.js +++ gc_lang/fr/webext/content_scripts/content_modifier.js @@ -109,17 +109,17 @@ } function createTFPanel (xTextArea) { console.log("Formateur de texte"); if (oTFPanel !== null) { - oTFPanel.setTextArea(xTextArea); + oTFPanel.start(xTextArea); oTFPanel.show(); } else { // create the panel oTFPanel = new GrammalecteTextFormatter("grammalecte_tf_panel", "Formateur de texte", 800, 620, false); oTFPanel.logInnerHTML(); - oTFPanel.setTextArea(xTextArea); + oTFPanel.start(xTextArea); oTFPanel.insertIntoPage(); } } function createLxgPanel () { Index: gc_lang/fr/webext/content_scripts/tf_content.js ================================================================== --- gc_lang/fr/webext/content_scripts/tf_content.js +++ gc_lang/fr/webext/content_scripts/tf_content.js @@ -11,14 +11,10 @@ this.xTFNode = this._createTextFormatter(); this.xPanelContent.appendChild(this.xTFNode); this.xTextArea = null; } - setTextArea (xTextArea) { - this.xTextArea = xTextArea; - } - _createTextFormatter () { let xTFNode = document.createElement("div"); try { // Options let xOptions = createNode("div", {id: "grammalecte_tf_options"}); @@ -76,11 +72,11 @@ // Actions let xActions = createNode("div", {id: "grammalecte_tf_actions"}); let xDefaultButton = createNode("div", {id: "grammalecte_tf_reset", textContent: "Par défaut", className: "grammalecte_button", style: "background-color: hsl(210, 50%, 50%)"}); xDefaultButton.addEventListener("click", () => { this.reset(); }); let xApplyButton = createNode("div", {id: "grammalecte_tf_apply", textContent: "Appliquer", className: "grammalecte_button", style: "background-color: hsl(180, 50%, 50%)"}); - xApplyButton.addEventListener("click", () => { this.apply(); }); + xApplyButton.addEventListener("click", () => { this.saveOptions(); this.apply(); }); xActions.appendChild(xDefaultButton); xActions.appendChild(createNode("progress", {id: "grammalecte_tf_progressbar"})); xActions.appendChild(createNode("span", {id: "grammalecte_tf_time_res", textContent: "…"})); xActions.appendChild(xApplyButton); //xActions.appendChild(createNode("div", {id: "grammalecte_infomsg", textContent: "blabla"})); @@ -179,10 +175,16 @@ /* Actions */ + start (xTextArea) { + this.xTextArea = xTextArea; + let xPromise = browser.storage.local.get("tf_options"); + xPromise.then(this.setOptions.bind(this), this.reset.bind(this)); + } + switchGroup (sOptName) { if (document.getElementById(sOptName).checked) { document.getElementById(sOptName.slice(2)).style.opacity = 1; } else { document.getElementById(sOptName.slice(2)).style.opacity = 0.3; @@ -204,30 +206,32 @@ document.getElementById('grammalecte_tf_progressbar').value = 0; document.getElementById('grammalecte_tf_time_res').textContent = ""; } setOptions (oOptions) { - for (let sOptName in oOptions) { - //console.log(sOptName + ":" + oOptions[sOptName]); - if (document.getElementById(sOptName) !== null) { - document.getElementById(sOptName).checked = oOptions[sOptName]; - if (sOptName.startsWith("o_group_")) { - switchGroup(sOptName); - } - if (document.getElementById("res_"+sOptName) !== null) { - document.getElementById("res_"+sOptName).textContent = ""; - } + if (oOptions.hasOwnProperty("tf_options")) { + oOptions = oOptions.tf_options; + } + for (let xNode of document.getElementsByClassName("option")) { + //console.log(xNode.id + " > " + oOptions.hasOwnProperty(xNode.id) + ": " + oOptions[xNode.id] + " [" + xNode.dataset.default + "]"); + xNode.checked = (oOptions.hasOwnProperty(xNode.id)) ? oOptions[xNode.id] : (xNode.dataset.default === "true"); + if (document.getElementById("res_"+xNode.id) !== null) { + document.getElementById("res_"+xNode.id).textContent = ""; + } + if (xNode.id.startsWith("o_group_")) { + this.switchGroup(xNode.id); } } } saveOptions () { let oOptions = {}; for (let xNode of document.getElementsByClassName("option")) { oOptions[xNode.id] = xNode.checked; + console.log(xNode.id + ": " + xNode.checked); } - self.port.emit("saveOptions", JSON.stringify(oOptions)); + browser.storage.local.set({"tf_options": oOptions}); } apply () { try { const t0 = Date.now(); Index: gc_lang/fr/webext/manifest.json ================================================================== --- gc_lang/fr/webext/manifest.json +++ gc_lang/fr/webext/manifest.json @@ -61,11 +61,12 @@ "grammalecte/fr/tests_data.json", "img/logo-16.png" ], "permissions": [ "activeTab", - "contextMenus" + "contextMenus", + "storage" ], "chrome_settings_overrides": { "search_provider": { "name": "Grammalecte", "search_url": "https://www.dicollecte.org/dictionary.php?prj=fr&lemma={searchTerms}",