Index: gc_lang/fr/webext/background.js ================================================================== --- gc_lang/fr/webext/background.js +++ gc_lang/fr/webext/background.js @@ -171,11 +171,11 @@ title: "Corriger", contexts: ["selection"] }); browser.contextMenus.create({ - id: "whatever", + id: "separator1", type: "separator", contexts: ["selection"] }); browser.contextMenus.create({ @@ -188,10 +188,21 @@ id: "conjugueur_tab", title: "Conjugueur [onglet]", contexts: ["all"] }); +browser.contextMenus.create({ + id: "separator2", + type: "separator", + contexts: ["editable"] +}); + +browser.contextMenus.create({ + id: "rescanPage", + title: "Rechercher à nouveau les zones de texte", + contexts: ["editable"] +}); browser.contextMenus.onClicked.addListener(function (xInfo, xTab) { // xInfo = https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/contextMenus/OnClickData // xTab = https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/tabs/Tab // confusing: no way to get the node where we click?! @@ -206,10 +217,14 @@ openConjugueurWindow(); break; case "conjugueur_tab": openConjugueurTab(); break; + case "rescanPage": + let xPort = dConnx.get(xTab.id); + xPort.postMessage({sActionDone: "rescanPage"}); + break; default: console.log("[Background] Unknown menu id: " + xInfo.menuItemId); console.log(xInfo); console.log(xTab); } 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 @@ -57,10 +57,21 @@ for (let xNode of lNode) { this.lMenu.push(new GrammalecteMenu(this.nMenu, xNode)); this.nMenu += 1; } }, + + rescanPage: function () { + if (this.oTFPanel !== null) { this.oTFPanel.hide(); } + if (this.oLxgPanel !== null) { this.oLxgPanel.hide(); } + if (this.oGCPanel !== null) { this.oGCPanel.hide(); } + for (let oMenu of this.lMenu) { + oMenu.deleteNodes(); + } + this.lMenu.length = 0; // to clear an array + this.createMenus(); + }, createTFPanel: function () { if (this.oTFPanel === null) { this.oTFPanel = new GrammalecteTextFormatter("grammalecte_tf_panel", "Formateur de texte", 760, 600, false); //this.oTFPanel.logInnerHTML(); @@ -126,10 +137,13 @@ oGrammalecte.createLxgPanel(); oGrammalecte.oLxgPanel.clear(); oGrammalecte.oLxgPanel.show(); oGrammalecte.oLxgPanel.startWaitIcon(); break; + case "rescanPage": + oGrammalecte.rescanPage(); + break; default: console.log("[Content script] Unknown command: " + sActionDone); } }); Index: gc_lang/fr/webext/content_scripts/menu.js ================================================================== --- gc_lang/fr/webext/content_scripts/menu.js +++ gc_lang/fr/webext/content_scripts/menu.js @@ -5,15 +5,15 @@ class GrammalecteMenu { constructor (nMenu, xTextArea) { this.sMenuId = "grammalecte_menu" + nMenu; - let xButton = createNode("div", {className: "grammalecte_menu_main_button", textContent: " "}); - xButton.onclick = () => { this.switchMenu(); }; - let xMenu = this._createMenu(xTextArea); - this._insertAfter(xButton, xTextArea); - this._insertAfter(xMenu, xTextArea); + this.xButton = createNode("div", {className: "grammalecte_menu_main_button", textContent: " "}); + this.xButton.onclick = () => { this.switchMenu(); }; + this.xMenu = this._createMenu(xTextArea); + this._insertAfter(this.xButton, xTextArea); + this._insertAfter(this.xMenu, xTextArea); } _insertAfter (xNewNode, xReferenceNode) { xReferenceNode.parentNode.insertBefore(xNewNode, xReferenceNode.nextSibling); } @@ -84,11 +84,16 @@ } catch (e) { showError(e); } } + + deleteNodes () { + this.xMenu.parentNode.removeChild(this.xMenu); + this.xButton.parentNode.removeChild(this.xButton); + } switchMenu () { let xMenu = document.getElementById(this.sMenuId); xMenu.style.display = (xMenu.style.display == "block") ? "none" : "block"; } }