Index: gc_lang/fr/mailext/background.js ================================================================== --- gc_lang/fr/mailext/background.js +++ gc_lang/fr/mailext/background.js @@ -356,10 +356,11 @@ console.log("[background] Unknown command: " + sCommand); console.log(oRequest); } }); //xPort.postMessage({sActionDone: "newId", result: iPortId}); + //console.log("[Grammalecte] init connection to content-script"); xPort.postMessage({sActionDone: "init", sUrl: browser.extension.getURL("")}); } browser.runtime.onConnect.addListener(handleConnexion); @@ -368,16 +369,12 @@ /* ComposeAction (Thunderbird only) */ if (bThunderbird) { - console.log("[Grammalecte] Thunderbird: listening compose action..."); browser.composeAction.onClicked.addListener(function (xTab, xData) { - console.log("ComposeAction clicked"); - console.log(xTab); - console.log(xData); - browser.tabs.sendMessage(xTab.id, {sActionRequest: "grammar_checker_compose_window"}); + sendCommandToTab(xTab.id, "grammar_checker_compose_window"); }); } /* ADDED gc_lang/fr/webext/content_scripts/editor.js Index: gc_lang/fr/webext/content_scripts/editor.js ================================================================== --- gc_lang/fr/webext/content_scripts/editor.js +++ gc_lang/fr/webext/content_scripts/editor.js @@ -0,0 +1,96 @@ +// JavaScript + +// Editor for HTML page + + +"use strict"; + + +class HTMLPageEditor { + + constructor (xRootNode=document.rootElement, bCheckSignature=false) { + this.xRootNode = xRootNode; + this.lNode = []; + this.bCheckSignature = bCheckSignature; + this._lParsableNodes = ["P", "LI"]; + this._lRootNodes = ["DIV", "UL", "OL"]; + + } + + * _getParsableNodes (xRootNode) { + // recursive function + try { + for (let xNode of this.xRootNode.childNodes) { + if (xNode.className !== "moz-cite-prefix" && xNode.tagName !== "BLOCKQUOTE" + && (xNode.nodeType == Node.TEXT_NODE || (xNode.nodeType == Node.ELEMENT_NODE && !xNode.textContent.startsWith(">"))) + && xNode.textContent !== "") { + if (xNode.tagName === undefined) { + if (!this.bCheckSignature && xNode.textContent.startsWith("-- ")) { + break; + } + yield xNode; + } + else if (this._lParsableNodes.includes(xNode.tagName)) { + yield xNode; + } + else if (this._lRootNodes.includes(xNode.tagName)) { + yield* this._getParsableNodes(xNode); + } + } + } + } + catch (e) { + showError(e); + } + } + + * getParagraphs () { + try { + let i = 0; + for (let xNode of this._getParsableNodes()) { + this.lNode.push(xNode); + yield [i, xNode.textContent]; + i += 1; + } + } + catch (e) { + showError(e); + } + } + + getPageText () { + try { + let sPageText = ""; + for (let [i, sLine] of this.getParagraphs()) { + sPageText += sLine + "\n"; + } + return sPageText; + } + catch (e) { + showError(e); + } + } + + getParagraph (iPara) { + try { + return this.lNode[iPara].textContent; + } + catch (e) { + showError(e); + } + } + + writeParagraph (iPara, sText) { + try { + return this.lNode[iPara].textContent = sText; + } + catch (e) { + showError(e); + } + } + + changeParagraph (iPara, sModif, iStart, iEnd) { + let sText = this.getParagraph(iPara); + this.writeParagraph(iPara, sText.slice(0, iStart) + sModif + sText.slice(iEnd)); + } +} 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 @@ -383,10 +383,11 @@ }.bind(this)); this.xConnect.onMessage.addListener(function (oMessage) { let { sActionDone, result, oInfo, bEnd, bError } = oMessage; switch (sActionDone) { case "init": + //console.log("[Grammalecte] content-script: init"); this.bConnected = true; oGrammalecte.sExtensionUrl = oMessage.sUrl; oGrammalecte.listen(); oGrammalecte.createButton(); break;