Index: gc_lang/fr/webext/background.js ================================================================== --- gc_lang/fr/webext/background.js +++ gc_lang/fr/webext/background.js @@ -121,13 +121,15 @@ const oInitHandler = { initUIOptions: function () { if (bChrome) { browser.storage.local.get("ui_options", this._initUIOptions); + browser.storage.local.get("autorefresh_option", this._initUIOptions); return; } browser.storage.local.get("ui_options").then(this._initUIOptions, showError); + browser.storage.local.get("autorefresh_option").then(this._initUIOptions, showError); }, initGrammarChecker: function () { if (bChrome) { browser.storage.local.get("gc_options", this._initGrammarChecker); @@ -149,10 +151,13 @@ browser.storage.local.set({"ui_options": { textarea: true, editablenode: true }}); } + if (!oSavedOptions.hasOwnProperty("autorefresh_option")) { + browser.storage.local.set({"autorefresh_option": true}); + } }, _initGrammarChecker: function (oSavedOptions) { try { let dOptions = (oSavedOptions.hasOwnProperty("gc_options")) ? oSavedOptions.gc_options : null; @@ -189,11 +194,10 @@ }, _initSCOptions: function (oData) { if (!oData.hasOwnProperty("sc_options")) { browser.storage.local.set({"sc_options": { - extended: true, community: true, personal: true }}); oWorkerHandler.xGCEWorker.postMessage({ sCommand: "setDictionaryOnOff", dParam: { sDictionary: "community", bActivate: true }, dInfo: {} }); oWorkerHandler.xGCEWorker.postMessage({ sCommand: "setDictionaryOnOff", dParam: { sDictionary: "personal", bActivate: true }, dInfo: {} }); Index: gc_lang/fr/webext/content_scripts/init.js ================================================================== --- gc_lang/fr/webext/content_scripts/init.js +++ gc_lang/fr/webext/content_scripts/init.js @@ -58,10 +58,12 @@ xObserver: null, sExtensionUrl: null, oOptions: null, + + bAutoRefresh: true, listenRightClick: function () { // Node where a right click is done // Bug report: https://bugzilla.mozilla.org/show_bug.cgi?id=1325814 document.addEventListener('contextmenu', (xEvent) => { @@ -280,10 +282,28 @@ xSelection.removeAllRanges(); xSelection.addRange(xRange); } }; + +function autoRefreshOption (oSavedOptions=null) { + // auto recallable function + if (oSavedOptions === null) { + if (bChrome) { + browser.storage.local.get("autorefresh_option", autoRefreshOption); + return; + } + browser.storage.local.get("autorefresh_option").then(autoRefreshOption, showError); + } + else if (oSavedOptions.hasOwnProperty("autorefresh_option")) { + console.log("autorefresh_option", oSavedOptions["autorefresh_option"]); + oGrammalecte.bAutoRefresh = oSavedOptions["autorefresh_option"]; + } +} + +autoRefreshOption(); + /* Connexion to the background */ let xGrammalectePort = browser.runtime.connect({name: "content-script port"}); @@ -291,11 +311,10 @@ xGrammalectePort.onMessage.addListener(function (oMessage) { let {sActionDone, result, dInfo, bEnd, bError} = oMessage; switch (sActionDone) { case "init": oGrammalecte.sExtensionUrl = oMessage.sUrl; - // Start oGrammalecte.listenRightClick(); oGrammalecte.createButtons(); oGrammalecte.observePage(); break; case "parseAndSpellcheck": Index: gc_lang/fr/webext/content_scripts/panel_gc.js ================================================================== --- gc_lang/fr/webext/content_scripts/panel_gc.js +++ gc_lang/fr/webext/content_scripts/panel_gc.js @@ -59,11 +59,10 @@ this.xPanelContent.addEventListener("click", onGrammalecteGCPanelClick, false); this.oTooltip = new GrammalecteTooltip(this.xParent, this.xGCPanelContent); this.xPanelContent.appendChild(this.xGCPanelContent); this.xNode = null; this.oTextControl = new GrammalecteTextControl(); - this.bAutoRefresh = false; this.nLastResult = 0 // Lexicographer this.nLxgCount = 0; this.xLxgPanelContent = oGrammalecte.createNode("div", {id: "grammalecte_lxg_panel_content"}); this.xPanelContent.appendChild(this.xLxgPanelContent); @@ -82,10 +81,12 @@ this.xLxgButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_button", textContent: "Lexicographe"}); this.xConjButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_button", textContent: "Conjugueur"}); this.xLEButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_button", textContent: "•Éditeur lexical•"}); this.xAutoRefresh = oGrammalecte.createNode("div", {className: "grammalecte_autorefresh_button", textContent: "AR", title: "Auto-rafraîchissement de la correction grammaticale (3 s après la dernière frappe)"}) this.xEditorButton.appendChild(this.xAutoRefresh); + this.bAutoRefresh = oGrammalecte.bAutoRefresh; + this.setAutoRefreshButton(); this.xTFButton.onclick = () => { if (!this.bWorking) { oGrammalecte.createTFPanel(); oGrammalecte.oTFPanel.start(); oGrammalecte.oTFPanel.show(); @@ -96,13 +97,13 @@ this.showEditor(); } }; this.xAutoRefresh.onclick = () => { this.bAutoRefresh = !this.bAutoRefresh; - this.xAutoRefresh.style.backgroundColor = (this.bAutoRefresh) ? "hsl(150, 50%, 50%)" : ""; - this.xAutoRefresh.style.color = (this.bAutoRefresh) ? "hsl(150, 50%, 96%)" : ""; - this.xAutoRefresh.style.opacity = (this.bAutoRefresh) ? "1" : ""; + oGrammalecte.bAutoRefresh = this.bAutoRefresh; + browser.storage.local.set({"autorefresh_option": this.bAutoRefresh}); + this.setAutoRefreshButton(); } this.xLxgButton.onclick = () => { if (!this.bWorking) { this.showLexicographer(); this.clearLexicographer(); @@ -125,10 +126,11 @@ } }; this.xLEButton.onclick = () => { xGrammalectePort.postMessage({sCommand: "openLexiconEditor", dParam: null, dInfo: null}); }; + // Menu, tabs this.xMenu.appendChild(this.xTFButton) this.xMenu.appendChild(this.xEditorButton) this.xMenu.appendChild(this.xLxgButton) this.xMenu.appendChild(this.xConjButton) this.xMenu.appendChild(this.xLEButton) @@ -153,10 +155,16 @@ // error oGrammalecte.oMessageBox.showMessage("[BUG] Analyse d’un élément inconnu…"); console.log("Grammalecte [bug]:", what); } } + + setAutoRefreshButton () { + this.xAutoRefresh.style.backgroundColor = (this.bAutoRefresh) ? "hsl(150, 50%, 50%)" : ""; + this.xAutoRefresh.style.color = (this.bAutoRefresh) ? "hsl(150, 50%, 96%)" : ""; + this.xAutoRefresh.style.opacity = (this.bAutoRefresh) ? "1" : ""; + } recheckAll () { this.oTooltip.hide(); this.showEditor(); this.clear();