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,18 @@ for (let xNode of lNode) { this.lMenu.push(new GrammalecteMenu(this.nMenu, xNode)); this.nMenu += 1; } }, + + createMenus2 () { + let lNode = document.querySelectorAll("[contenteditable]"); + 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(); } @@ -150,5 +158,6 @@ /* Start */ oGrammalecte.createMenus(); +oGrammalecte.createMenus2(); 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 @@ -3,81 +3,83 @@ "use strict"; class GrammalecteMenu { - constructor (nMenu, xTextArea) { + constructor (nMenu, xNode) { this.sMenuId = "grammalecte_menu" + nMenu; 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); + this.xMenu = this._createMenu(xNode); + this._insertAfter(this.xButton, xNode); + this._insertAfter(this.xMenu, xNode); } _insertAfter (xNewNode, xReferenceNode) { xReferenceNode.parentNode.insertBefore(xNewNode, xReferenceNode.nextSibling); } - _createMenu (xTextArea) { + _createMenu (xNode) { try { + let sText = (xNode.tagName == "TEXTAREA") ? xNode.value : xNode.textContent; let xMenu = createNode("div", {id: this.sMenuId, className: "grammalecte_menu"}); + xMenu.appendChild(createNode("div", {className: "grammalecte_menu_header", textContent: "GRAMMALECTE"})); // Text formatter - let xTFButton = createNode("div", {className: "grammalecte_menu_item", textContent: "Formateur de texte"}); - xTFButton.onclick = () => { - this.switchMenu(); - oGrammalecte.createTFPanel(); - oGrammalecte.oTFPanel.start(xTextArea); - oGrammalecte.oTFPanel.show(); - }; + if (xNode.tagName == "TEXTAREA") { + let xTFButton = createNode("div", {className: "grammalecte_menu_item", textContent: "Formateur de texte"}); + xTFButton.onclick = () => { + this.switchMenu(); + oGrammalecte.createTFPanel(); + oGrammalecte.oTFPanel.start(xNode); + oGrammalecte.oTFPanel.show(); + }; + xMenu.appendChild(xTFButton); + } // lexicographe let xLxgButton = createNode("div", {className: "grammalecte_menu_item", textContent: "Lexicographe"}); xLxgButton.onclick = () => { - this.switchMenu(); + this.switchMenu(); oGrammalecte.createLxgPanel(); oGrammalecte.oLxgPanel.clear(); oGrammalecte.oLxgPanel.show(); oGrammalecte.oLxgPanel.startWaitIcon(); xGrammalectePort.postMessage({ sCommand: "getListOfTokens", - dParam: {sText: xTextArea.value}, - dInfo: {sTextAreaId: xTextArea.id} + dParam: {sText: sText}, + dInfo: {sTextAreaId: xNode.id} }); }; + xMenu.appendChild(xLxgButton); // Grammar checker let xGCButton = createNode("div", {className: "grammalecte_menu_item", textContent: "Correction grammaticale"}); xGCButton.onclick = () => { - this.switchMenu(); + this.switchMenu(); oGrammalecte.createGCPanel(); - oGrammalecte.oGCPanel.start(xTextArea); + oGrammalecte.oGCPanel.start(xNode); oGrammalecte.oGCPanel.show(); oGrammalecte.oGCPanel.startWaitIcon(); xGrammalectePort.postMessage({ sCommand: "parseAndSpellcheck", - dParam: {sText: xTextArea.value, sCountry: "FR", bDebug: false, bContext: false}, - dInfo: {sTextAreaId: xTextArea.id} + dParam: {sText: sText, sCountry: "FR", bDebug: false, bContext: false}, + dInfo: {sTextAreaId: xNode.id} }); }; + xMenu.appendChild(xGCButton); // Conjugation tool let xConjButton = createNode("div", {className: "grammalecte_menu_item_block", textContent: "Conjugueur"}); let xConjButtonTab = createNode("div", {className: "grammalecte_menu_button", textContent: "Onglet"}); xConjButtonTab.onclick = () => { - this.switchMenu(); - xGrammalectePort.postMessage({sCommand: "openConjugueurTab", dParam: null, dInfo: null}); + this.switchMenu(); + xGrammalectePort.postMessage({sCommand: "openConjugueurTab", dParam: null, dInfo: null}); }; let xConjButtonWin = createNode("div", {className: "grammalecte_menu_button", textContent: "Fenêtre"}); xConjButtonWin.onclick = () => { - this.switchMenu(); - xGrammalectePort.postMessage({sCommand: "openConjugueurWindow", dParam: null, dInfo: null}); + this.switchMenu(); + xGrammalectePort.postMessage({sCommand: "openConjugueurWindow", dParam: null, dInfo: null}); }; xConjButton.appendChild(xConjButtonTab); xConjButton.appendChild(xConjButtonWin); - // Create - xMenu.appendChild(createNode("div", {className: "grammalecte_menu_header", textContent: "GRAMMALECTE"})); - xMenu.appendChild(xTFButton); - xMenu.appendChild(xLxgButton); - xMenu.appendChild(xGCButton); xMenu.appendChild(xConjButton); //xMenu.appendChild(createNode("img", {scr: browser.extension.getURL("img/logo-16.png")})); // can’t work, due to content-script policy: https://bugzilla.mozilla.org/show_bug.cgi?id=1267027 xMenu.appendChild(createNode("div", {className: "grammalecte_menu_footer"})); return xMenu; @@ -91,9 +93,9 @@ this.xMenu.parentNode.removeChild(this.xMenu); this.xButton.parentNode.removeChild(this.xButton); } switchMenu () { - let xMenu = document.getElementById(this.sMenuId); + let xMenu = document.getElementById(this.sMenuId); xMenu.style.display = (xMenu.style.display == "block") ? "none" : "block"; } } 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 @@ -53,15 +53,15 @@ this.oTooltip = new GrammalecteTooltip(this.xContentNode); this.xPanelContent.appendChild(this.xContentNode); this.oTAC = new GrammalecteTextAreaControl(); } - start (xTextArea=null) { + start (xNode=null) { this.oTooltip.hide(); this.clear(); - if (xTextArea) { - this.oTAC.setTextArea(xTextArea); + if (xNode && xNode.tagName == "TEXTAREA") { + this.oTAC.setTextArea(xNode); } } clear () { while (this.xParagraphList.firstChild) { @@ -448,11 +448,11 @@ this._dParagraph.set(i, sText.slice(iStart, iEnd)); i++; iStart = iEnd+1; } this._dParagraph.set(i, sText.slice(iStart)); - console.log("Paragraphs number: " + (i+1)); + //console.log("Paragraphs number: " + (i+1)); } write () { if (this._xTextArea !== null) { let sText = "";