Index: gc_lang/fr/webext/content_scripts/panel.css ================================================================== --- gc_lang/fr/webext/content_scripts/panel.css +++ gc_lang/fr/webext/content_scripts/panel.css @@ -144,11 +144,22 @@ border-radius: 3px; } div.grammalecte_menu_button:hover { background-color: hsl(210, 80%, 40%); } - +div.grammalecte_autorefresh_button { + display: inline-block; + padding: 1px 5px; + margin-left: 5px; + border-radius: 3px; + background-color: hsl(0, 50%, 50%); + color: hsl(0, 50%, 96%); + opacity: .7; +} +div.grammalecte_autorefresh_button:hover { + opacity: 1; +} div.grammalecte_panel_content { /* https://stackoverflow.com/questions/7676022/html5-flexible-box-model-height-calculation/15388247#15388247 */ position: relative; flex-grow: 1; 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,10 +59,11 @@ 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; // Lexicographer this.nLxgCount = 0; this.xLxgPanelContent = oGrammalecte.createNode("div", {id: "grammalecte_lxg_panel_content"}); this.xPanelContent.appendChild(this.xLxgPanelContent); // Conjugueur @@ -78,10 +79,12 @@ this.xTFButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_button", textContent: "Formateur de texte"}); this.xEditorButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_button", textContent: "Éditeur"}); 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"}) + this.xEditorButton.appendChild(this.xAutoRefresh); this.xTFButton.onclick = () => { if (!this.bWorking) { oGrammalecte.createTFPanel(); oGrammalecte.oTFPanel.start(); oGrammalecte.oTFPanel.show(); @@ -90,10 +93,18 @@ this.xEditorButton.onclick = () => { if (!this.bWorking) { this.showEditor(); } }; + this.xAutoRefresh.onclick = () => { + console.log("autor"); + 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" : ""; + console.log("on"); + } this.xLxgButton.onclick = () => { if (!this.bWorking) { this.showLexicographer(); this.clearLexicographer(); this.startWaitIcon(); @@ -215,17 +226,19 @@ // paragraph let xParagraph = oGrammalecte.createNode("p", {id: "grammalecte_paragraph"+oResult.iParaNum, className: "grammalecte_paragraph", lang: "fr", contentEditable: "true"}, {para_num: oResult.iParaNum}); xParagraph.setAttribute("spellcheck", "false"); // doesn’t seem possible to use “spellcheck” as a common attribute. xParagraph.dataset.timer_id = "0"; xParagraph.addEventListener("input", function (xEvent) { - // timer for refreshing analysis - window.clearTimeout(parseInt(xParagraph.dataset.timer_id)); - xParagraph.dataset.timer_id = window.setTimeout(this.recheckParagraph.bind(this), 3000, oResult.iParaNum); - // save caret position - let [nStart, nEnd] = oGrammalecte.getCaretPosition(xParagraph); - xParagraph.dataset.caret_position_start = nStart; - xParagraph.dataset.caret_position_end = nEnd; + if (this.bAutoRefresh) { + // timer for refreshing analysis + window.clearTimeout(parseInt(xParagraph.dataset.timer_id)); + xParagraph.dataset.timer_id = window.setTimeout(this.recheckParagraph.bind(this), 3000, oResult.iParaNum); + // save caret position + let [nStart, nEnd] = oGrammalecte.getCaretPosition(xParagraph); + xParagraph.dataset.caret_position_start = nStart; + xParagraph.dataset.caret_position_end = nEnd; + } // write text this.oTextControl.setParagraph(parseInt(xEvent.target.dataset.para_num), this.purgeText(xEvent.target.textContent)); this.oTextControl.write(); }.bind(this) , true);