DELETED gc_lang/fr/webext/content_scripts/gc_content.css Index: gc_lang/fr/webext/content_scripts/gc_content.css ================================================================== --- gc_lang/fr/webext/content_scripts/gc_content.css +++ /dev/null @@ -1,366 +0,0 @@ -/* - Grammar checker -*/ -#grammalecte_gc_panel_content { - margin: 0; - padding: 5px; -} - -.grammalecte_paragraph_block { - margin: 0 0 5px 0; -} - -.grammalecte_paragraph { - margin: 0; - padding: 10px; - background-color: hsl(0, 0%, 96%); - border-radius: 2px; - font-size: 14px; - font-family : "Courier New", Courier, "Lucida Sans Typewriter", "Lucida Typewriter", monospace; - color: hsl(0, 0%, 0%); -} - -.grammalecte_paragraph a { - background-color: hsla(210, 50%, 50%, 1); - padding: 1px 5px; - border-radius: 2px; - color: hsla(210, 0%, 96%, 1); - cursor: pointer; - text-decoration: none; -} -.grammalecte_paragraph a:hover { - background-color: hsla(210, 60%, 40%, 1); - color: hsla(0, 0%, 100%, 1); - text-shadow: 0 0 3px hsl(210, 30%, 60%); -} - -.grammalecte_paragraph u { - text-decoration: none; -} - -.grammalecte_paragraph u.corrected, -.grammalecte_paragraph u.ignored { - background-color: hsla(120, 50%, 70%, 1); - color: hsla(0, 0%, 4%, 1); - border-radius: 2px; - text-decoration: none; -} -.grammalecte_paragraph u.ignored { - background-color: hsla(30, 20%, 80%, 1); -} - -.grammalecte_paragraph u.error { - position: relative; - cursor: pointer; - border-radius: 2px; - text-decoration: none; /* to remove for wavy underlines */ -} -.grammalecte_paragraph u.error:hover { - cursor: pointer; -} - - -/* - Action buttons -*/ - -.grammalecte_paragraph_actions { - float: right; - margin: 0 0 5px 10px; -} - -.grammalecte_paragraph_actions .button { - display: inline-block; - background-color: hsl(0, 0%, 50%); - text-align: center; - margin-left: 2px; - padding: 1px 4px 3px 4px; - cursor: pointer; - font-size: 14px; - color: hsl(0, 0%, 96%); - border-radius: 2px; -} -.grammalecte_paragraph_actions .button:hover { - background-color: hsl(0, 0%, 40%); - color: hsl(0, 0%, 100%); -} - -.grammalecte_paragraph_actions .green { - background-color: hsl(120, 30%, 50%); - color: hsl(0, 0%, 96%); -} -.grammalecte_paragraph_actions .green:hover { - background-color: hsl(120, 50%, 40%); - color: hsl(0, 0%, 100%); -} -.grammalecte_paragraph_actions .red { - background-color: hsl(0, 30%, 50%); - color: hsl(0, 0%, 96%); -} -.grammalecte_paragraph_actions .red:hover { - background-color: hsl(0, 50%, 40%); - color: hsl(0, 0%, 100%); -} -.grammalecte_paragraph_actions .orange { - background-color: hsl(30, 50%, 50%); - color: hsl(30, 0%, 96%); -} -.grammalecte_paragraph_actions .orange:hover { - background-color: hsl(30, 70%, 40%); - color: hsl(30, 0%, 100%); -} -.grammalecte_paragraph_actions .bold { - font-weight: bold; -} - - - -/* - TOOLTIP -*/ -#grammalecte_tooltip_arrow { - position: absolute; - display: none; -} - -#grammalecte_tooltip { - position: absolute; - margin: 0; - display: none; - width: 300px; - border-radius: 5px; - box-shadow: 0 0 6px hsla(0, 0%, 0%, 0.3); - font-family: Tahoma, "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", sans-serif; - font-size: 12px; - line-height: 18px; - cursor: default; - text-decoration: none; - border: 3px solid hsl(210, 50%, 30%); - color: hsla(210, 10%, 20%, 1); - z-index: 1000; -} - -#grammalecte_tooltip_message_block { - margin: 0; - padding: 5px 10px 10px 10px; - background-color: hsl(210, 50%, 30%); - color: hsl(210, 50%, 96%); -} -#grammalecte_tooltip_rule_id { - display: none; - margin: 0 0 5px 0; - border: 1px solid hsl(210, 50%, 60%); - background-color: hsl(210, 50%, 40%); - padding: 2px 5px; - border-radius: 2px; - color: hsla(210, 0%, 96%, 1); - font-size: 11px; - font-style: normal; - text-align: center; -} -#grammalecte_tooltip_message { - font-size: 15px; - margin: 0 0 5px 0; -} -#grammalecte_tooltip_ignore { - display: inline-block; - padding: 2px 5px; - background-color: hsla(30, 30%, 40%, 1); - color: hsla(30, 0%, 96%, 1); - border-radius: 2px; - cursor: pointer; - text-decoration: none; -} -#grammalecte_tooltip_ignore:hover { - background-color: hsla(30, 30%, 50%, 1); - color: hsla(0, 0%, 100%, 1); - text-shadow: 0 0 3px hsl(30, 30%, 60%); -} -#grammalecte_tooltip_url { - display: inline-block; - margin: 0 0 0 10px; - padding: 2px 5px; - background-color: hsla(210, 50%, 50%, 1); - color: hsla(210, 0%, 96%, 1); - border-radius: 2px; - cursor: pointer; - text-decoration: none; -} -#grammalecte_tooltip_url:hover { - background-color: hsla(210, 50%, 60%, 1); - color: hsla(0, 0%, 100%, 1); - text-shadow: 0 0 3px hsl(210, 30%, 60%); -} -#grammalecte_tooltip_sugg_title { - padding: 0 10px; - background-color: hsl(210, 10%, 90%); - color: hsl(210, 50%, 30%); - font-size: 10px; - font-weight: bold; -} -#grammalecte_tooltip_sugg_block { - padding: 10px; - background-color: hsl(210, 10%, 96%); - border-radius: 0 0 2px 2px; - line-height: 20px; -} -#grammalecte_tooltip_sugg_block a.sugg { - padding: 1px 6px; - background-color: hsla(180, 60%, 40%, 1); - color: hsla(180, 0%, 96%, 1); - border-radius: 2px; - cursor: pointer; - text-decoration: none; -} -#grammalecte_tooltip_sugg_block a.sugg:hover { - background-color: hsla(180, 70%, 45%, 1); - color: hsla(0, 0%, 100%, 1); -} - - -/* - ERRORS -*/ - -.grammalecte_paragraph .error { - /* default color */ - background-color: hsl(240, 10%, 50%); - color: hsl(240, 0%, 96%); -} -.grammalecte_paragraph .error:hover { - background-color: hsl(240, 10%, 40%); - color: hsl(240, 0%, 100%); -} - -/* elems */ -.grammalecte_paragraph .WORD { - background-color: hsl(0, 50%, 50%); - color: hsl(0, 0%, 96%); - /*text-decoration: underline wavy hsl(0, 50%, 50%);*/ -} -.grammalecte_paragraph .WORD:hover { - background-color: hsl(0, 60%, 40%); - color: hsl(0, 0%, 100%); -} - -/* elems */ -.grammalecte_paragraph .typo, -.grammalecte_paragraph .esp, -.grammalecte_paragraph .nbsp, -.grammalecte_paragraph .eif, -.grammalecte_paragraph .maj, -.grammalecte_paragraph .virg, -.grammalecte_paragraph .tu, -.grammalecte_paragraph .num, -.grammalecte_paragraph .unit, -.grammalecte_paragraph .nf, -.grammalecte_paragraph .liga, -.grammalecte_paragraph .mapos, -.grammalecte_paragraph .chim { - background-color: hsl(30, 70%, 50%); - color: hsl(30, 10%, 96%); - /*text-decoration: underline wavy hsl(30, 70%, 50%);*/ -} - -.grammalecte_paragraph .typo:hover, -.grammalecte_paragraph .esp:hover, -.grammalecte_paragraph .nbsp:hover, -.grammalecte_paragraph .eif:hover, -.grammalecte_paragraph .maj:hover, -.grammalecte_paragraph .virg:hover, -.grammalecte_paragraph .tu:hover, -.grammalecte_paragraph .num:hover, -.grammalecte_paragraph .unit:hover, -.grammalecte_paragraph .nf:hover, -.grammalecte_paragraph .liga:hover, -.grammalecte_paragraph .mapos:hover, -.grammalecte_paragraph .chim:hover { - background-color: hsl(30, 80%, 45%); - color: hsl(30, 10%, 96%); -} - -/* elems */ -.grammalecte_paragraph .apos { - background-color: hsl(40, 90%, 50%); - color: hsl(40, 10%, 96%); - /*text-decoration: underline wavy hsl(40, 70%, 45%);*/ -} -.grammalecte_paragraph .apos:hover { - background-color: hsl(40, 100%, 45%); - color: hsl(40, 10%, 96%); -} - -/* elems */ -.grammalecte_paragraph .gn, -.grammalecte_paragraph .sgpl { - background-color: hsl(210, 50%, 50%); - color: hsl(210, 10%, 96%); - /*text-decoration: underline wavy hsl(210, 50%, 50%);*/ -} -.grammalecte_paragraph .gn:hover, -.grammalecte_paragraph .sgpl:hover { - background-color: hsl(210, 60%, 40%); - color: hsl(210, 10%, 96%); -} - -/* elems */ -.grammalecte_paragraph .conj, -.grammalecte_paragraph .infi, -.grammalecte_paragraph .imp, -.grammalecte_paragraph .inte, -.grammalecte_paragraph .ppas, -.grammalecte_paragraph .vmode { - background-color: hsl(300, 30%, 40%); - color: hsl(300, 10%, 96%); - /*text-decoration: underline wavy hsl(300, 40%, 40%);*/ -} - -.grammalecte_paragraph .conj:hover, -.grammalecte_paragraph .infi:hover, -.grammalecte_paragraph .imp:hover, -.grammalecte_paragraph .inte:hover, -.grammalecte_paragraph .ppas:hover, -.grammalecte_paragraph .vmode:hover { - background-color: hsl(300, 40%, 30%); - color: hsl(300, 10%, 96%); -} - -/* elems */ -.grammalecte_paragraph .conf, -.grammalecte_paragraph .ocr { - background-color: hsl(270, 40%, 30%); - color: hsl(270, 10%, 96%); - /*text-decoration: underline wavy hsl(270, 40%, 30%);*/ -} - -.grammalecte_paragraph .conf:hover, -.grammalecte_paragraph .ocr:hover { - background-color: hsl(270, 50%, 20%); - color: hsl(270, 10%, 96%); -} - -/* elems */ -.grammalecte_paragraph .bs, -.grammalecte_paragraph .pleo, -.grammalecte_paragraph .neg, -.grammalecte_paragraph .redon1, -.grammalecte_paragraph .redon2, -.grammalecte_paragraph .mc, -.grammalecte_paragraph .date, -.grammalecte_paragraph .notype { - background-color: hsl(180, 50%, 40%); - color: hsl(180, 10%, 96%); - /*text-decoration: underline wavy hsl(180, 50%, 40%);*/ -} - -.grammalecte_paragraph .bs:hover, -.grammalecte_paragraph .pleo:hover, -.grammalecte_paragraph .neg:hover, -.grammalecte_paragraph .redon1:hover, -.grammalecte_paragraph .redon2:hover, -.grammalecte_paragraph .mc:hover, -.grammalecte_paragraph .date:hover, -.grammalecte_paragraph .notype:hover { - background-color: hsl(180, 60%, 30%); - color: hsl(180, 10%, 96%); -} DELETED gc_lang/fr/webext/content_scripts/gc_content.js Index: gc_lang/fr/webext/content_scripts/gc_content.js ================================================================== --- gc_lang/fr/webext/content_scripts/gc_content.js +++ /dev/null @@ -1,458 +0,0 @@ -// JavaScript - -"use strict"; - -function onGrammalecteGCPanelClick (xEvent) { - try { - let xElem = xEvent.target; - if (xElem.id) { - if (xElem.id.startsWith("grammalecte_sugg")) { - oGrammalecte.oGCPanel.applySuggestion(xElem.id); - } else if (xElem.id === "grammalecte_tooltip_ignore") { - oGrammalecte.oGCPanel.ignoreError(xElem.id); - } else if (xElem.id.startsWith("grammalecte_check")) { - oGrammalecte.oGCPanel.recheckParagraph(parseInt(xElem.dataset.para_num)); - } else if (xElem.id.startsWith("grammalecte_hide")) { - xElem.parentNode.parentNode.style.display = "none"; - } else if (xElem.tagName === "U" && xElem.id.startsWith("grammalecte_err") - && xElem.className !== "corrected" && xElem.className !== "ignored") { - oGrammalecte.oGCPanel.oTooltip.show(xElem.id); - } else if (xElem.id === "grammalecte_tooltip_url") { - oGrammalecte.oGCPanel.openURL(xElem.dataset.url); - } else { - oGrammalecte.oGCPanel.oTooltip.hide(); - } - } else { - oGrammalecte.oGCPanel.oTooltip.hide(); - } - } - catch (e) { - showError(e); - } -} - - -class GrammalecteGrammarChecker extends GrammalectePanel { - /* - KEYS for identifiers: - grammalecte_paragraph{Id} : [paragraph number] - grammalecte_check{Id} : [paragraph number] - grammalecte_hide{Id} : [paragraph number] - grammalecte_error{Id} : [paragraph number]-[error_number] - grammalecte_sugg{Id} : [paragraph number]-[error_number]--[suggestion_number] - */ - - constructor (...args) { - super(...args); - this.aIgnoredErrors = new Set(); - this.xContentNode = createNode("div", {id: "grammalecte_gc_panel_content"}); - this.xParagraphList = createNode("div", {id: "grammalecte_paragraph_list"}); - this.xContentNode.appendChild(this.xParagraphList); - this.xPanelContent.addEventListener("click", onGrammalecteGCPanelClick, false); - this.oTooltip = new GrammalecteTooltip(this.xContentNode); - this.xPanelContent.appendChild(this.xContentNode); - this.oTAC = new GrammalecteTextAreaControl(); - } - - start (xTextArea=null) { - this.clear(); - if (xTextArea) { - this.oTAC.setTextArea(xTextArea); - } - } - - clear () { - while (this.xParagraphList.firstChild) { - this.xParagraphList.removeChild(this.xParagraphList.firstChild); - } - this.aIgnoredErrors.clear(); - } - - hide () { - this.xPanelNode.style.display = "none"; - this.oTAC.clear(); - } - - addParagraphResult (oResult) { - try { - if (oResult && oResult.sParagraph.trim() !== "" && (oResult.aGrammErr.length > 0 || oResult.aSpellErr.length > 0)) { - let xNodeDiv = createNode("div", {className: "grammalecte_paragraph_block"}); - // actions - let xActionsBar = createNode("div", {className: "grammalecte_paragraph_actions"}); - xActionsBar.appendChild(createNode("div", {id: "grammalecte_check" + oResult.iParaNum, className: "button green", textContent: "Réanalyser"}, {para_num: oResult.iParaNum})); - xActionsBar.appendChild(createNode("div", {id: "grammalecte_hide" + oResult.iParaNum, className: "button red bold", textContent: "×"})); - // paragraph - let xParagraph = createNode("p", {id: "grammalecte_paragraph"+oResult.iParaNum, lang: "fr", contentEditable: "true"}, {para_num: oResult.iParaNum}); - xParagraph.setAttribute("spellcheck", "false"); // doesn’t seem possible to use “spellcheck” as a common attribute. - xParagraph.className = (oResult.aGrammErr.length || oResult.aSpellErr.length) ? "grammalecte_paragraph softred" : "grammalecte_paragraph"; - xParagraph.addEventListener("keyup", function (xEvent) { - this.oTAC.setParagraph(parseInt(xEvent.target.dataset.para_num), this.purgeText(xEvent.target.textContent)); - this.oTAC.write(); - }.bind(this) - , true); - this._tagParagraph(xParagraph, oResult.sParagraph, oResult.iParaNum, oResult.aGrammErr, oResult.aSpellErr); - // creation - xNodeDiv.appendChild(xActionsBar); - xNodeDiv.appendChild(xParagraph); - this.xParagraphList.appendChild(xNodeDiv); - } - } - catch (e) { - showError(e); - } - } - - recheckParagraph (iParaNum) { - let sParagraphId = "grammalecte_paragraph" + iParaNum; - let xParagraph = document.getElementById(sParagraphId); - this.blockParagraph(xParagraph); - let sText = this.purgeText(xParagraph.textContent); - xPort.postMessage({ - sCommand: "parseAndSpellcheck1", - dParam: {sText: sText, sCountry: "FR", bDebug: false, bContext: false}, - dInfo: {sParagraphId: sParagraphId} - }); - this.oTAC.setParagraph(iParaNum, sText); - this.oTAC.write(); - } - - refreshParagraph (sParagraphId, oResult) { - try { - let xParagraph = document.getElementById(sParagraphId); - xParagraph.className = (oResult.aGrammErr.length || oResult.aSpellErr.length) ? "grammalecte_paragraph softred" : "grammalecte_paragraph"; - xParagraph.textContent = ""; - this._tagParagraph(xParagraph, oResult.sParagraph, sParagraphId.slice(21), oResult.aGrammErr, oResult.aSpellErr); - this.freeParagraph(xParagraph); - } - catch (e) { - showError(e); - } - } - - _tagParagraph (xParagraph, sParagraph, iParaNum, aSpellErr, aGrammErr) { - try { - if (aGrammErr.length === 0 && aSpellErr.length === 0) { - xParagraph.textContent = sParagraph; - return; - } - aGrammErr.push(...aSpellErr); - aGrammErr.sort(function (a, b) { - if (a["nStart"] < b["nStart"]) - return -1; - if (a["nStart"] > b["nStart"]) - return 1; - return 0; - }); - let nErr = 0; // we count errors to give them an identifier - let nEndLastErr = 0; - for (let oErr of aGrammErr) { - let nStart = oErr["nStart"]; - let nEnd = oErr["nEnd"]; - if (nStart >= nEndLastErr) { - oErr['sErrorId'] = iParaNum + "-" + nErr.toString(); // error identifier - oErr['sIgnoredKey'] = iParaNum + ":" + nStart.toString() + ":" + sParagraph.slice(nStart, nEnd); - if (nEndLastErr < nStart) { - xParagraph.appendChild(document.createTextNode(sParagraph.slice(nEndLastErr, nStart))); - } - xParagraph.appendChild(this._createError(sParagraph.slice(nStart, nEnd), oErr)); - xParagraph.insertAdjacentHTML("beforeend", ""); - nEndLastErr = nEnd; - } - nErr += 1; - } - if (nEndLastErr <= sParagraph.length) { - xParagraph.appendChild(document.createTextNode(sParagraph.slice(nEndLastErr))); - } - } - catch (e) { - showError(e); - } - } - - _createError (sUnderlined, oErr) { - let xNodeErr = document.createElement("u"); - xNodeErr.id = "grammalecte_err" + oErr['sErrorId']; - xNodeErr.textContent = sUnderlined; - xNodeErr.dataset.error_id = oErr['sErrorId']; - xNodeErr.dataset.ignored_key = oErr['sIgnoredKey']; - xNodeErr.dataset.error_type = (oErr['sType'] === "WORD") ? "spelling" : "grammar"; - if (xNodeErr.dataset.error_type === "grammar") { - xNodeErr.dataset.gc_message = oErr['sMessage']; - xNodeErr.dataset.gc_url = oErr['URL']; - if (xNodeErr.dataset.gc_message.includes(" #")) { - xNodeErr.dataset.line_id = oErr['sLineId']; - xNodeErr.dataset.rule_id = oErr['sRuleId']; - } - xNodeErr.dataset.suggestions = oErr["aSuggestions"].join("|"); - } - xNodeErr.className = (this.aIgnoredErrors.has(xNodeErr.dataset.ignored_key)) ? "ignored" : "error " + oErr['sType']; - return xNodeErr; - } - - blockParagraph (xParagraph) { - xParagraph.contentEditable = "false"; - document.getElementById("grammalecte_check"+xParagraph.dataset.para_num).textContent = "Analyse…"; - } - - freeParagraph (xParagraph) { - xParagraph.contentEditable = "true"; - document.getElementById("grammalecte_check"+xParagraph.dataset.para_num).textContent = "Réanalyser"; - } - - applySuggestion (sNodeSuggId) { // sugg - try { - let sErrorId = document.getElementById(sNodeSuggId).dataset.error_id; - //let sParaNum = sErrorId.slice(0, sErrorId.indexOf("-")); - let xNodeErr = document.getElementById("grammalecte_err" + sErrorId); - xNodeErr.textContent = document.getElementById(sNodeSuggId).textContent; - xNodeErr.className = "corrected"; - xNodeErr.removeAttribute("style"); - this.oTooltip.hide(); - this.recheckParagraph(parseInt(sErrorId.slice(0, sErrorId.indexOf("-")))); - } - catch (e) { - showError(e); - } - } - - ignoreError (sIgnoreButtonId) { // ignore - try { - let sErrorId = document.getElementById(sIgnoreButtonId).dataset.error_id; - let xNodeErr = document.getElementById("grammalecte_err" + sErrorId); - this.aIgnoredErrors.add(xNodeErr.dataset.ignored_key); - xNodeErr.className = "ignored"; - this.oTooltip.hide(); - } - catch (e) { - showError(e); - } - } - - purgeText (sText) { - return sText.replace(/ /g, " ").replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&"); - } - - addSummary () { - // todo - } - - addMessage (sMessage) { - let xNode = createNode("div", {className: "grammalecte_gc_panel_message", textContent: sMessage}); - this.xParagraphList.appendChild(xNode); - } - - _copyToClipboard (sText) { - // recipe from https://github.com/mdn/webextensions-examples/blob/master/context-menu-copy-link-with-types/clipboard-helper.js - function setClipboardData (xEvent) { - document.removeEventListener("copy", setClipboardData, true); - xEvent.stopImmediatePropagation(); - xEvent.preventDefault(); - xEvent.clipboardData.setData("text/plain", sText); - }; - - document.addEventListener("copy", setClipboardData, true); - document.execCommand("copy"); - } - - copyTextToClipboard () { - this.startWaitIcon(); - try { - let xClipboardButton = document.getElementById("grammalecte_clipboard_button"); - xClipboardButton.textContent = "->>"; - let sText = ""; - for (let xNode of document.getElementsByClassName("grammalecte_paragraph")) { - sText += xNode.textContent + "\n"; - } - this._copyToClipboard(sText); - xClipboardButton.textContent = "OK"; - window.setTimeout(function() { xClipboardButton.textContent = "∑"; } , 2000); - } - catch (e) { - showError(e); - } - this.stopWaitIcon(); - } -} - - -class GrammalecteTooltip { - - constructor (xContentNode) { - this.xTooltip = createNode("div", {id: "grammalecte_tooltip"}); - this.xTooltipArrow = createNode("img", { - id: "grammalecte_tooltip_arrow", - src: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAECAYAAACzzX7wAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAOwQAADsEBuJFr7QAAABl0RVh0U29mdHdhcmUAcGFpbnQubmV0IDQuMC4xNkRpr/UAAAAlSURBVBhXY/j//z8cq/kW/wdhZDEMSXRFWCVhGKwAmwQCF/8HAGUkScGH4cM8AAAAAElFTkSuQmCC", - alt: "^" - }); - this.xTooltipSuggBlock = createNode("div", {id: "grammalecte_tooltip_sugg_block"}); - let xMessageBlock = createNode("div", {id: "grammalecte_tooltip_message_block"}); - xMessageBlock.appendChild(createNode("p", {id: "grammalecte_tooltip_rule_id"})); - xMessageBlock.appendChild(createNode("p", {id: "grammalecte_tooltip_message", textContent: "Erreur."})); - let xActions = xMessageBlock.appendChild(createNode("div", {id: "grammalecte_tooltip_actions"})); - xActions.appendChild(createNode("div", {id: "grammalecte_tooltip_ignore", textContent: "Ignorer"})); - xActions.appendChild(createNode("div", {id: "grammalecte_tooltip_url", textContent: "Voulez-vous en savoir plus ?…"}, {url: ""})); - xMessageBlock.appendChild(xActions); - this.xTooltip.appendChild(xMessageBlock); - this.xTooltip.appendChild(createNode("div", {id: "grammalecte_tooltip_sugg_title", textContent: "SUGGESTIONS :"})); - this.xTooltip.appendChild(this.xTooltipSuggBlock); - xContentNode.appendChild(this.xTooltip); - xContentNode.appendChild(this.xTooltipArrow); - } - - show (sNodeErrorId) { // err - try { - let xNodeErr = document.getElementById(sNodeErrorId); - let nLimit = 500 - 330; // paragraph width - tooltip width - this.xTooltipArrow.style.top = (xNodeErr.offsetTop + 16) + "px"; - this.xTooltipArrow.style.left = (xNodeErr.offsetLeft + Math.floor((xNodeErr.offsetWidth / 2))-4) + "px"; // 4 is half the width of the arrow. - this.xTooltip.style.top = (xNodeErr.offsetTop + 20) + "px"; - this.xTooltip.style.left = (xNodeErr.offsetLeft > nLimit) ? nLimit + "px" : xNodeErr.offsetLeft + "px"; - if (xNodeErr.dataset.error_type === "grammar") { - // grammar error - if (xNodeErr.dataset.gc_message.includes(" ##")) { - let n = xNodeErr.dataset.gc_message.indexOf(" ##"); - document.getElementById("grammalecte_tooltip_message").textContent = xNodeErr.dataset.gc_message.slice(0, n); - document.getElementById("grammalecte_tooltip_rule_id").textContent = "Règle : " + xNodeErr.dataset.gc_message.slice(n+2); - document.getElementById("grammalecte_tooltip_rule_id").style.display = "block"; - } else { - document.getElementById("grammalecte_tooltip_message").textContent = xNodeErr.dataset.gc_message; - document.getElementById("grammalecte_tooltip_rule_id").style.display = "none"; - } - if (xNodeErr.dataset.gc_url != "") { - document.getElementById("grammalecte_tooltip_url").dataset.url = xNodeErr.dataset.gc_url; - document.getElementById("grammalecte_tooltip_url").style.display = "inline"; - } else { - document.getElementById("grammalecte_tooltip_url").dataset.url = ""; - document.getElementById("grammalecte_tooltip_url").style.display = "none"; - } - document.getElementById("grammalecte_tooltip_ignore").dataset.error_id = xNodeErr.dataset.error_id; - let iSugg = 0; - let xGCSugg = document.getElementById("grammalecte_tooltip_sugg_block"); - xGCSugg.textContent = ""; - if (xNodeErr.dataset.suggestions.length > 0) { - for (let sSugg of xNodeErr.dataset.suggestions.split("|")) { - xGCSugg.appendChild(this._createSuggestion(xNodeErr.dataset.error_id, iSugg, sSugg)); - xGCSugg.appendChild(document.createTextNode(" ")); - iSugg += 1; - } - } else { - xGCSugg.textContent = "Aucune."; - } - } - this.xTooltipArrow.style.display = "block"; - this.xTooltip.style.display = "block"; - if (xNodeErr.dataset.error_type === "spelling") { - // spelling mistake - document.getElementById("grammalecte_tooltip_message").textContent = "Mot inconnu du dictionnaire."; - document.getElementById("grammalecte_tooltip_ignore").dataset.error_id = xNodeErr.dataset.error_id; - while (this.xTooltipSuggBlock.firstChild) { - this.xTooltipSuggBlock.removeChild(this.xTooltipSuggBlock.firstChild); - } - //console.log("getSuggFor: " + xNodeErr.textContent.trim() + " // error_id: " + xNodeErr.dataset.error_id); - //self.port.emit("getSuggestionsForTo", xNodeErr.textContent.trim(), xNodeErr.dataset.error_id); - this.setSpellSuggestionsFor(xNodeErr.textContent.trim(), "", xNodeErr.dataset.error_id); - } - } - catch (e) { - showError(e); - } - } - - setTooltipColor () { - // todo - } - - hide () { - this.xTooltipArrow.style.display = "none"; - this.xTooltip.style.display = "none"; - } - - _createSuggestion (sErrId, iSugg, sSugg) { - let xNodeSugg = document.createElement("a"); - xNodeSugg.id = "grammalecte_sugg" + sErrId + "--" + iSugg.toString(); - xNodeSugg.className = "sugg"; - xNodeSugg.dataset.error_id = sErrId; - xNodeSugg.textContent = sSugg; - return xNodeSugg; - } - - setSpellSuggestionsFor (sWord, sSuggestions, sErrId) { - // spell checking suggestions - try { - // console.log("setSuggestionsFor: " + sWord + " > " + sSuggestions + " // " + sErrId); - let xSuggBlock = document.getElementById("grammalecte_tooltip_sugg_block"); - xSuggBlock.textContent = ""; - if (sSuggestions === "") { - xSuggBlock.appendChild(document.createTextNode("Aucune.")); - } else if (sSuggestions.startsWith("#")) { - xSuggBlock.appendChild(document.createTextNode(sSuggestions)); - } else { - let lSugg = sSuggestions.split("|"); - let iSugg = 0; - for (let sSugg of lSugg) { - xSuggBlock.appendChild(this._createSuggestion(sErrId, iSugg, sSugg)); - xSuggBlock.appendChild(document.createTextNode(" ")); - iSugg += 1; - } - } - } - catch (e) { - showError(e); - } - } -} - - -class GrammalecteTextAreaControl { - - constructor () { - this._xTextArea = null; - this._dParagraph = new Map(); - } - - setTextArea (xNode) { - this.clear(); - this._xTextArea = xNode; - this._xTextArea.disabled = true; - this._loadText(); - } - - clear () { - if (this._xTextArea !== null) { - this._xTextArea.disabled = false; - this._xTextArea = null; - } - this._dParagraph.clear(); - } - - setParagraph (iParagraph, sText) { - if (this._xTextArea !== null) { - this._dParagraph.set(iParagraph, sText); - } - } - - _loadText () { - let sText = this._xTextArea.value; - let i = 0; - let iStart = 0; - let iEnd = 0; - sText = sText.replace("\r\n", "\n").replace("\r", "\n"); - while ((iEnd = sText.indexOf("\n", iStart)) !== -1) { - 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)); - } - - write () { - if (this._xTextArea !== null) { - let sText = ""; - this._dParagraph.forEach(function (val, key) { - sText += val + "\n"; - }); - this._xTextArea.value = sText.slice(0,-1); - } - } -} DELETED gc_lang/fr/webext/content_scripts/lxg_content.css Index: gc_lang/fr/webext/content_scripts/lxg_content.css ================================================================== --- gc_lang/fr/webext/content_scripts/lxg_content.css +++ /dev/null @@ -1,83 +0,0 @@ -/* - Lexicographer -*/ -#grammalecte_lxg_panel_content { - padding: 5px; - font-size: 13px; -} - -.grammalecte_lxg_list_of_tokens { - margin: 5px 0 10px 0; - padding: 10px; - background-color: hsla(0, 0%, 96%, 1); - border-radius: 2px; -} -.grammalecte_lxg_list_of_tokens .num { - float: right; - margin: -12px 0 5px 10px; - padding: 5px 10px; - font-weight: bold; - border-radius: 0 0 4px 4px; - background-color: hsl(0, 50%, 50%); - color: hsl(0, 10%, 96%); -} -.grammalecte_token { - padding: 4px 0; -} -.grammalecte_token .separator { - margin: 20px 0; - padding: 5px 5px; - background-color: hsla(0, 0%, 75%, 1); - color: hsla(0, 0%, 96%, 1); - border-radius: 5px; - text-align: center; - font-size: 20px; -} -.grammalecte_token ul { - margin: 0 0 5px 5px; -} -.grammalecte_token b { - background-color: hsla(150, 10%, 50%, 1); - color: hsla(0, 0%, 96%, 1); - padding: 2px 5px; - border-radius: 2px; - text-decoration: none; -} -.grammalecte_token b.WORD { - background-color: hsla(150, 50%, 50%, 1); -} -.grammalecte_token b.ELPFX { - background-color: hsla(150, 30%, 50%, 1); -} -.grammalecte_token b.UNKNOWN { - background-color: hsla(0, 50%, 50%, 1); -} -.grammalecte_token b.NUM { - background-color: hsla(180, 50%, 50%, 1); -} -.grammalecte_token b.COMPLEX { - background-color: hsla(60, 50%, 50%, 1); -} -.grammalecte_token b.SEPARATOR { - background-color: hsla(210, 50%, 50%, 1); -} -.grammalecte_token b.LINK { - background-color: hsla(270, 50%, 50%, 1); -} -.grammalecte_token s { - color: hsla(0, 0%, 60%, 1); - text-decoration: none; -} -.grammalecte_token .textline { - text-decoration: bold; -} - -.grammalecte_token p.message { - margin-top: 20px; - padding: 10px 10px; - background-color: hsla(240, 10%, 50%, 1); - font-size: 18px; - color: hsla(240, 0%, 96%, 1); - border-radius: 3px; - text-align: center; -} DELETED gc_lang/fr/webext/content_scripts/lxg_content.js Index: gc_lang/fr/webext/content_scripts/lxg_content.js ================================================================== --- gc_lang/fr/webext/content_scripts/lxg_content.js +++ /dev/null @@ -1,69 +0,0 @@ -// JavaScript - -"use strict"; - -class GrammalecteLexicographer extends GrammalectePanel { - - constructor (...args) { - super(...args); - this._nCount = 0; - this._xContentNode = createNode("div", {id: "grammalecte_lxg_panel_content"}); - this.xPanelContent.appendChild(this._xContentNode); - } - - clear () { - this._nCount = 0; - while (this._xContentNode.firstChild) { - this._xContentNode.removeChild(this._xContentNode.firstChild); - } - } - - addSeparator (sText) { - if (this._xContentNode.textContent !== "") { - this._xContentNode.appendChild(createNode("div", {className: "grammalecte_lxg_separator", textContent: sText})); - } - } - - addMessage (sClass, sText) { - this._xContentNode.appendChild(createNode("div", {className: sClass, textContent: sText})); - } - - addListOfTokens (lTokens) { - try { - if (lTokens) { - this._nCount += 1; - let xNodeDiv = createNode("div", {className: "grammalecte_lxg_list_of_tokens"}); - xNodeDiv.appendChild(createNode("div", {className: "num", textContent: this._nCount})); - for (let oToken of lTokens) { - xNodeDiv.appendChild(this._createTokenNode(oToken)); - } - this._xContentNode.appendChild(xNodeDiv); - } - } - catch (e) { - showError(e); - } - } - - _createTokenNode (oToken) { - let xTokenNode = createNode("div", {className: "grammalecte_token"}); - xTokenNode.appendChild(createNode("b", {className: oToken.sType, textContent: oToken.sValue})); - xTokenNode.appendChild(createNode("s", {textContent: " : "})); - if (oToken.aLabel.length === 1) { - xTokenNode.appendChild(document.createTextNode(oToken.aLabel[0])); - } else { - let xTokenList = document.createElement("ul"); - for (let sLabel of oToken.aLabel) { - xTokenList.appendChild(createNode("li", {textContent: sLabel})); - } - xTokenNode.appendChild(xTokenList); - } - return xTokenNode; - } - - setHidden (sClass, bHidden) { - for (let xNode of document.getElementsByClassName(sClass)) { - xNode.hidden = bHidden; - } - } -} ADDED gc_lang/fr/webext/content_scripts/panel.css Index: gc_lang/fr/webext/content_scripts/panel.css ================================================================== --- /dev/null +++ gc_lang/fr/webext/content_scripts/panel.css @@ -0,0 +1,121 @@ +/* + CSS + Content panels for Grammalecte +*/ + +.grammalecte_panel { + padding: 0; + margin: 0; + position: fixed; + z-index: 100; + border: 2px solid hsl(210, 0%, 50%); + border-radius: 10px 10px 10px 10px; + background-color: hsl(210, 20%, 100%); + color: hsl(210, 10%, 4%); + font-family: "Trebuchet MS", "Liberation Sans", sans-serif; + box-shadow: 0 0 4px 2px hsl(210, 0%, 50%); +} + +.grammalecte_panel_bar { + position: sticky; + width: 100%; + background-color: hsl(210, 0%, 90%); + border-radius: 10px 10px 0 0; + border-bottom: 1px solid hsl(210, 10%, 80%); + font-size: 20px; +} +.grammalecte_panel_title { + padding: 10px 20px; +} +.grammalecte_panel_label { + display: inline-block; + padding: 0 10px; +} + +.grammalecte_panel_commands { + float: right; +} +.grammalecte_copy_button { + display: inline-block; + padding: 2px 10px; + background-color: hsl(150, 80%, 30%); + border-radius: 0 0 0 3px; + font-size: 22px; + font-weight: bold; + color: hsl(150, 0%, 100%); + text-align: center; + cursor: pointer; +} +.grammalecte_copy_button:hover { + background-color: hsl(150, 100%, 40%); +} +.grammalecte_move_button { + display: inline-block; + padding: 2px 5px; + background-color: hsl(180, 80%, 50%); + font-size: 22px; + font-weight: bold; + color: hsl(180, 0%, 100%); + text-align: center; + cursor: pointer; +} +.grammalecte_move_button:hover { + background-color: hsl(180, 100%, 60%); +} +.grammalecte_close_button { + display: inline-block; + padding: 2px 10px; + border-radius: 0 8px 0 0; + background-color: hsl(0, 80%, 50%); + font-size: 22px; + font-weight: bold; + color: hsl(210, 0%, 100%); + text-align: center; + cursor: pointer; +} +.grammalecte_close_button:hover { + background-color: hsl(0, 100%, 60%); +} + +.grammalecte_panel_content { + height: calc(100% - 55px); /* panel height - title_bar */ + overflow: auto; +} + + +/* + CSS Spinner + Double bounce + http://tobiasahlin.com/spinkit/ +*/ +.grammalecte_spinner { + visibility: hidden; + width: 40px; + height: 40px; + position: absolute; + top: 2px; + right: 180px; +} +.grammalecte_spinner .bounce1, +.grammalecte_spinner .bounce2 { + width: 100%; + height: 100%; + border-radius: 50%; + background-color: hsl(0, 50%, 75%); + opacity: 0.6; + position: absolute; + top: 0; + left: 0; + animation: grammalecte-sk-bounce 2.0s infinite ease-in-out; +} +.grammalecte_spinner .bounce2 { + animation-delay: -1.0s; +} + +@keyframes grammalecte-sk-bounce { + 0%, 100% { + transform: scale(0.0); + } 50% { + transform: scale(1.0); + } +} ADDED gc_lang/fr/webext/content_scripts/panel.js Index: gc_lang/fr/webext/content_scripts/panel.js ================================================================== --- /dev/null +++ gc_lang/fr/webext/content_scripts/panel.js @@ -0,0 +1,147 @@ +// JavaScript +// Panel creator + +"use strict"; + + +class GrammalectePanel { + + constructor (sId, sTitle, nWidth, nHeight, bFlexible=true) { + this.sId = sId; + this.nWidth = nWidth; + this.nHeight = nHeight; + this.bFlexible = bFlexible; + this.xPanelContent = createNode("div", {className: "grammalecte_panel_content"}); + this.xWaitIcon = this._createWaitIcon(); + this.xPanelNode = this._createPanel(sTitle); + this.center(); + } + + _createPanel (sTitle) { + try { + let xPanel = createNode("div", {id: this.sId, className: "grammalecte_panel"}); + let xBar = createNode("div", {className: "grammalecte_panel_bar"}); + xBar.appendChild(this._createButtons()); + let xTitle = createNode("div", {className: "grammalecte_panel_title"}); + xTitle.appendChild(this._createLogo()); + xTitle.appendChild(createNode("div", {className: "grammalecte_panel_label", textContent: sTitle})); + xBar.appendChild(xTitle); + xPanel.appendChild(xBar); + xPanel.appendChild(this.xPanelContent); + return xPanel; + } + catch (e) { + showError(e); + } + } + + _createLogo () { + let xImg = document.createElement("img"); + xImg.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAC8UlEQVQ4jX3TbUgTcRwH8P89ddu5u9tt082aZmpFEU4tFz0QGTUwCi0heniR9MSUIKRaD0RvIlKigsooo+iNFa0XJYuwIjEK19OcDtPElsG0ktyp591t7u7+vUh7MPX3+vf5/n8/+P0BmKJIPUUVlh2rdVVeesWlzEybqg+bFOsoylnqPmNavGFfknV2Omu2Lvja3vxAURKJib3opHizu8riLK6gjRyuKgmoSoMRFENRUqfXTzvBGK62LC2uoFkOl4RhjQ8+qWt7dPNE3sbdp+2LXbsGe9qb4rIo/BfwFy6nWQ4ThWGNDzbcfu29dMDh2nHU7CypYNLmzTda0/L5cNuzmDQi/A4Y27k6eQxLI79wS/11D0AAMNvs6XT6ojVJjJEgTbMy2BT77xBMp09KcpaWV1uc41jQoi0NdUHfjeOO9WWn7AVF7s7n986SithPJGeupBh2PCSP/xxqxAp3eq6wuUV7Wc6MSZIEhA8vHjbfOe/OcW3zmAuKy+nUzAyD2bow8ODaEROFq8AyZ5WBYdEZXGqGxZ61HJV+9HYCJRbTNA0QBA40HWunaKN5dKg/DBKxeCIe09Th/m4MJwiMSZmLEzMQAABQRuNqgu8NYX3doTcMpvCkLbtQZ2AJkrPOZG1zlnY13T+Hy9EehY90h57eqcorcZ/lctZuMzAsOjLEqwNv66/6vZcPYRBC+C3cGaBxhSet2av1BpYgTTY7k5y2JPT41slIR6Axv8R9nnOs+4Pf+2r992uOxGVJwgAAAEINfgt3BGgsESWtWas1iGDyl+CT/u7WpvxNFRc4x7qtBoZFhSFejb7z1fq9NYfjsiT+cwcQavBruCOgU4SIGo18amuoq3Js3FNlynVtH385+s53ze+t8cRkURx3yMTTRBAEQVAUXbFlf3XystJKA2NExeFBdWASDAAA+MQACCEEmqbJ0b6PMC7JwhDU8YFHV5u9NZ64LErT/oW/63tPV6uJwmKoOND78u7Fg5NhAAD4CVbzY9cwrWQrAAAAAElFTkSuQmCC"; + return xImg; + } + + _createButtons () { + let xButtonLine = createNode("div", {className: "grammalecte_panel_commands"}); + xButtonLine.appendChild(this.xWaitIcon); + if (this.sId === "grammalecte_gc_panel") { + xButtonLine.appendChild(this._createCopyButton()); + } + xButtonLine.appendChild(this._createMoveButton("stickToTop", "¯", "Coller en haut")); + xButtonLine.appendChild(this._createMoveButton("stickToLeft", "«", "Coller à gauche")); + xButtonLine.appendChild(this._createMoveButton("center", "•", "Centrer")); + xButtonLine.appendChild(this._createMoveButton("stickToRight", "»", "Coller à droite")); + xButtonLine.appendChild(this._createMoveButton("stickToBottom", "_", "Coller en bas")); + xButtonLine.appendChild(this._createCloseButton()); + return xButtonLine; + } + + _createWaitIcon () { + let xWaitIcon = createNode("div", {className: "grammalecte_spinner"}); + xWaitIcon.appendChild(createNode("div", {className: "bounce1"})); + xWaitIcon.appendChild(createNode("div", {className: "bounce2"})); + return xWaitIcon; + } + + _createCopyButton () { + let xButton = createNode("div", {id: "grammalecte_clipboard_button", className: "grammalecte_copy_button", textContent: "∑", title: "Copier dans le presse-papiers"}); + xButton.onclick = function () { this.copyTextToClipboard(); }.bind(this); + return xButton; + } + + _createMoveButton (sAction, sLabel, sTitle) { + let xButton = createNode("div", {className: "grammalecte_move_button", textContent: sLabel, title: sTitle}); + xButton.onclick = function () { this[sAction](); }.bind(this); + return xButton; + } + + _createCloseButton () { + let xButton = createNode("div", {className: "grammalecte_close_button", textContent: "×", title: "Fermer la fenêtre"}); + xButton.onclick = function () { this.hide(); }.bind(this); // better than writing “let that = this;” before the function? + return xButton; + } + + insertIntoPage () { + document.body.appendChild(this.xPanelNode); + } + + show () { + this.xPanelNode.style.display = "block"; + } + + hide () { + this.xPanelNode.style.display = "none"; + } + + center () { + let nHeight = (this.bFlexible) ? window.innerHeight-100 : this.nHeight; + this.xPanelNode.style = `top: 50%; left: 50%; width: ${this.nWidth}px; height: ${nHeight}px; margin-top: -${nHeight/2}px; margin-left: -${this.nWidth/2}px;`; + } + + stickToLeft () { + let nHeight = (this.bFlexible) ? window.innerHeight-100 : this.nHeight; + this.xPanelNode.style = `top: 50%; left: -2px; width: ${this.nWidth}px; height: ${nHeight}px; margin-top: -${nHeight/2}px;`; + } + + stickToRight () { + let nHeight = (this.bFlexible) ? window.innerHeight-100 : this.nHeight; + this.xPanelNode.style = `top: 50%; right: -2px; width: ${this.nWidth}px; height: ${nHeight}px; margin-top: -${nHeight/2}px;`; + } + + stickToTop () { + let nWidth = (this.bFlexible) ? Math.floor(window.innerWidth/2) : this.nWidth; + let nHeight = (this.bFlexible) ? Math.floor(window.innerHeight*0.45) : this.nHeight; + this.xPanelNode.style = `top: -2px; left: 50%; width: ${nWidth}px; height: ${nHeight}px; margin-left: -${nWidth/2}px;`; + } + + stickToBottom () { + let nWidth = (this.bFlexible) ? Math.floor(window.innerWidth/2) : this.nWidth; + let nHeight = (this.bFlexible) ? Math.floor(window.innerHeight*0.45) : this.nHeight; + this.xPanelNode.style = `bottom: -2px; left: 50%; width: ${nWidth}px; height: ${nHeight}px; margin-left: -${nWidth/2}px;`; + } + + reduce () { + // todo + } + + logInnerHTML () { + // for debugging + console.log(this.xPanelNode.innerHTML); + } + + startWaitIcon () { + this.xWaitIcon.style.visibility = "visible"; + } + + stopWaitIcon () { + this.xWaitIcon.style.visibility = "hidden"; + } + + openURL (sURL) { + xPort.postMessage({ + sCommand: "openURL", + dParam: {"sURL": sURL}, + dInfo: {} + }); + } +} ADDED gc_lang/fr/webext/content_scripts/panel_gc.css Index: gc_lang/fr/webext/content_scripts/panel_gc.css ================================================================== --- /dev/null +++ gc_lang/fr/webext/content_scripts/panel_gc.css @@ -0,0 +1,366 @@ +/* + Grammar checker +*/ +#grammalecte_gc_panel_content { + margin: 0; + padding: 5px; +} + +.grammalecte_paragraph_block { + margin: 0 0 5px 0; +} + +.grammalecte_paragraph { + margin: 0; + padding: 10px; + background-color: hsl(0, 0%, 96%); + border-radius: 2px; + font-size: 14px; + font-family : "Courier New", Courier, "Lucida Sans Typewriter", "Lucida Typewriter", monospace; + color: hsl(0, 0%, 0%); +} + +.grammalecte_paragraph a { + background-color: hsla(210, 50%, 50%, 1); + padding: 1px 5px; + border-radius: 2px; + color: hsla(210, 0%, 96%, 1); + cursor: pointer; + text-decoration: none; +} +.grammalecte_paragraph a:hover { + background-color: hsla(210, 60%, 40%, 1); + color: hsla(0, 0%, 100%, 1); + text-shadow: 0 0 3px hsl(210, 30%, 60%); +} + +.grammalecte_paragraph u { + text-decoration: none; +} + +.grammalecte_paragraph u.corrected, +.grammalecte_paragraph u.ignored { + background-color: hsla(120, 50%, 70%, 1); + color: hsla(0, 0%, 4%, 1); + border-radius: 2px; + text-decoration: none; +} +.grammalecte_paragraph u.ignored { + background-color: hsla(30, 20%, 80%, 1); +} + +.grammalecte_paragraph u.error { + position: relative; + cursor: pointer; + border-radius: 2px; + text-decoration: none; /* to remove for wavy underlines */ +} +.grammalecte_paragraph u.error:hover { + cursor: pointer; +} + + +/* + Action buttons +*/ + +.grammalecte_paragraph_actions { + float: right; + margin: 0 0 5px 10px; +} + +.grammalecte_paragraph_actions .button { + display: inline-block; + background-color: hsl(0, 0%, 50%); + text-align: center; + margin-left: 2px; + padding: 1px 4px 3px 4px; + cursor: pointer; + font-size: 14px; + color: hsl(0, 0%, 96%); + border-radius: 2px; +} +.grammalecte_paragraph_actions .button:hover { + background-color: hsl(0, 0%, 40%); + color: hsl(0, 0%, 100%); +} + +.grammalecte_paragraph_actions .green { + background-color: hsl(120, 30%, 50%); + color: hsl(0, 0%, 96%); +} +.grammalecte_paragraph_actions .green:hover { + background-color: hsl(120, 50%, 40%); + color: hsl(0, 0%, 100%); +} +.grammalecte_paragraph_actions .red { + background-color: hsl(0, 30%, 50%); + color: hsl(0, 0%, 96%); +} +.grammalecte_paragraph_actions .red:hover { + background-color: hsl(0, 50%, 40%); + color: hsl(0, 0%, 100%); +} +.grammalecte_paragraph_actions .orange { + background-color: hsl(30, 50%, 50%); + color: hsl(30, 0%, 96%); +} +.grammalecte_paragraph_actions .orange:hover { + background-color: hsl(30, 70%, 40%); + color: hsl(30, 0%, 100%); +} +.grammalecte_paragraph_actions .bold { + font-weight: bold; +} + + + +/* + TOOLTIP +*/ +#grammalecte_tooltip_arrow { + position: absolute; + display: none; +} + +#grammalecte_tooltip { + position: absolute; + margin: 0; + display: none; + width: 300px; + border-radius: 5px; + box-shadow: 0 0 6px hsla(0, 0%, 0%, 0.3); + font-family: Tahoma, "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", sans-serif; + font-size: 12px; + line-height: 18px; + cursor: default; + text-decoration: none; + border: 3px solid hsl(210, 50%, 30%); + color: hsla(210, 10%, 20%, 1); + z-index: 1000; +} + +#grammalecte_tooltip_message_block { + margin: 0; + padding: 5px 10px 10px 10px; + background-color: hsl(210, 50%, 30%); + color: hsl(210, 50%, 96%); +} +#grammalecte_tooltip_rule_id { + display: none; + margin: 0 0 5px 0; + border: 1px solid hsl(210, 50%, 60%); + background-color: hsl(210, 50%, 40%); + padding: 2px 5px; + border-radius: 2px; + color: hsla(210, 0%, 96%, 1); + font-size: 11px; + font-style: normal; + text-align: center; +} +#grammalecte_tooltip_message { + font-size: 15px; + margin: 0 0 5px 0; +} +#grammalecte_tooltip_ignore { + display: inline-block; + padding: 2px 5px; + background-color: hsla(30, 30%, 40%, 1); + color: hsla(30, 0%, 96%, 1); + border-radius: 2px; + cursor: pointer; + text-decoration: none; +} +#grammalecte_tooltip_ignore:hover { + background-color: hsla(30, 30%, 50%, 1); + color: hsla(0, 0%, 100%, 1); + text-shadow: 0 0 3px hsl(30, 30%, 60%); +} +#grammalecte_tooltip_url { + display: inline-block; + margin: 0 0 0 10px; + padding: 2px 5px; + background-color: hsla(210, 50%, 50%, 1); + color: hsla(210, 0%, 96%, 1); + border-radius: 2px; + cursor: pointer; + text-decoration: none; +} +#grammalecte_tooltip_url:hover { + background-color: hsla(210, 50%, 60%, 1); + color: hsla(0, 0%, 100%, 1); + text-shadow: 0 0 3px hsl(210, 30%, 60%); +} +#grammalecte_tooltip_sugg_title { + padding: 0 10px; + background-color: hsl(210, 10%, 90%); + color: hsl(210, 50%, 30%); + font-size: 10px; + font-weight: bold; +} +#grammalecte_tooltip_sugg_block { + padding: 10px; + background-color: hsl(210, 10%, 96%); + border-radius: 0 0 2px 2px; + line-height: 20px; +} +#grammalecte_tooltip_sugg_block a.sugg { + padding: 1px 6px; + background-color: hsla(180, 60%, 40%, 1); + color: hsla(180, 0%, 96%, 1); + border-radius: 2px; + cursor: pointer; + text-decoration: none; +} +#grammalecte_tooltip_sugg_block a.sugg:hover { + background-color: hsla(180, 70%, 45%, 1); + color: hsla(0, 0%, 100%, 1); +} + + +/* + ERRORS +*/ + +.grammalecte_paragraph .error { + /* default color */ + background-color: hsl(240, 10%, 50%); + color: hsl(240, 0%, 96%); +} +.grammalecte_paragraph .error:hover { + background-color: hsl(240, 10%, 40%); + color: hsl(240, 0%, 100%); +} + +/* elems */ +.grammalecte_paragraph .WORD { + background-color: hsl(0, 50%, 50%); + color: hsl(0, 0%, 96%); + /*text-decoration: underline wavy hsl(0, 50%, 50%);*/ +} +.grammalecte_paragraph .WORD:hover { + background-color: hsl(0, 60%, 40%); + color: hsl(0, 0%, 100%); +} + +/* elems */ +.grammalecte_paragraph .typo, +.grammalecte_paragraph .esp, +.grammalecte_paragraph .nbsp, +.grammalecte_paragraph .eif, +.grammalecte_paragraph .maj, +.grammalecte_paragraph .virg, +.grammalecte_paragraph .tu, +.grammalecte_paragraph .num, +.grammalecte_paragraph .unit, +.grammalecte_paragraph .nf, +.grammalecte_paragraph .liga, +.grammalecte_paragraph .mapos, +.grammalecte_paragraph .chim { + background-color: hsl(30, 70%, 50%); + color: hsl(30, 10%, 96%); + /*text-decoration: underline wavy hsl(30, 70%, 50%);*/ +} + +.grammalecte_paragraph .typo:hover, +.grammalecte_paragraph .esp:hover, +.grammalecte_paragraph .nbsp:hover, +.grammalecte_paragraph .eif:hover, +.grammalecte_paragraph .maj:hover, +.grammalecte_paragraph .virg:hover, +.grammalecte_paragraph .tu:hover, +.grammalecte_paragraph .num:hover, +.grammalecte_paragraph .unit:hover, +.grammalecte_paragraph .nf:hover, +.grammalecte_paragraph .liga:hover, +.grammalecte_paragraph .mapos:hover, +.grammalecte_paragraph .chim:hover { + background-color: hsl(30, 80%, 45%); + color: hsl(30, 10%, 96%); +} + +/* elems */ +.grammalecte_paragraph .apos { + background-color: hsl(40, 90%, 50%); + color: hsl(40, 10%, 96%); + /*text-decoration: underline wavy hsl(40, 70%, 45%);*/ +} +.grammalecte_paragraph .apos:hover { + background-color: hsl(40, 100%, 45%); + color: hsl(40, 10%, 96%); +} + +/* elems */ +.grammalecte_paragraph .gn, +.grammalecte_paragraph .sgpl { + background-color: hsl(210, 50%, 50%); + color: hsl(210, 10%, 96%); + /*text-decoration: underline wavy hsl(210, 50%, 50%);*/ +} +.grammalecte_paragraph .gn:hover, +.grammalecte_paragraph .sgpl:hover { + background-color: hsl(210, 60%, 40%); + color: hsl(210, 10%, 96%); +} + +/* elems */ +.grammalecte_paragraph .conj, +.grammalecte_paragraph .infi, +.grammalecte_paragraph .imp, +.grammalecte_paragraph .inte, +.grammalecte_paragraph .ppas, +.grammalecte_paragraph .vmode { + background-color: hsl(300, 30%, 40%); + color: hsl(300, 10%, 96%); + /*text-decoration: underline wavy hsl(300, 40%, 40%);*/ +} + +.grammalecte_paragraph .conj:hover, +.grammalecte_paragraph .infi:hover, +.grammalecte_paragraph .imp:hover, +.grammalecte_paragraph .inte:hover, +.grammalecte_paragraph .ppas:hover, +.grammalecte_paragraph .vmode:hover { + background-color: hsl(300, 40%, 30%); + color: hsl(300, 10%, 96%); +} + +/* elems */ +.grammalecte_paragraph .conf, +.grammalecte_paragraph .ocr { + background-color: hsl(270, 40%, 30%); + color: hsl(270, 10%, 96%); + /*text-decoration: underline wavy hsl(270, 40%, 30%);*/ +} + +.grammalecte_paragraph .conf:hover, +.grammalecte_paragraph .ocr:hover { + background-color: hsl(270, 50%, 20%); + color: hsl(270, 10%, 96%); +} + +/* elems */ +.grammalecte_paragraph .bs, +.grammalecte_paragraph .pleo, +.grammalecte_paragraph .neg, +.grammalecte_paragraph .redon1, +.grammalecte_paragraph .redon2, +.grammalecte_paragraph .mc, +.grammalecte_paragraph .date, +.grammalecte_paragraph .notype { + background-color: hsl(180, 50%, 40%); + color: hsl(180, 10%, 96%); + /*text-decoration: underline wavy hsl(180, 50%, 40%);*/ +} + +.grammalecte_paragraph .bs:hover, +.grammalecte_paragraph .pleo:hover, +.grammalecte_paragraph .neg:hover, +.grammalecte_paragraph .redon1:hover, +.grammalecte_paragraph .redon2:hover, +.grammalecte_paragraph .mc:hover, +.grammalecte_paragraph .date:hover, +.grammalecte_paragraph .notype:hover { + background-color: hsl(180, 60%, 30%); + color: hsl(180, 10%, 96%); +} ADDED gc_lang/fr/webext/content_scripts/panel_gc.js Index: gc_lang/fr/webext/content_scripts/panel_gc.js ================================================================== --- /dev/null +++ gc_lang/fr/webext/content_scripts/panel_gc.js @@ -0,0 +1,458 @@ +// JavaScript + +"use strict"; + +function onGrammalecteGCPanelClick (xEvent) { + try { + let xElem = xEvent.target; + if (xElem.id) { + if (xElem.id.startsWith("grammalecte_sugg")) { + oGrammalecte.oGCPanel.applySuggestion(xElem.id); + } else if (xElem.id === "grammalecte_tooltip_ignore") { + oGrammalecte.oGCPanel.ignoreError(xElem.id); + } else if (xElem.id.startsWith("grammalecte_check")) { + oGrammalecte.oGCPanel.recheckParagraph(parseInt(xElem.dataset.para_num)); + } else if (xElem.id.startsWith("grammalecte_hide")) { + xElem.parentNode.parentNode.style.display = "none"; + } else if (xElem.tagName === "U" && xElem.id.startsWith("grammalecte_err") + && xElem.className !== "corrected" && xElem.className !== "ignored") { + oGrammalecte.oGCPanel.oTooltip.show(xElem.id); + } else if (xElem.id === "grammalecte_tooltip_url") { + oGrammalecte.oGCPanel.openURL(xElem.dataset.url); + } else { + oGrammalecte.oGCPanel.oTooltip.hide(); + } + } else { + oGrammalecte.oGCPanel.oTooltip.hide(); + } + } + catch (e) { + showError(e); + } +} + + +class GrammalecteGrammarChecker extends GrammalectePanel { + /* + KEYS for identifiers: + grammalecte_paragraph{Id} : [paragraph number] + grammalecte_check{Id} : [paragraph number] + grammalecte_hide{Id} : [paragraph number] + grammalecte_error{Id} : [paragraph number]-[error_number] + grammalecte_sugg{Id} : [paragraph number]-[error_number]--[suggestion_number] + */ + + constructor (...args) { + super(...args); + this.aIgnoredErrors = new Set(); + this.xContentNode = createNode("div", {id: "grammalecte_gc_panel_content"}); + this.xParagraphList = createNode("div", {id: "grammalecte_paragraph_list"}); + this.xContentNode.appendChild(this.xParagraphList); + this.xPanelContent.addEventListener("click", onGrammalecteGCPanelClick, false); + this.oTooltip = new GrammalecteTooltip(this.xContentNode); + this.xPanelContent.appendChild(this.xContentNode); + this.oTAC = new GrammalecteTextAreaControl(); + } + + start (xTextArea=null) { + this.clear(); + if (xTextArea) { + this.oTAC.setTextArea(xTextArea); + } + } + + clear () { + while (this.xParagraphList.firstChild) { + this.xParagraphList.removeChild(this.xParagraphList.firstChild); + } + this.aIgnoredErrors.clear(); + } + + hide () { + this.xPanelNode.style.display = "none"; + this.oTAC.clear(); + } + + addParagraphResult (oResult) { + try { + if (oResult && oResult.sParagraph.trim() !== "" && (oResult.aGrammErr.length > 0 || oResult.aSpellErr.length > 0)) { + let xNodeDiv = createNode("div", {className: "grammalecte_paragraph_block"}); + // actions + let xActionsBar = createNode("div", {className: "grammalecte_paragraph_actions"}); + xActionsBar.appendChild(createNode("div", {id: "grammalecte_check" + oResult.iParaNum, className: "button green", textContent: "Réanalyser"}, {para_num: oResult.iParaNum})); + xActionsBar.appendChild(createNode("div", {id: "grammalecte_hide" + oResult.iParaNum, className: "button red bold", textContent: "×"})); + // paragraph + let xParagraph = createNode("p", {id: "grammalecte_paragraph"+oResult.iParaNum, lang: "fr", contentEditable: "true"}, {para_num: oResult.iParaNum}); + xParagraph.setAttribute("spellcheck", "false"); // doesn’t seem possible to use “spellcheck” as a common attribute. + xParagraph.className = (oResult.aGrammErr.length || oResult.aSpellErr.length) ? "grammalecte_paragraph softred" : "grammalecte_paragraph"; + xParagraph.addEventListener("keyup", function (xEvent) { + this.oTAC.setParagraph(parseInt(xEvent.target.dataset.para_num), this.purgeText(xEvent.target.textContent)); + this.oTAC.write(); + }.bind(this) + , true); + this._tagParagraph(xParagraph, oResult.sParagraph, oResult.iParaNum, oResult.aGrammErr, oResult.aSpellErr); + // creation + xNodeDiv.appendChild(xActionsBar); + xNodeDiv.appendChild(xParagraph); + this.xParagraphList.appendChild(xNodeDiv); + } + } + catch (e) { + showError(e); + } + } + + recheckParagraph (iParaNum) { + let sParagraphId = "grammalecte_paragraph" + iParaNum; + let xParagraph = document.getElementById(sParagraphId); + this.blockParagraph(xParagraph); + let sText = this.purgeText(xParagraph.textContent); + xPort.postMessage({ + sCommand: "parseAndSpellcheck1", + dParam: {sText: sText, sCountry: "FR", bDebug: false, bContext: false}, + dInfo: {sParagraphId: sParagraphId} + }); + this.oTAC.setParagraph(iParaNum, sText); + this.oTAC.write(); + } + + refreshParagraph (sParagraphId, oResult) { + try { + let xParagraph = document.getElementById(sParagraphId); + xParagraph.className = (oResult.aGrammErr.length || oResult.aSpellErr.length) ? "grammalecte_paragraph softred" : "grammalecte_paragraph"; + xParagraph.textContent = ""; + this._tagParagraph(xParagraph, oResult.sParagraph, sParagraphId.slice(21), oResult.aGrammErr, oResult.aSpellErr); + this.freeParagraph(xParagraph); + } + catch (e) { + showError(e); + } + } + + _tagParagraph (xParagraph, sParagraph, iParaNum, aSpellErr, aGrammErr) { + try { + if (aGrammErr.length === 0 && aSpellErr.length === 0) { + xParagraph.textContent = sParagraph; + return; + } + aGrammErr.push(...aSpellErr); + aGrammErr.sort(function (a, b) { + if (a["nStart"] < b["nStart"]) + return -1; + if (a["nStart"] > b["nStart"]) + return 1; + return 0; + }); + let nErr = 0; // we count errors to give them an identifier + let nEndLastErr = 0; + for (let oErr of aGrammErr) { + let nStart = oErr["nStart"]; + let nEnd = oErr["nEnd"]; + if (nStart >= nEndLastErr) { + oErr['sErrorId'] = iParaNum + "-" + nErr.toString(); // error identifier + oErr['sIgnoredKey'] = iParaNum + ":" + nStart.toString() + ":" + sParagraph.slice(nStart, nEnd); + if (nEndLastErr < nStart) { + xParagraph.appendChild(document.createTextNode(sParagraph.slice(nEndLastErr, nStart))); + } + xParagraph.appendChild(this._createError(sParagraph.slice(nStart, nEnd), oErr)); + xParagraph.insertAdjacentHTML("beforeend", ""); + nEndLastErr = nEnd; + } + nErr += 1; + } + if (nEndLastErr <= sParagraph.length) { + xParagraph.appendChild(document.createTextNode(sParagraph.slice(nEndLastErr))); + } + } + catch (e) { + showError(e); + } + } + + _createError (sUnderlined, oErr) { + let xNodeErr = document.createElement("u"); + xNodeErr.id = "grammalecte_err" + oErr['sErrorId']; + xNodeErr.textContent = sUnderlined; + xNodeErr.dataset.error_id = oErr['sErrorId']; + xNodeErr.dataset.ignored_key = oErr['sIgnoredKey']; + xNodeErr.dataset.error_type = (oErr['sType'] === "WORD") ? "spelling" : "grammar"; + if (xNodeErr.dataset.error_type === "grammar") { + xNodeErr.dataset.gc_message = oErr['sMessage']; + xNodeErr.dataset.gc_url = oErr['URL']; + if (xNodeErr.dataset.gc_message.includes(" #")) { + xNodeErr.dataset.line_id = oErr['sLineId']; + xNodeErr.dataset.rule_id = oErr['sRuleId']; + } + xNodeErr.dataset.suggestions = oErr["aSuggestions"].join("|"); + } + xNodeErr.className = (this.aIgnoredErrors.has(xNodeErr.dataset.ignored_key)) ? "ignored" : "error " + oErr['sType']; + return xNodeErr; + } + + blockParagraph (xParagraph) { + xParagraph.contentEditable = "false"; + document.getElementById("grammalecte_check"+xParagraph.dataset.para_num).textContent = "Analyse…"; + } + + freeParagraph (xParagraph) { + xParagraph.contentEditable = "true"; + document.getElementById("grammalecte_check"+xParagraph.dataset.para_num).textContent = "Réanalyser"; + } + + applySuggestion (sNodeSuggId) { // sugg + try { + let sErrorId = document.getElementById(sNodeSuggId).dataset.error_id; + //let sParaNum = sErrorId.slice(0, sErrorId.indexOf("-")); + let xNodeErr = document.getElementById("grammalecte_err" + sErrorId); + xNodeErr.textContent = document.getElementById(sNodeSuggId).textContent; + xNodeErr.className = "corrected"; + xNodeErr.removeAttribute("style"); + this.oTooltip.hide(); + this.recheckParagraph(parseInt(sErrorId.slice(0, sErrorId.indexOf("-")))); + } + catch (e) { + showError(e); + } + } + + ignoreError (sIgnoreButtonId) { // ignore + try { + let sErrorId = document.getElementById(sIgnoreButtonId).dataset.error_id; + let xNodeErr = document.getElementById("grammalecte_err" + sErrorId); + this.aIgnoredErrors.add(xNodeErr.dataset.ignored_key); + xNodeErr.className = "ignored"; + this.oTooltip.hide(); + } + catch (e) { + showError(e); + } + } + + purgeText (sText) { + return sText.replace(/ /g, " ").replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&"); + } + + addSummary () { + // todo + } + + addMessage (sMessage) { + let xNode = createNode("div", {className: "grammalecte_gc_panel_message", textContent: sMessage}); + this.xParagraphList.appendChild(xNode); + } + + _copyToClipboard (sText) { + // recipe from https://github.com/mdn/webextensions-examples/blob/master/context-menu-copy-link-with-types/clipboard-helper.js + function setClipboardData (xEvent) { + document.removeEventListener("copy", setClipboardData, true); + xEvent.stopImmediatePropagation(); + xEvent.preventDefault(); + xEvent.clipboardData.setData("text/plain", sText); + }; + + document.addEventListener("copy", setClipboardData, true); + document.execCommand("copy"); + } + + copyTextToClipboard () { + this.startWaitIcon(); + try { + let xClipboardButton = document.getElementById("grammalecte_clipboard_button"); + xClipboardButton.textContent = "->>"; + let sText = ""; + for (let xNode of document.getElementsByClassName("grammalecte_paragraph")) { + sText += xNode.textContent + "\n"; + } + this._copyToClipboard(sText); + xClipboardButton.textContent = "OK"; + window.setTimeout(function() { xClipboardButton.textContent = "∑"; } , 2000); + } + catch (e) { + showError(e); + } + this.stopWaitIcon(); + } +} + + +class GrammalecteTooltip { + + constructor (xContentNode) { + this.xTooltip = createNode("div", {id: "grammalecte_tooltip"}); + this.xTooltipArrow = createNode("img", { + id: "grammalecte_tooltip_arrow", + src: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAECAYAAACzzX7wAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAOwQAADsEBuJFr7QAAABl0RVh0U29mdHdhcmUAcGFpbnQubmV0IDQuMC4xNkRpr/UAAAAlSURBVBhXY/j//z8cq/kW/wdhZDEMSXRFWCVhGKwAmwQCF/8HAGUkScGH4cM8AAAAAElFTkSuQmCC", + alt: "^" + }); + this.xTooltipSuggBlock = createNode("div", {id: "grammalecte_tooltip_sugg_block"}); + let xMessageBlock = createNode("div", {id: "grammalecte_tooltip_message_block"}); + xMessageBlock.appendChild(createNode("p", {id: "grammalecte_tooltip_rule_id"})); + xMessageBlock.appendChild(createNode("p", {id: "grammalecte_tooltip_message", textContent: "Erreur."})); + let xActions = xMessageBlock.appendChild(createNode("div", {id: "grammalecte_tooltip_actions"})); + xActions.appendChild(createNode("div", {id: "grammalecte_tooltip_ignore", textContent: "Ignorer"})); + xActions.appendChild(createNode("div", {id: "grammalecte_tooltip_url", textContent: "Voulez-vous en savoir plus ?…"}, {url: ""})); + xMessageBlock.appendChild(xActions); + this.xTooltip.appendChild(xMessageBlock); + this.xTooltip.appendChild(createNode("div", {id: "grammalecte_tooltip_sugg_title", textContent: "SUGGESTIONS :"})); + this.xTooltip.appendChild(this.xTooltipSuggBlock); + xContentNode.appendChild(this.xTooltip); + xContentNode.appendChild(this.xTooltipArrow); + } + + show (sNodeErrorId) { // err + try { + let xNodeErr = document.getElementById(sNodeErrorId); + let nLimit = 500 - 330; // paragraph width - tooltip width + this.xTooltipArrow.style.top = (xNodeErr.offsetTop + 16) + "px"; + this.xTooltipArrow.style.left = (xNodeErr.offsetLeft + Math.floor((xNodeErr.offsetWidth / 2))-4) + "px"; // 4 is half the width of the arrow. + this.xTooltip.style.top = (xNodeErr.offsetTop + 20) + "px"; + this.xTooltip.style.left = (xNodeErr.offsetLeft > nLimit) ? nLimit + "px" : xNodeErr.offsetLeft + "px"; + if (xNodeErr.dataset.error_type === "grammar") { + // grammar error + if (xNodeErr.dataset.gc_message.includes(" ##")) { + let n = xNodeErr.dataset.gc_message.indexOf(" ##"); + document.getElementById("grammalecte_tooltip_message").textContent = xNodeErr.dataset.gc_message.slice(0, n); + document.getElementById("grammalecte_tooltip_rule_id").textContent = "Règle : " + xNodeErr.dataset.gc_message.slice(n+2); + document.getElementById("grammalecte_tooltip_rule_id").style.display = "block"; + } else { + document.getElementById("grammalecte_tooltip_message").textContent = xNodeErr.dataset.gc_message; + document.getElementById("grammalecte_tooltip_rule_id").style.display = "none"; + } + if (xNodeErr.dataset.gc_url != "") { + document.getElementById("grammalecte_tooltip_url").dataset.url = xNodeErr.dataset.gc_url; + document.getElementById("grammalecte_tooltip_url").style.display = "inline"; + } else { + document.getElementById("grammalecte_tooltip_url").dataset.url = ""; + document.getElementById("grammalecte_tooltip_url").style.display = "none"; + } + document.getElementById("grammalecte_tooltip_ignore").dataset.error_id = xNodeErr.dataset.error_id; + let iSugg = 0; + let xGCSugg = document.getElementById("grammalecte_tooltip_sugg_block"); + xGCSugg.textContent = ""; + if (xNodeErr.dataset.suggestions.length > 0) { + for (let sSugg of xNodeErr.dataset.suggestions.split("|")) { + xGCSugg.appendChild(this._createSuggestion(xNodeErr.dataset.error_id, iSugg, sSugg)); + xGCSugg.appendChild(document.createTextNode(" ")); + iSugg += 1; + } + } else { + xGCSugg.textContent = "Aucune."; + } + } + this.xTooltipArrow.style.display = "block"; + this.xTooltip.style.display = "block"; + if (xNodeErr.dataset.error_type === "spelling") { + // spelling mistake + document.getElementById("grammalecte_tooltip_message").textContent = "Mot inconnu du dictionnaire."; + document.getElementById("grammalecte_tooltip_ignore").dataset.error_id = xNodeErr.dataset.error_id; + while (this.xTooltipSuggBlock.firstChild) { + this.xTooltipSuggBlock.removeChild(this.xTooltipSuggBlock.firstChild); + } + //console.log("getSuggFor: " + xNodeErr.textContent.trim() + " // error_id: " + xNodeErr.dataset.error_id); + //self.port.emit("getSuggestionsForTo", xNodeErr.textContent.trim(), xNodeErr.dataset.error_id); + this.setSpellSuggestionsFor(xNodeErr.textContent.trim(), "", xNodeErr.dataset.error_id); + } + } + catch (e) { + showError(e); + } + } + + setTooltipColor () { + // todo + } + + hide () { + this.xTooltipArrow.style.display = "none"; + this.xTooltip.style.display = "none"; + } + + _createSuggestion (sErrId, iSugg, sSugg) { + let xNodeSugg = document.createElement("a"); + xNodeSugg.id = "grammalecte_sugg" + sErrId + "--" + iSugg.toString(); + xNodeSugg.className = "sugg"; + xNodeSugg.dataset.error_id = sErrId; + xNodeSugg.textContent = sSugg; + return xNodeSugg; + } + + setSpellSuggestionsFor (sWord, sSuggestions, sErrId) { + // spell checking suggestions + try { + // console.log("setSuggestionsFor: " + sWord + " > " + sSuggestions + " // " + sErrId); + let xSuggBlock = document.getElementById("grammalecte_tooltip_sugg_block"); + xSuggBlock.textContent = ""; + if (sSuggestions === "") { + xSuggBlock.appendChild(document.createTextNode("Aucune.")); + } else if (sSuggestions.startsWith("#")) { + xSuggBlock.appendChild(document.createTextNode(sSuggestions)); + } else { + let lSugg = sSuggestions.split("|"); + let iSugg = 0; + for (let sSugg of lSugg) { + xSuggBlock.appendChild(this._createSuggestion(sErrId, iSugg, sSugg)); + xSuggBlock.appendChild(document.createTextNode(" ")); + iSugg += 1; + } + } + } + catch (e) { + showError(e); + } + } +} + + +class GrammalecteTextAreaControl { + + constructor () { + this._xTextArea = null; + this._dParagraph = new Map(); + } + + setTextArea (xNode) { + this.clear(); + this._xTextArea = xNode; + this._xTextArea.disabled = true; + this._loadText(); + } + + clear () { + if (this._xTextArea !== null) { + this._xTextArea.disabled = false; + this._xTextArea = null; + } + this._dParagraph.clear(); + } + + setParagraph (iParagraph, sText) { + if (this._xTextArea !== null) { + this._dParagraph.set(iParagraph, sText); + } + } + + _loadText () { + let sText = this._xTextArea.value; + let i = 0; + let iStart = 0; + let iEnd = 0; + sText = sText.replace("\r\n", "\n").replace("\r", "\n"); + while ((iEnd = sText.indexOf("\n", iStart)) !== -1) { + 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)); + } + + write () { + if (this._xTextArea !== null) { + let sText = ""; + this._dParagraph.forEach(function (val, key) { + sText += val + "\n"; + }); + this._xTextArea.value = sText.slice(0,-1); + } + } +} ADDED gc_lang/fr/webext/content_scripts/panel_lxg.css Index: gc_lang/fr/webext/content_scripts/panel_lxg.css ================================================================== --- /dev/null +++ gc_lang/fr/webext/content_scripts/panel_lxg.css @@ -0,0 +1,83 @@ +/* + Lexicographer +*/ +#grammalecte_lxg_panel_content { + padding: 5px; + font-size: 13px; +} + +.grammalecte_lxg_list_of_tokens { + margin: 5px 0 10px 0; + padding: 10px; + background-color: hsla(0, 0%, 96%, 1); + border-radius: 2px; +} +.grammalecte_lxg_list_of_tokens .num { + float: right; + margin: -12px 0 5px 10px; + padding: 5px 10px; + font-weight: bold; + border-radius: 0 0 4px 4px; + background-color: hsl(0, 50%, 50%); + color: hsl(0, 10%, 96%); +} +.grammalecte_token { + padding: 4px 0; +} +.grammalecte_token .separator { + margin: 20px 0; + padding: 5px 5px; + background-color: hsla(0, 0%, 75%, 1); + color: hsla(0, 0%, 96%, 1); + border-radius: 5px; + text-align: center; + font-size: 20px; +} +.grammalecte_token ul { + margin: 0 0 5px 5px; +} +.grammalecte_token b { + background-color: hsla(150, 10%, 50%, 1); + color: hsla(0, 0%, 96%, 1); + padding: 2px 5px; + border-radius: 2px; + text-decoration: none; +} +.grammalecte_token b.WORD { + background-color: hsla(150, 50%, 50%, 1); +} +.grammalecte_token b.ELPFX { + background-color: hsla(150, 30%, 50%, 1); +} +.grammalecte_token b.UNKNOWN { + background-color: hsla(0, 50%, 50%, 1); +} +.grammalecte_token b.NUM { + background-color: hsla(180, 50%, 50%, 1); +} +.grammalecte_token b.COMPLEX { + background-color: hsla(60, 50%, 50%, 1); +} +.grammalecte_token b.SEPARATOR { + background-color: hsla(210, 50%, 50%, 1); +} +.grammalecte_token b.LINK { + background-color: hsla(270, 50%, 50%, 1); +} +.grammalecte_token s { + color: hsla(0, 0%, 60%, 1); + text-decoration: none; +} +.grammalecte_token .textline { + text-decoration: bold; +} + +.grammalecte_token p.message { + margin-top: 20px; + padding: 10px 10px; + background-color: hsla(240, 10%, 50%, 1); + font-size: 18px; + color: hsla(240, 0%, 96%, 1); + border-radius: 3px; + text-align: center; +} ADDED gc_lang/fr/webext/content_scripts/panel_lxg.js Index: gc_lang/fr/webext/content_scripts/panel_lxg.js ================================================================== --- /dev/null +++ gc_lang/fr/webext/content_scripts/panel_lxg.js @@ -0,0 +1,69 @@ +// JavaScript + +"use strict"; + +class GrammalecteLexicographer extends GrammalectePanel { + + constructor (...args) { + super(...args); + this._nCount = 0; + this._xContentNode = createNode("div", {id: "grammalecte_lxg_panel_content"}); + this.xPanelContent.appendChild(this._xContentNode); + } + + clear () { + this._nCount = 0; + while (this._xContentNode.firstChild) { + this._xContentNode.removeChild(this._xContentNode.firstChild); + } + } + + addSeparator (sText) { + if (this._xContentNode.textContent !== "") { + this._xContentNode.appendChild(createNode("div", {className: "grammalecte_lxg_separator", textContent: sText})); + } + } + + addMessage (sClass, sText) { + this._xContentNode.appendChild(createNode("div", {className: sClass, textContent: sText})); + } + + addListOfTokens (lTokens) { + try { + if (lTokens) { + this._nCount += 1; + let xNodeDiv = createNode("div", {className: "grammalecte_lxg_list_of_tokens"}); + xNodeDiv.appendChild(createNode("div", {className: "num", textContent: this._nCount})); + for (let oToken of lTokens) { + xNodeDiv.appendChild(this._createTokenNode(oToken)); + } + this._xContentNode.appendChild(xNodeDiv); + } + } + catch (e) { + showError(e); + } + } + + _createTokenNode (oToken) { + let xTokenNode = createNode("div", {className: "grammalecte_token"}); + xTokenNode.appendChild(createNode("b", {className: oToken.sType, textContent: oToken.sValue})); + xTokenNode.appendChild(createNode("s", {textContent: " : "})); + if (oToken.aLabel.length === 1) { + xTokenNode.appendChild(document.createTextNode(oToken.aLabel[0])); + } else { + let xTokenList = document.createElement("ul"); + for (let sLabel of oToken.aLabel) { + xTokenList.appendChild(createNode("li", {textContent: sLabel})); + } + xTokenNode.appendChild(xTokenList); + } + return xTokenNode; + } + + setHidden (sClass, bHidden) { + for (let xNode of document.getElementsByClassName(sClass)) { + xNode.hidden = bHidden; + } + } +} ADDED gc_lang/fr/webext/content_scripts/panel_tf.css Index: gc_lang/fr/webext/content_scripts/panel_tf.css ================================================================== --- /dev/null +++ gc_lang/fr/webext/content_scripts/panel_tf.css @@ -0,0 +1,104 @@ +/* + CSS for the Text Formatter +*/ + + +/* + Options +*/ +#grammalecte_tf_options { + display: flex; + padding: 10px; +} +.grammalecte_tf_column { + flex-grow: 1; + width: 360px; + padding: 0 5px; +} +#grammalecte_tf_options legend label { + font-size: 20px; + color: hsla(210, 20%, 50%, .8); + font-weight: bold; +} +#grammalecte_tf_options fieldset { + padding: 2px 10px 10px 13px; + margin-bottom: 5px; + background-color: hsl(210, 10%, 96%); + border-color: hsl(210, 20%, 80%); + border-radius: 3px; +} +#grammalecte_tf_options legend .option { + margin: 7px 5px 0 4px; + float: left; +} +#grammalecte_tf_options label { + font-size: 13px; +} +#grammalecte_tf_options .underline:hover { + background-color: hsl(210, 10%, 86%); + border-radius: 2px; +} +#grammalecte_tf_options .blockopt .option { + margin: 4px 5px 0 6px; + float: left; +} +#grammalecte_tf_options .grammalecte_tf_result { + float: right; + margin: 2px 3px 0 0; + font-size: 13px; +} +#grammalecte_tf_options .indent { + padding-left: 20px; +} +#grammalecte_tf_options .inlineblock { + display: inline-block; + margin-right: 10px; +} +#grammalecte_tf_options .rmg10 { + margin-right: 10px; +} + + + +/* + Actions +*/ +#grammalecte_tf_actions { + /*background-color: hsl(120, 10%, 92%);*/ + display: flex; + justify-content: space-between; + padding: 15px 15px 10px 15px; + border-top: 1px solid hsl(210, 10%, 90%); +} + +.grammalecte_button { + display: inline-block; + padding: 5px 10px; + width: 100px; + border-radius: 3px; + font-size: 16px; + font-weight: bold; + text-align: center; + cursor: pointer; +} + +#grammalecte_tf_reset { + background-color: hsl(210, 100%, 50%); + color: hsl(210, 0%, 100%); +} +#grammalecte_tf_progressbar { + width: 400px; +} +#grammalecte_tf_time_res { + width: 60px; + padding: 5px 10px; +} +#grammalecte_tf_apply { + background-color: hsl(120, 100%, 50%); + color: hsl(150, 0%, 100%); +} + +#grammalecte_progressbarbox { + display: inline-block; + padding: 10px 20px; +} ADDED gc_lang/fr/webext/content_scripts/panel_tf.js Index: gc_lang/fr/webext/content_scripts/panel_tf.js ================================================================== --- /dev/null +++ gc_lang/fr/webext/content_scripts/panel_tf.js @@ -0,0 +1,553 @@ +// JavaScript +// Text formatter + +"use strict"; + + +class GrammalecteTextFormatter extends GrammalectePanel { + + constructor (...args) { + super(...args); + this.xTFNode = this._createTextFormatter(); + this.xPanelContent.appendChild(this.xTFNode); + this.xTextArea = null; + } + + _createTextFormatter () { + let xTFNode = document.createElement("div"); + try { + // Options + let xOptions = createNode("div", {id: "grammalecte_tf_options"}); + let xColumn1 = createNode("div", {className: "grammalecte_tf_column"}); + let xSSP = this._createFieldset("group_ssp", true, "Espaces surnuméraires"); + xSSP.appendChild(this._createSimpleOption("o_start_of_paragraph", true, "En début de paragraphe")); + xSSP.appendChild(this._createSimpleOption("o_end_of_paragraph", true, "En fin de paragraphe")); + xSSP.appendChild(this._createSimpleOption("o_between_words", true, "Entre les mots")); + xSSP.appendChild(this._createSimpleOption("o_before_punctuation", true, "Avant les points (.), les virgules (,)")); + xSSP.appendChild(this._createSimpleOption("o_within_parenthesis", true, "À l’intérieur des parenthèses")); + xSSP.appendChild(this._createSimpleOption("o_within_square_brackets", true, "À l’intérieur des crochets")); + xSSP.appendChild(this._createSimpleOption("o_within_quotation_marks", true, "À l’intérieur des guillemets “ et ”")); + let xSpace = this._createFieldset("group_space", true, "Espaces manquants"); + xSpace.appendChild(this._createSimpleOption("o_add_space_after_punctuation", true, "Après , ; : ? ! . …")); + xSpace.appendChild(this._createSimpleOption("o_add_space_around_hyphens", true, "Autour des tirets d’incise")); + let xNBSP = this._createFieldset("group_nbsp", true, "Espaces insécables"); + xNBSP.appendChild(this._createSimpleOption("o_nbsp_before_punctuation", true, "Avant : ; ? et !")); + xNBSP.appendChild(this._createSimpleOption("o_nbsp_within_quotation_marks", true, "Avec les guillemets « et »")); + xNBSP.appendChild(this._createSimpleOption("o_nbsp_before_symbol", true, "Avant % ‰ € $ £ ¥ ˚C")); + xNBSP.appendChild(this._createSimpleOption("o_nbsp_within_numbers", true, "À l’intérieur des nombres")); + xNBSP.appendChild(this._createSimpleOption("o_nbsp_before_units", true, "Avant les unités de mesure")); + let xDelete = this._createFieldset("group_delete", true, "Suppressions"); + xDelete.appendChild(this._createSimpleOption("o_erase_non_breaking_hyphens", true, "Tirets conditionnels")); + let xColumn2 = createNode("div", {className: "grammalecte_tf_column"}); + let xTypo = this._createFieldset("group_typo", true, "Signes typographiques"); + xTypo.appendChild(this._createSimpleOption("o_ts_apostrophe", true, "Apostrophe (’)")); + xTypo.appendChild(this._createSimpleOption("o_ts_ellipsis", true, "Points de suspension (…)")); + xTypo.appendChild(this._createSimpleOption("o_ts_dash_middle", true, "Tirets d’incise :")); + xTypo.appendChild(this._createRadioBoxHyphens("hyphen1", "o_ts_m_dash_middle", "o_ts_n_dash_middle", false)); + xTypo.appendChild(this._createSimpleOption("o_ts_dash_start", true, "Tirets en début de paragraphe :")); + xTypo.appendChild(this._createRadioBoxHyphens("hyphen2", "o_ts_m_dash_start", "o_ts_n_dash_start", true)); + xTypo.appendChild(this._createSimpleOption("o_ts_quotation_marks", true, "Modifier les guillemets droits (\" et ')")); + xTypo.appendChild(this._createSimpleOption("o_ts_units", true, "Points médians des unités (N·m, Ω·m…)")); + xTypo.appendChild(this._createSimpleOption("o_ts_spell", true, "Ligatures (cœur…) et diacritiques (ça, État…)")); + xTypo.appendChild(this._createRadioBoxLigatures()); + xTypo.appendChild(this._createLigaturesSelection()); + let xMisc = this._createFieldset("group_misc", true, "Divers"); + xMisc.appendChild(this._createOrdinalOptions()); + xMisc.appendChild(this._createSimpleOption("o_etc", true, "Et cætera, etc.")); + xMisc.appendChild(this._createSimpleOption("o_missing_hyphens", true, "Traits d’union manquants")); + xMisc.appendChild(this._createSimpleOption("o_ma_word", true, "Apostrophes manquantes")); + xMisc.appendChild(this._createSingleLetterOptions()); + let xStruct = this._createFieldset("group_struct", false, "Restructuration [!]"); + xStruct.appendChild(this._createSimpleOption("o_remove_hyphens_at_end_of_paragraphs", false, "Enlever césures en fin de ligne/paragraphe [!]")); + xStruct.appendChild(this._createSimpleOption("o_merge_contiguous_paragraphs", false, "Fusionner les paragraphes contigus [!]")); + xColumn1.appendChild(xSSP); + xColumn1.appendChild(xSpace); + xColumn1.appendChild(xNBSP); + xColumn1.appendChild(xDelete); + xColumn2.appendChild(xTypo); + xColumn2.appendChild(xMisc); + xColumn2.appendChild(xStruct); + xOptions.appendChild(xColumn1); + xOptions.appendChild(xColumn2); + // Actions + let xActions = createNode("div", {id: "grammalecte_tf_actions"}); + let xDefaultButton = createNode("div", {id: "grammalecte_tf_reset", textContent: "Par défaut", className: "grammalecte_button", style: "background-color: hsl(210, 50%, 50%)"}); + xDefaultButton.addEventListener("click", () => { this.reset(); }); + let xApplyButton = createNode("div", {id: "grammalecte_tf_apply", textContent: "Appliquer", className: "grammalecte_button", style: "background-color: hsl(180, 50%, 50%)"}); + xApplyButton.addEventListener("click", () => { this.saveOptions(); this.apply(); }); + xActions.appendChild(xDefaultButton); + xActions.appendChild(createNode("progress", {id: "grammalecte_tf_progressbar"})); + xActions.appendChild(createNode("span", {id: "grammalecte_tf_time_res", textContent: "…"})); + xActions.appendChild(xApplyButton); + //xActions.appendChild(createNode("div", {id: "grammalecte_infomsg", textContent: "blabla"})); + // create result + xTFNode.appendChild(xOptions); + xTFNode.appendChild(xActions); + } + catch (e) { + showError(e); + } + return xTFNode; + } + + // Common options + _createFieldset (sId, bDefault, sLabel) { + let xFieldset = createNode("fieldset", {id: sId, className: "groupblock"}); + let xLegend = document.createElement("legend"); + let xGroupOption = createNode("input", {type: "checkbox", id: "o_"+sId, className: "option"}, {default: bDefault}); + xGroupOption.addEventListener("click", (xEvent) => { this.switchGroup(xEvent.target.id); }); + xLegend.appendChild(xGroupOption); + xLegend.appendChild(createNode("label", {htmlFor: "o_"+sId, textContent: sLabel})); + xFieldset.appendChild(xLegend); + return xFieldset; + } + + _createSimpleOption (sId, bDefault, sLabel) { + let xLine = createNode("div", {className: "blockopt underline"}); + xLine.appendChild(createNode("input", {type: "checkbox", id: sId, className: "option"}, {default: bDefault})); + xLine.appendChild(createNode("label", {htmlFor: sId, textContent: sLabel, className: "opt_lbl largew"})); + xLine.appendChild(createNode("div", {id: "res_"+sId, className: "grammalecte_tf_result", textContent: "·"})); + return xLine; + } + + // Hyphens + _createRadioBoxHyphens (sName, sIdEmDash, sIdEnDash, bDefaultEmDash) { + let xLine = createNode("div", {className: "blockopt indent"}); + xLine.appendChild(this._createInlineRadioOption(sName, sIdEmDash, "cadratin (—)", bDefaultEmDash)); + xLine.appendChild(this._createInlineRadioOption(sName, sIdEnDash, "demi-cadratin (—)", !bDefaultEmDash)); + return xLine; + } + + // Ligatures + _createRadioBoxLigatures () { + let xLine = createNode("div", {className: "blockopt underline"}); + xLine.appendChild(createNode("div", {id: "res_"+"o_ts_ligature", className: "grammalecte_tf_result", textContent: "·"})); + xLine.appendChild(this._createInlineCheckboxOption("o_ts_ligature", "Ligatures", true)); + xLine.appendChild(this._createInlineRadioOption("liga", "o_ts_ligature_do", "faire", false)); + xLine.appendChild(this._createInlineRadioOption("liga", "o_ts_ligature_undo", "défaire", true)); + return xLine; + } + + _createLigaturesSelection () { + let xLine = createNode("div", {className: "blockopt indent"}); + xLine.appendChild(this._createInlineCheckboxOption("o_ts_ligature_ff", "ff", true)); + xLine.appendChild(this._createInlineCheckboxOption("o_ts_ligature_fi", "fi", true)); + xLine.appendChild(this._createInlineCheckboxOption("o_ts_ligature_ffi", "ffi", true)); + xLine.appendChild(this._createInlineCheckboxOption("o_ts_ligature_fl", "fl", true)); + xLine.appendChild(this._createInlineCheckboxOption("o_ts_ligature_ffl", "ffl", true)); + xLine.appendChild(this._createInlineCheckboxOption("o_ts_ligature_ft", "ft", true)); + xLine.appendChild(this._createInlineCheckboxOption("o_ts_ligature_st", "st", false)); + return xLine; + } + + // Apostrophes + _createSingleLetterOptions () { + let xLine = createNode("div", {className: "blockopt indent"}); + xLine.appendChild(this._createInlineCheckboxOption("o_ma_1letter_lowercase", "lettres isolées (j’ n’ m’ t’ s’ c’ d’ l’)", false)); + xLine.appendChild(this._createInlineCheckboxOption("o_ma_1letter_uppercase", "Maj.", false)); + return xLine; + } + + // Ordinals + _createOrdinalOptions () { + let xLine = createNode("div", {className: "blockopt underline"}); + xLine.appendChild(createNode("div", {id: "res_"+"o_ordinals_no_exponant", className: "grammalecte_tf_result", textContent: "·"})); + xLine.appendChild(this._createInlineCheckboxOption("o_ordinals_no_exponant", "Ordinaux (15e, XXIe…)", true)); + xLine.appendChild(this._createInlineCheckboxOption("o_ordinals_exponant", "e → ᵉ", true)); + return xLine; + } + + + // Inline option block + _createInlineCheckboxOption (sId, sLabel, bDefault) { + let xInlineBlock = createNode("div", {className: "inlineblock"}); + xInlineBlock.appendChild(createNode("input", {type: "checkbox", id: sId, className: "option"}, {default: bDefault})); + xInlineBlock.appendChild(createNode("label", {htmlFor: sId, textContent: sLabel, className: "opt_lbl"})); + return xInlineBlock; + } + + _createInlineRadioOption (sName, sId, sLabel, bDefault) { + let xInlineBlock = createNode("div", {className: "inlineblock"}); + xInlineBlock.appendChild(createNode("input", {type: "radio", id: sId, name: sName, className:"option"}, {default: bDefault})); + xInlineBlock.appendChild(createNode("label", {htmlFor: sId, className: "opt_lbl", textContent: sLabel})); + return xInlineBlock; + } + + + /* + Actions + */ + start (xTextArea) { + this.xTextArea = xTextArea; + let xPromise = browser.storage.local.get("tf_options"); + xPromise.then(this.setOptions.bind(this), this.reset.bind(this)); + } + + switchGroup (sOptName) { + if (document.getElementById(sOptName).checked) { + document.getElementById(sOptName.slice(2)).style.opacity = 1; + } else { + document.getElementById(sOptName.slice(2)).style.opacity = 0.3; + } + this.resetProgressBar(); + } + + reset () { + this.resetProgressBar(); + for (let xNode of document.getElementsByClassName("option")) { + xNode.checked = (xNode.dataset.default === "true"); + if (xNode.id.startsWith("o_group_")) { + this.switchGroup(xNode.id); + } + } + } + + resetProgressBar () { + document.getElementById('grammalecte_tf_progressbar').value = 0; + document.getElementById('grammalecte_tf_time_res').textContent = ""; + } + + setOptions (oOptions) { + if (oOptions.hasOwnProperty("tf_options")) { + oOptions = oOptions.tf_options; + } + for (let xNode of document.getElementsByClassName("option")) { + //console.log(xNode.id + " > " + oOptions.hasOwnProperty(xNode.id) + ": " + oOptions[xNode.id] + " [" + xNode.dataset.default + "]"); + xNode.checked = (oOptions.hasOwnProperty(xNode.id)) ? oOptions[xNode.id] : (xNode.dataset.default === "true"); + if (document.getElementById("res_"+xNode.id) !== null) { + document.getElementById("res_"+xNode.id).textContent = ""; + } + if (xNode.id.startsWith("o_group_")) { + this.switchGroup(xNode.id); + } + } + } + + saveOptions () { + let oOptions = {}; + for (let xNode of document.getElementsByClassName("option")) { + oOptions[xNode.id] = xNode.checked; + //console.log(xNode.id + ": " + xNode.checked); + } + browser.storage.local.set({"tf_options": oOptions}); + } + + apply () { + try { + const t0 = Date.now(); + //window.setCursor("wait"); // change pointer + this.resetProgressBar(); + let sText = this.xTextArea.value; + document.getElementById('grammalecte_tf_progressbar').max = 7; + let n1 = 0, n2 = 0, n3 = 0, n4 = 0, n5 = 0, n6 = 0, n7 = 0; + + // Restructuration + if (document.getElementById("o_group_struct").checked) { + if (document.getElementById("o_remove_hyphens_at_end_of_paragraphs").checked) { + [sText, n1] = this.removeHyphenAtEndOfParagraphs(sText); + document.getElementById('res_o_remove_hyphens_at_end_of_paragraphs').textContent = n1; + } + if (document.getElementById("o_merge_contiguous_paragraphs").checked) { + [sText, n1] = this.mergeContiguousParagraphs(sText); + document.getElementById('res_o_merge_contiguous_paragraphs').textContent = n1; + } + document.getElementById("o_group_struct").checked = false; + this.switchGroup("o_group_struct"); + } + document.getElementById('grammalecte_tf_progressbar').value = 1; + + // espaces surnuméraires + if (document.getElementById("o_group_ssp").checked) { + if (document.getElementById("o_end_of_paragraph").checked) { + [sText, n1] = this.formatText(sText, "end_of_paragraph"); + document.getElementById('res_o_end_of_paragraph').textContent = n1; + } + if (document.getElementById("o_between_words").checked) { + [sText, n1] = this.formatText(sText, "between_words"); + document.getElementById('res_o_between_words').textContent = n1; + } + if (document.getElementById("o_start_of_paragraph").checked) { + [sText, n1] = this.formatText(sText, "start_of_paragraph"); + document.getElementById('res_o_start_of_paragraph').textContent = n1; + } + if (document.getElementById("o_before_punctuation").checked) { + [sText, n1] = this.formatText(sText, "before_punctuation"); + document.getElementById('res_o_before_punctuation').textContent = n1; + } + if (document.getElementById("o_within_parenthesis").checked) { + [sText, n1] = this.formatText(sText, "within_parenthesis"); + document.getElementById('res_o_within_parenthesis').textContent = n1; + } + if (document.getElementById("o_within_square_brackets").checked) { + [sText, n1] = this.formatText(sText, "within_square_brackets"); + document.getElementById('res_o_within_square_brackets').textContent = n1; + } + if (document.getElementById("o_within_quotation_marks").checked) { + [sText, n1] = this.formatText(sText, "within_quotation_marks"); + document.getElementById('res_o_within_quotation_marks').textContent = n1; + } + document.getElementById("o_group_ssp").checked = false; + this.switchGroup("o_group_ssp"); + } + document.getElementById('grammalecte_tf_progressbar').value = 2; + + // espaces typographiques + if (document.getElementById("o_group_nbsp").checked) { + if (document.getElementById("o_nbsp_before_punctuation").checked) { + [sText, n1] = this.formatText(sText, "nbsp_before_punctuation"); + [sText, n2] = this.formatText(sText, "nbsp_repair"); + document.getElementById('res_o_nbsp_before_punctuation').textContent = n1 - n2; + } + if (document.getElementById("o_nbsp_within_quotation_marks").checked) { + [sText, n1] = this.formatText(sText, "nbsp_within_quotation_marks"); + document.getElementById('res_o_nbsp_within_quotation_marks').textContent = n1; + } + if (document.getElementById("o_nbsp_before_symbol").checked) { + [sText, n1] = this.formatText(sText, "nbsp_before_symbol"); + document.getElementById('res_o_nbsp_before_symbol').textContent = n1; + } + if (document.getElementById("o_nbsp_within_numbers").checked) { + [sText, n1] = this.formatText(sText, "nbsp_within_numbers"); + document.getElementById('res_o_nbsp_within_numbers').textContent = n1; + } + if (document.getElementById("o_nbsp_before_units").checked) { + [sText, n1] = this.formatText(sText, "nbsp_before_units"); + document.getElementById('res_o_nbsp_before_units').textContent = n1; + } + document.getElementById("o_group_nbsp").checked = false; + this.switchGroup("o_group_nbsp"); + } + document.getElementById('grammalecte_tf_progressbar').value = 3; + + // espaces manquants + if (document.getElementById("o_group_typo").checked) { + if (document.getElementById("o_ts_units").checked) { + [sText, n1] = this.formatText(sText, "ts_units"); + document.getElementById('res_o_ts_units').textContent = n1; + } + } + if (document.getElementById("o_group_space").checked) { + if (document.getElementById("o_add_space_after_punctuation").checked) { + [sText, n1] = this.formatText(sText, "add_space_after_punctuation"); + [sText, n2] = this.formatText(sText, "add_space_repair"); + document.getElementById('res_o_add_space_after_punctuation').textContent = n1 - n2; + } + if (document.getElementById("o_add_space_around_hyphens").checked) { + [sText, n1] = this.formatText(sText, "add_space_around_hyphens"); + document.getElementById('res_o_add_space_around_hyphens').textContent = n1; + } + document.getElementById("o_group_space").checked = false; + this.switchGroup("o_group_space"); + } + document.getElementById('grammalecte_tf_progressbar').value = 4; + + // suppression + if (document.getElementById("o_group_delete").checked) { + if (document.getElementById("o_erase_non_breaking_hyphens").checked) { + [sText, n1] = this.formatText(sText, "erase_non_breaking_hyphens"); + document.getElementById('res_o_erase_non_breaking_hyphens').textContent = n1; + } + document.getElementById("o_group_delete").checked = false; + this.switchGroup("o_group_delete"); + } + document.getElementById('grammalecte_tf_progressbar').value = 5; + + // signes typographiques + if (document.getElementById("o_group_typo").checked) { + if (document.getElementById("o_ts_apostrophe").checked) { + [sText, n1] = this.formatText(sText, "ts_apostrophe"); + document.getElementById('res_o_ts_apostrophe').textContent = n1; + } + if (document.getElementById("o_ts_ellipsis").checked) { + [sText, n1] = this.formatText(sText, "ts_ellipsis"); + document.getElementById('res_o_ts_ellipsis').textContent = n1; + } + if (document.getElementById("o_ts_dash_start").checked) { + if (document.getElementById("o_ts_m_dash_start").checked) { + [sText, n1] = this.formatText(sText, "ts_m_dash_start"); + } else { + [sText, n1] = this.formatText(sText, "ts_n_dash_start"); + } + document.getElementById('res_o_ts_dash_start').textContent = n1; + } + if (document.getElementById("o_ts_dash_middle").checked) { + if (document.getElementById("o_ts_m_dash_middle").checked) { + [sText, n1] = this.formatText(sText, "ts_m_dash_middle"); + } else { + [sText, n1] = this.formatText(sText, "ts_n_dash_middle"); + } + document.getElementById('res_o_ts_dash_middle').textContent = n1; + } + if (document.getElementById("o_ts_quotation_marks").checked) { + [sText, n1] = this.formatText(sText, "ts_quotation_marks"); + document.getElementById('res_o_ts_quotation_marks').textContent = n1; + } + if (document.getElementById("o_ts_spell").checked) { + [sText, n1] = this.formatText(sText, "ts_spell"); + document.getElementById('res_o_ts_spell').textContent = n1; + } + if (document.getElementById("o_ts_ligature").checked) { + // ligatures typographiques : fi, fl, ff, ffi, ffl, ft, st + if (document.getElementById("o_ts_ligature_do").checked) { + if (document.getElementById("o_ts_ligature_ffi").checked) { + [sText, n1] = this.formatText(sText, "ts_ligature_ffi_do"); + } + if (document.getElementById("o_ts_ligature_ffl").checked) { + [sText, n2] = this.formatText(sText, "ts_ligature_ffl_do"); + } + if (document.getElementById("o_ts_ligature_fi").checked) { + [sText, n3] = this.formatText(sText, "ts_ligature_fi_do"); + } + if (document.getElementById("o_ts_ligature_fl").checked) { + [sText, n4] = this.formatText(sText, "ts_ligature_fl_do"); + } + if (document.getElementById("o_ts_ligature_ff").checked) { + [sText, n5] = this.formatText(sText, "ts_ligature_ff_do"); + } + if (document.getElementById("o_ts_ligature_ft").checked) { + [sText, n6] = this.formatText(sText, "ts_ligature_ft_do"); + } + if (document.getElementById("o_ts_ligature_st").checked) { + [sText, n7] = this.formatText(sText, "ts_ligature_st_do"); + } + } + if (document.getElementById("o_ts_ligature_undo").checked) { + if (document.getElementById("o_ts_ligature_ffi").checked) { + [sText, n1] = this.formatText(sText, "ts_ligature_ffi_undo"); + } + if (document.getElementById("o_ts_ligature_ffl").checked) { + [sText, n2] = this.formatText(sText, "ts_ligature_ffl_undo"); + } + if (document.getElementById("o_ts_ligature_fi").checked) { + [sText, n3] = this.formatText(sText, "ts_ligature_fi_undo"); + } + if (document.getElementById("o_ts_ligature_fl").checked) { + [sText, n4] = this.formatText(sText, "ts_ligature_fl_undo"); + } + if (document.getElementById("o_ts_ligature_ff").checked) { + [sText, n5] = this.formatText(sText, "ts_ligature_ff_undo"); + } + if (document.getElementById("o_ts_ligature_ft").checked) { + [sText, n6] = this.formatText(sText, "ts_ligature_ft_undo"); + } + if (document.getElementById("o_ts_ligature_st").checked) { + [sText, n7] = this.formatText(sText, "ts_ligature_st_undo"); + } + } + document.getElementById('res_o_ts_ligature').textContent = n1 + n2 + n3 + n4 + n5 + n6 + n7; + } + document.getElementById("o_group_typo").checked = false; + this.switchGroup("o_group_typo"); + } + document.getElementById('grammalecte_tf_progressbar').value = 6; + + // divers + if (document.getElementById("o_group_misc").checked) { + if (document.getElementById("o_ordinals_no_exponant").checked) { + if (document.getElementById("o_ordinals_exponant").checked) { + [sText, n1] = this.formatText(sText, "ordinals_exponant"); + } else { + [sText, n1] = this.formatText(sText, "ordinals_no_exponant"); + } + document.getElementById('res_o_ordinals_no_exponant').textContent = n1; + } + if (document.getElementById("o_etc").checked) { + [sText, n1] = this.formatText(sText, "etc"); + document.getElementById('res_o_etc').textContent = n1; + } + if (document.getElementById("o_missing_hyphens").checked) { + [sText, n1] = this.formatText(sText, "missing_hyphens"); + document.getElementById('res_o_missing_hyphens').textContent = n1; + } + if (document.getElementById("o_ma_word").checked) { + [sText, n1] = this.formatText(sText, "ma_word"); + if (document.getElementById("o_ma_1letter_lowercase").checked) { + [sText, n1] = this.formatText(sText, "ma_1letter_lowercase"); + if (document.getElementById("o_ma_1letter_uppercase").checked) { + [sText, n1] = this.formatText(sText, "ma_1letter_uppercase"); + } + } + document.getElementById('res_o_ma_word').textContent = n1; + } + document.getElementById("o_group_misc").checked = false; + this.switchGroup("o_group_misc"); + } + document.getElementById('grammalecte_tf_progressbar').value = document.getElementById('grammalecte_tf_progressbar').max; + // end of processing + + //window.setCursor("auto"); // restore pointer + + const t1 = Date.now(); + document.getElementById('grammalecte_tf_time_res').textContent = this.getTimeRes((t1-t0)/1000); + this.xTextArea.value = sText; + } + catch (e) { + showError(e); + } + } + + formatText (sText, sOptName) { + let nCount = 0; + try { + if (!oReplTable.hasOwnProperty(sOptName)) { + console.log("# Error. TF: there is no option “" + sOptName+ "”."); + return [sText, nCount]; + } + for (let [zRgx, sRep] of oReplTable[sOptName]) { + nCount += (sText.match(zRgx) || []).length; + sText = sText.replace(zRgx, sRep); + } + } + catch (e) { + showError(e); + } + return [sText, nCount]; + } + + removeHyphenAtEndOfParagraphs (sText) { + let nCount = (sText.match(/-[  ]*\n/gm) || []).length; + sText = sText.replace(/-[  ]*\n/gm, ""); + return [sText, nCount]; + } + + mergeContiguousParagraphs (sText) { + let nCount = 0; + sText = sText.replace(/^[  ]+$/gm, ""); // clear empty paragraphs + let s = ""; + for (let sParagraph of this.getParagraph(sText)) { + if (sParagraph === "") { + s += "\n"; + } else { + s += sParagraph + " "; + nCount += 1; + } + } + s = s.replace(/ +/gm, " ").replace(/ $/gm, ""); + return [s, nCount]; + } + + * getParagraph (sText) { + // generator: returns paragraphs of text + let iStart = 0; + let iEnd = 0; + while ((iEnd = sText.indexOf("\n", iStart)) !== -1) { + yield sText.slice(iStart, iEnd); + iStart = iEnd + 1; + } + yield sText.slice(iStart); + } + + getTimeRes (n) { + // returns duration in seconds as string + if (n < 10) { + return n.toFixed(3).toString() + " s"; + } + if (n < 100) { + return n.toFixed(2).toString() + " s"; + } + if (n < 1000) { + return n.toFixed(1).toString() + " s"; + } + return n.toFixed().toString() + " s"; + } +} DELETED gc_lang/fr/webext/content_scripts/panels_content.css Index: gc_lang/fr/webext/content_scripts/panels_content.css ================================================================== --- gc_lang/fr/webext/content_scripts/panels_content.css +++ /dev/null @@ -1,121 +0,0 @@ -/* - CSS - Content panels for Grammalecte -*/ - -.grammalecte_panel { - padding: 0; - margin: 0; - position: fixed; - z-index: 100; - border: 2px solid hsl(210, 0%, 50%); - border-radius: 10px 10px 10px 10px; - background-color: hsl(210, 20%, 100%); - color: hsl(210, 10%, 4%); - font-family: "Trebuchet MS", "Liberation Sans", sans-serif; - box-shadow: 0 0 4px 2px hsl(210, 0%, 50%); -} - -.grammalecte_panel_bar { - position: sticky; - width: 100%; - background-color: hsl(210, 0%, 90%); - border-radius: 10px 10px 0 0; - border-bottom: 1px solid hsl(210, 10%, 80%); - font-size: 20px; -} -.grammalecte_panel_title { - padding: 10px 20px; -} -.grammalecte_panel_label { - display: inline-block; - padding: 0 10px; -} - -.grammalecte_panel_commands { - float: right; -} -.grammalecte_copy_button { - display: inline-block; - padding: 2px 10px; - background-color: hsl(150, 80%, 30%); - border-radius: 0 0 0 3px; - font-size: 22px; - font-weight: bold; - color: hsl(150, 0%, 100%); - text-align: center; - cursor: pointer; -} -.grammalecte_copy_button:hover { - background-color: hsl(150, 100%, 40%); -} -.grammalecte_move_button { - display: inline-block; - padding: 2px 5px; - background-color: hsl(180, 80%, 50%); - font-size: 22px; - font-weight: bold; - color: hsl(180, 0%, 100%); - text-align: center; - cursor: pointer; -} -.grammalecte_move_button:hover { - background-color: hsl(180, 100%, 60%); -} -.grammalecte_close_button { - display: inline-block; - padding: 2px 10px; - border-radius: 0 8px 0 0; - background-color: hsl(0, 80%, 50%); - font-size: 22px; - font-weight: bold; - color: hsl(210, 0%, 100%); - text-align: center; - cursor: pointer; -} -.grammalecte_close_button:hover { - background-color: hsl(0, 100%, 60%); -} - -.grammalecte_panel_content { - height: calc(100% - 55px); /* panel height - title_bar */ - overflow: auto; -} - - -/* - CSS Spinner - Double bounce - http://tobiasahlin.com/spinkit/ -*/ -.grammalecte_spinner { - visibility: hidden; - width: 40px; - height: 40px; - position: absolute; - top: 2px; - right: 180px; -} -.grammalecte_spinner .bounce1, -.grammalecte_spinner .bounce2 { - width: 100%; - height: 100%; - border-radius: 50%; - background-color: hsl(0, 50%, 75%); - opacity: 0.6; - position: absolute; - top: 0; - left: 0; - animation: grammalecte-sk-bounce 2.0s infinite ease-in-out; -} -.grammalecte_spinner .bounce2 { - animation-delay: -1.0s; -} - -@keyframes grammalecte-sk-bounce { - 0%, 100% { - transform: scale(0.0); - } 50% { - transform: scale(1.0); - } -} DELETED gc_lang/fr/webext/content_scripts/panels_content.js Index: gc_lang/fr/webext/content_scripts/panels_content.js ================================================================== --- gc_lang/fr/webext/content_scripts/panels_content.js +++ /dev/null @@ -1,147 +0,0 @@ -// JavaScript -// Panel creator - -"use strict"; - - -class GrammalectePanel { - - constructor (sId, sTitle, nWidth, nHeight, bFlexible=true) { - this.sId = sId; - this.nWidth = nWidth; - this.nHeight = nHeight; - this.bFlexible = bFlexible; - this.xPanelContent = createNode("div", {className: "grammalecte_panel_content"}); - this.xWaitIcon = this._createWaitIcon(); - this.xPanelNode = this._createPanel(sTitle); - this.center(); - } - - _createPanel (sTitle) { - try { - let xPanel = createNode("div", {id: this.sId, className: "grammalecte_panel"}); - let xBar = createNode("div", {className: "grammalecte_panel_bar"}); - xBar.appendChild(this._createButtons()); - let xTitle = createNode("div", {className: "grammalecte_panel_title"}); - xTitle.appendChild(this._createLogo()); - xTitle.appendChild(createNode("div", {className: "grammalecte_panel_label", textContent: sTitle})); - xBar.appendChild(xTitle); - xPanel.appendChild(xBar); - xPanel.appendChild(this.xPanelContent); - return xPanel; - } - catch (e) { - showError(e); - } - } - - _createLogo () { - let xImg = document.createElement("img"); - xImg.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAC8UlEQVQ4jX3TbUgTcRwH8P89ddu5u9tt082aZmpFEU4tFz0QGTUwCi0heniR9MSUIKRaD0RvIlKigsooo+iNFa0XJYuwIjEK19OcDtPElsG0ktyp591t7u7+vUh7MPX3+vf5/n8/+P0BmKJIPUUVlh2rdVVeesWlzEybqg+bFOsoylnqPmNavGFfknV2Omu2Lvja3vxAURKJib3opHizu8riLK6gjRyuKgmoSoMRFENRUqfXTzvBGK62LC2uoFkOl4RhjQ8+qWt7dPNE3sbdp+2LXbsGe9qb4rIo/BfwFy6nWQ4ThWGNDzbcfu29dMDh2nHU7CypYNLmzTda0/L5cNuzmDQi/A4Y27k6eQxLI79wS/11D0AAMNvs6XT6ojVJjJEgTbMy2BT77xBMp09KcpaWV1uc41jQoi0NdUHfjeOO9WWn7AVF7s7n986SithPJGeupBh2PCSP/xxqxAp3eq6wuUV7Wc6MSZIEhA8vHjbfOe/OcW3zmAuKy+nUzAyD2bow8ODaEROFq8AyZ5WBYdEZXGqGxZ61HJV+9HYCJRbTNA0QBA40HWunaKN5dKg/DBKxeCIe09Th/m4MJwiMSZmLEzMQAABQRuNqgu8NYX3doTcMpvCkLbtQZ2AJkrPOZG1zlnY13T+Hy9EehY90h57eqcorcZ/lctZuMzAsOjLEqwNv66/6vZcPYRBC+C3cGaBxhSet2av1BpYgTTY7k5y2JPT41slIR6Axv8R9nnOs+4Pf+2r992uOxGVJwgAAAEINfgt3BGgsESWtWas1iGDyl+CT/u7WpvxNFRc4x7qtBoZFhSFejb7z1fq9NYfjsiT+cwcQavBruCOgU4SIGo18amuoq3Js3FNlynVtH385+s53ze+t8cRkURx3yMTTRBAEQVAUXbFlf3XystJKA2NExeFBdWASDAAA+MQACCEEmqbJ0b6PMC7JwhDU8YFHV5u9NZ64LErT/oW/63tPV6uJwmKoOND78u7Fg5NhAAD4CVbzY9cwrWQrAAAAAElFTkSuQmCC"; - return xImg; - } - - _createButtons () { - let xButtonLine = createNode("div", {className: "grammalecte_panel_commands"}); - xButtonLine.appendChild(this.xWaitIcon); - if (this.sId === "grammalecte_gc_panel") { - xButtonLine.appendChild(this._createCopyButton()); - } - xButtonLine.appendChild(this._createMoveButton("stickToTop", "¯", "Coller en haut")); - xButtonLine.appendChild(this._createMoveButton("stickToLeft", "«", "Coller à gauche")); - xButtonLine.appendChild(this._createMoveButton("center", "•", "Centrer")); - xButtonLine.appendChild(this._createMoveButton("stickToRight", "»", "Coller à droite")); - xButtonLine.appendChild(this._createMoveButton("stickToBottom", "_", "Coller en bas")); - xButtonLine.appendChild(this._createCloseButton()); - return xButtonLine; - } - - _createWaitIcon () { - let xWaitIcon = createNode("div", {className: "grammalecte_spinner"}); - xWaitIcon.appendChild(createNode("div", {className: "bounce1"})); - xWaitIcon.appendChild(createNode("div", {className: "bounce2"})); - return xWaitIcon; - } - - _createCopyButton () { - let xButton = createNode("div", {id: "grammalecte_clipboard_button", className: "grammalecte_copy_button", textContent: "∑", title: "Copier dans le presse-papiers"}); - xButton.onclick = function () { this.copyTextToClipboard(); }.bind(this); - return xButton; - } - - _createMoveButton (sAction, sLabel, sTitle) { - let xButton = createNode("div", {className: "grammalecte_move_button", textContent: sLabel, title: sTitle}); - xButton.onclick = function () { this[sAction](); }.bind(this); - return xButton; - } - - _createCloseButton () { - let xButton = createNode("div", {className: "grammalecte_close_button", textContent: "×", title: "Fermer la fenêtre"}); - xButton.onclick = function () { this.hide(); }.bind(this); // better than writing “let that = this;” before the function? - return xButton; - } - - insertIntoPage () { - document.body.appendChild(this.xPanelNode); - } - - show () { - this.xPanelNode.style.display = "block"; - } - - hide () { - this.xPanelNode.style.display = "none"; - } - - center () { - let nHeight = (this.bFlexible) ? window.innerHeight-100 : this.nHeight; - this.xPanelNode.style = `top: 50%; left: 50%; width: ${this.nWidth}px; height: ${nHeight}px; margin-top: -${nHeight/2}px; margin-left: -${this.nWidth/2}px;`; - } - - stickToLeft () { - let nHeight = (this.bFlexible) ? window.innerHeight-100 : this.nHeight; - this.xPanelNode.style = `top: 50%; left: -2px; width: ${this.nWidth}px; height: ${nHeight}px; margin-top: -${nHeight/2}px;`; - } - - stickToRight () { - let nHeight = (this.bFlexible) ? window.innerHeight-100 : this.nHeight; - this.xPanelNode.style = `top: 50%; right: -2px; width: ${this.nWidth}px; height: ${nHeight}px; margin-top: -${nHeight/2}px;`; - } - - stickToTop () { - let nWidth = (this.bFlexible) ? Math.floor(window.innerWidth/2) : this.nWidth; - let nHeight = (this.bFlexible) ? Math.floor(window.innerHeight*0.45) : this.nHeight; - this.xPanelNode.style = `top: -2px; left: 50%; width: ${nWidth}px; height: ${nHeight}px; margin-left: -${nWidth/2}px;`; - } - - stickToBottom () { - let nWidth = (this.bFlexible) ? Math.floor(window.innerWidth/2) : this.nWidth; - let nHeight = (this.bFlexible) ? Math.floor(window.innerHeight*0.45) : this.nHeight; - this.xPanelNode.style = `bottom: -2px; left: 50%; width: ${nWidth}px; height: ${nHeight}px; margin-left: -${nWidth/2}px;`; - } - - reduce () { - // todo - } - - logInnerHTML () { - // for debugging - console.log(this.xPanelNode.innerHTML); - } - - startWaitIcon () { - this.xWaitIcon.style.visibility = "visible"; - } - - stopWaitIcon () { - this.xWaitIcon.style.visibility = "hidden"; - } - - openURL (sURL) { - xPort.postMessage({ - sCommand: "openURL", - dParam: {"sURL": sURL}, - dInfo: {} - }); - } -} DELETED gc_lang/fr/webext/content_scripts/tf_content.css Index: gc_lang/fr/webext/content_scripts/tf_content.css ================================================================== --- gc_lang/fr/webext/content_scripts/tf_content.css +++ /dev/null @@ -1,104 +0,0 @@ -/* - CSS for the Text Formatter -*/ - - -/* - Options -*/ -#grammalecte_tf_options { - display: flex; - padding: 10px; -} -.grammalecte_tf_column { - flex-grow: 1; - width: 360px; - padding: 0 5px; -} -#grammalecte_tf_options legend label { - font-size: 20px; - color: hsla(210, 20%, 50%, .8); - font-weight: bold; -} -#grammalecte_tf_options fieldset { - padding: 2px 10px 10px 13px; - margin-bottom: 5px; - background-color: hsl(210, 10%, 96%); - border-color: hsl(210, 20%, 80%); - border-radius: 3px; -} -#grammalecte_tf_options legend .option { - margin: 7px 5px 0 4px; - float: left; -} -#grammalecte_tf_options label { - font-size: 13px; -} -#grammalecte_tf_options .underline:hover { - background-color: hsl(210, 10%, 86%); - border-radius: 2px; -} -#grammalecte_tf_options .blockopt .option { - margin: 4px 5px 0 6px; - float: left; -} -#grammalecte_tf_options .grammalecte_tf_result { - float: right; - margin: 2px 3px 0 0; - font-size: 13px; -} -#grammalecte_tf_options .indent { - padding-left: 20px; -} -#grammalecte_tf_options .inlineblock { - display: inline-block; - margin-right: 10px; -} -#grammalecte_tf_options .rmg10 { - margin-right: 10px; -} - - - -/* - Actions -*/ -#grammalecte_tf_actions { - /*background-color: hsl(120, 10%, 92%);*/ - display: flex; - justify-content: space-between; - padding: 15px 15px 10px 15px; - border-top: 1px solid hsl(210, 10%, 90%); -} - -.grammalecte_button { - display: inline-block; - padding: 5px 10px; - width: 100px; - border-radius: 3px; - font-size: 16px; - font-weight: bold; - text-align: center; - cursor: pointer; -} - -#grammalecte_tf_reset { - background-color: hsl(210, 100%, 50%); - color: hsl(210, 0%, 100%); -} -#grammalecte_tf_progressbar { - width: 400px; -} -#grammalecte_tf_time_res { - width: 60px; - padding: 5px 10px; -} -#grammalecte_tf_apply { - background-color: hsl(120, 100%, 50%); - color: hsl(150, 0%, 100%); -} - -#grammalecte_progressbarbox { - display: inline-block; - padding: 10px 20px; -} DELETED gc_lang/fr/webext/content_scripts/tf_content.js Index: gc_lang/fr/webext/content_scripts/tf_content.js ================================================================== --- gc_lang/fr/webext/content_scripts/tf_content.js +++ /dev/null @@ -1,553 +0,0 @@ -// JavaScript -// Text formatter - -"use strict"; - - -class GrammalecteTextFormatter extends GrammalectePanel { - - constructor (...args) { - super(...args); - this.xTFNode = this._createTextFormatter(); - this.xPanelContent.appendChild(this.xTFNode); - this.xTextArea = null; - } - - _createTextFormatter () { - let xTFNode = document.createElement("div"); - try { - // Options - let xOptions = createNode("div", {id: "grammalecte_tf_options"}); - let xColumn1 = createNode("div", {className: "grammalecte_tf_column"}); - let xSSP = this._createFieldset("group_ssp", true, "Espaces surnuméraires"); - xSSP.appendChild(this._createSimpleOption("o_start_of_paragraph", true, "En début de paragraphe")); - xSSP.appendChild(this._createSimpleOption("o_end_of_paragraph", true, "En fin de paragraphe")); - xSSP.appendChild(this._createSimpleOption("o_between_words", true, "Entre les mots")); - xSSP.appendChild(this._createSimpleOption("o_before_punctuation", true, "Avant les points (.), les virgules (,)")); - xSSP.appendChild(this._createSimpleOption("o_within_parenthesis", true, "À l’intérieur des parenthèses")); - xSSP.appendChild(this._createSimpleOption("o_within_square_brackets", true, "À l’intérieur des crochets")); - xSSP.appendChild(this._createSimpleOption("o_within_quotation_marks", true, "À l’intérieur des guillemets “ et ”")); - let xSpace = this._createFieldset("group_space", true, "Espaces manquants"); - xSpace.appendChild(this._createSimpleOption("o_add_space_after_punctuation", true, "Après , ; : ? ! . …")); - xSpace.appendChild(this._createSimpleOption("o_add_space_around_hyphens", true, "Autour des tirets d’incise")); - let xNBSP = this._createFieldset("group_nbsp", true, "Espaces insécables"); - xNBSP.appendChild(this._createSimpleOption("o_nbsp_before_punctuation", true, "Avant : ; ? et !")); - xNBSP.appendChild(this._createSimpleOption("o_nbsp_within_quotation_marks", true, "Avec les guillemets « et »")); - xNBSP.appendChild(this._createSimpleOption("o_nbsp_before_symbol", true, "Avant % ‰ € $ £ ¥ ˚C")); - xNBSP.appendChild(this._createSimpleOption("o_nbsp_within_numbers", true, "À l’intérieur des nombres")); - xNBSP.appendChild(this._createSimpleOption("o_nbsp_before_units", true, "Avant les unités de mesure")); - let xDelete = this._createFieldset("group_delete", true, "Suppressions"); - xDelete.appendChild(this._createSimpleOption("o_erase_non_breaking_hyphens", true, "Tirets conditionnels")); - let xColumn2 = createNode("div", {className: "grammalecte_tf_column"}); - let xTypo = this._createFieldset("group_typo", true, "Signes typographiques"); - xTypo.appendChild(this._createSimpleOption("o_ts_apostrophe", true, "Apostrophe (’)")); - xTypo.appendChild(this._createSimpleOption("o_ts_ellipsis", true, "Points de suspension (…)")); - xTypo.appendChild(this._createSimpleOption("o_ts_dash_middle", true, "Tirets d’incise :")); - xTypo.appendChild(this._createRadioBoxHyphens("hyphen1", "o_ts_m_dash_middle", "o_ts_n_dash_middle", false)); - xTypo.appendChild(this._createSimpleOption("o_ts_dash_start", true, "Tirets en début de paragraphe :")); - xTypo.appendChild(this._createRadioBoxHyphens("hyphen2", "o_ts_m_dash_start", "o_ts_n_dash_start", true)); - xTypo.appendChild(this._createSimpleOption("o_ts_quotation_marks", true, "Modifier les guillemets droits (\" et ')")); - xTypo.appendChild(this._createSimpleOption("o_ts_units", true, "Points médians des unités (N·m, Ω·m…)")); - xTypo.appendChild(this._createSimpleOption("o_ts_spell", true, "Ligatures (cœur…) et diacritiques (ça, État…)")); - xTypo.appendChild(this._createRadioBoxLigatures()); - xTypo.appendChild(this._createLigaturesSelection()); - let xMisc = this._createFieldset("group_misc", true, "Divers"); - xMisc.appendChild(this._createOrdinalOptions()); - xMisc.appendChild(this._createSimpleOption("o_etc", true, "Et cætera, etc.")); - xMisc.appendChild(this._createSimpleOption("o_missing_hyphens", true, "Traits d’union manquants")); - xMisc.appendChild(this._createSimpleOption("o_ma_word", true, "Apostrophes manquantes")); - xMisc.appendChild(this._createSingleLetterOptions()); - let xStruct = this._createFieldset("group_struct", false, "Restructuration [!]"); - xStruct.appendChild(this._createSimpleOption("o_remove_hyphens_at_end_of_paragraphs", false, "Enlever césures en fin de ligne/paragraphe [!]")); - xStruct.appendChild(this._createSimpleOption("o_merge_contiguous_paragraphs", false, "Fusionner les paragraphes contigus [!]")); - xColumn1.appendChild(xSSP); - xColumn1.appendChild(xSpace); - xColumn1.appendChild(xNBSP); - xColumn1.appendChild(xDelete); - xColumn2.appendChild(xTypo); - xColumn2.appendChild(xMisc); - xColumn2.appendChild(xStruct); - xOptions.appendChild(xColumn1); - xOptions.appendChild(xColumn2); - // Actions - let xActions = createNode("div", {id: "grammalecte_tf_actions"}); - let xDefaultButton = createNode("div", {id: "grammalecte_tf_reset", textContent: "Par défaut", className: "grammalecte_button", style: "background-color: hsl(210, 50%, 50%)"}); - xDefaultButton.addEventListener("click", () => { this.reset(); }); - let xApplyButton = createNode("div", {id: "grammalecte_tf_apply", textContent: "Appliquer", className: "grammalecte_button", style: "background-color: hsl(180, 50%, 50%)"}); - xApplyButton.addEventListener("click", () => { this.saveOptions(); this.apply(); }); - xActions.appendChild(xDefaultButton); - xActions.appendChild(createNode("progress", {id: "grammalecte_tf_progressbar"})); - xActions.appendChild(createNode("span", {id: "grammalecte_tf_time_res", textContent: "…"})); - xActions.appendChild(xApplyButton); - //xActions.appendChild(createNode("div", {id: "grammalecte_infomsg", textContent: "blabla"})); - // create result - xTFNode.appendChild(xOptions); - xTFNode.appendChild(xActions); - } - catch (e) { - showError(e); - } - return xTFNode; - } - - // Common options - _createFieldset (sId, bDefault, sLabel) { - let xFieldset = createNode("fieldset", {id: sId, className: "groupblock"}); - let xLegend = document.createElement("legend"); - let xGroupOption = createNode("input", {type: "checkbox", id: "o_"+sId, className: "option"}, {default: bDefault}); - xGroupOption.addEventListener("click", (xEvent) => { this.switchGroup(xEvent.target.id); }); - xLegend.appendChild(xGroupOption); - xLegend.appendChild(createNode("label", {htmlFor: "o_"+sId, textContent: sLabel})); - xFieldset.appendChild(xLegend); - return xFieldset; - } - - _createSimpleOption (sId, bDefault, sLabel) { - let xLine = createNode("div", {className: "blockopt underline"}); - xLine.appendChild(createNode("input", {type: "checkbox", id: sId, className: "option"}, {default: bDefault})); - xLine.appendChild(createNode("label", {htmlFor: sId, textContent: sLabel, className: "opt_lbl largew"})); - xLine.appendChild(createNode("div", {id: "res_"+sId, className: "grammalecte_tf_result", textContent: "·"})); - return xLine; - } - - // Hyphens - _createRadioBoxHyphens (sName, sIdEmDash, sIdEnDash, bDefaultEmDash) { - let xLine = createNode("div", {className: "blockopt indent"}); - xLine.appendChild(this._createInlineRadioOption(sName, sIdEmDash, "cadratin (—)", bDefaultEmDash)); - xLine.appendChild(this._createInlineRadioOption(sName, sIdEnDash, "demi-cadratin (—)", !bDefaultEmDash)); - return xLine; - } - - // Ligatures - _createRadioBoxLigatures () { - let xLine = createNode("div", {className: "blockopt underline"}); - xLine.appendChild(createNode("div", {id: "res_"+"o_ts_ligature", className: "grammalecte_tf_result", textContent: "·"})); - xLine.appendChild(this._createInlineCheckboxOption("o_ts_ligature", "Ligatures", true)); - xLine.appendChild(this._createInlineRadioOption("liga", "o_ts_ligature_do", "faire", false)); - xLine.appendChild(this._createInlineRadioOption("liga", "o_ts_ligature_undo", "défaire", true)); - return xLine; - } - - _createLigaturesSelection () { - let xLine = createNode("div", {className: "blockopt indent"}); - xLine.appendChild(this._createInlineCheckboxOption("o_ts_ligature_ff", "ff", true)); - xLine.appendChild(this._createInlineCheckboxOption("o_ts_ligature_fi", "fi", true)); - xLine.appendChild(this._createInlineCheckboxOption("o_ts_ligature_ffi", "ffi", true)); - xLine.appendChild(this._createInlineCheckboxOption("o_ts_ligature_fl", "fl", true)); - xLine.appendChild(this._createInlineCheckboxOption("o_ts_ligature_ffl", "ffl", true)); - xLine.appendChild(this._createInlineCheckboxOption("o_ts_ligature_ft", "ft", true)); - xLine.appendChild(this._createInlineCheckboxOption("o_ts_ligature_st", "st", false)); - return xLine; - } - - // Apostrophes - _createSingleLetterOptions () { - let xLine = createNode("div", {className: "blockopt indent"}); - xLine.appendChild(this._createInlineCheckboxOption("o_ma_1letter_lowercase", "lettres isolées (j’ n’ m’ t’ s’ c’ d’ l’)", false)); - xLine.appendChild(this._createInlineCheckboxOption("o_ma_1letter_uppercase", "Maj.", false)); - return xLine; - } - - // Ordinals - _createOrdinalOptions () { - let xLine = createNode("div", {className: "blockopt underline"}); - xLine.appendChild(createNode("div", {id: "res_"+"o_ordinals_no_exponant", className: "grammalecte_tf_result", textContent: "·"})); - xLine.appendChild(this._createInlineCheckboxOption("o_ordinals_no_exponant", "Ordinaux (15e, XXIe…)", true)); - xLine.appendChild(this._createInlineCheckboxOption("o_ordinals_exponant", "e → ᵉ", true)); - return xLine; - } - - - // Inline option block - _createInlineCheckboxOption (sId, sLabel, bDefault) { - let xInlineBlock = createNode("div", {className: "inlineblock"}); - xInlineBlock.appendChild(createNode("input", {type: "checkbox", id: sId, className: "option"}, {default: bDefault})); - xInlineBlock.appendChild(createNode("label", {htmlFor: sId, textContent: sLabel, className: "opt_lbl"})); - return xInlineBlock; - } - - _createInlineRadioOption (sName, sId, sLabel, bDefault) { - let xInlineBlock = createNode("div", {className: "inlineblock"}); - xInlineBlock.appendChild(createNode("input", {type: "radio", id: sId, name: sName, className:"option"}, {default: bDefault})); - xInlineBlock.appendChild(createNode("label", {htmlFor: sId, className: "opt_lbl", textContent: sLabel})); - return xInlineBlock; - } - - - /* - Actions - */ - start (xTextArea) { - this.xTextArea = xTextArea; - let xPromise = browser.storage.local.get("tf_options"); - xPromise.then(this.setOptions.bind(this), this.reset.bind(this)); - } - - switchGroup (sOptName) { - if (document.getElementById(sOptName).checked) { - document.getElementById(sOptName.slice(2)).style.opacity = 1; - } else { - document.getElementById(sOptName.slice(2)).style.opacity = 0.3; - } - this.resetProgressBar(); - } - - reset () { - this.resetProgressBar(); - for (let xNode of document.getElementsByClassName("option")) { - xNode.checked = (xNode.dataset.default === "true"); - if (xNode.id.startsWith("o_group_")) { - this.switchGroup(xNode.id); - } - } - } - - resetProgressBar () { - document.getElementById('grammalecte_tf_progressbar').value = 0; - document.getElementById('grammalecte_tf_time_res').textContent = ""; - } - - setOptions (oOptions) { - if (oOptions.hasOwnProperty("tf_options")) { - oOptions = oOptions.tf_options; - } - for (let xNode of document.getElementsByClassName("option")) { - //console.log(xNode.id + " > " + oOptions.hasOwnProperty(xNode.id) + ": " + oOptions[xNode.id] + " [" + xNode.dataset.default + "]"); - xNode.checked = (oOptions.hasOwnProperty(xNode.id)) ? oOptions[xNode.id] : (xNode.dataset.default === "true"); - if (document.getElementById("res_"+xNode.id) !== null) { - document.getElementById("res_"+xNode.id).textContent = ""; - } - if (xNode.id.startsWith("o_group_")) { - this.switchGroup(xNode.id); - } - } - } - - saveOptions () { - let oOptions = {}; - for (let xNode of document.getElementsByClassName("option")) { - oOptions[xNode.id] = xNode.checked; - //console.log(xNode.id + ": " + xNode.checked); - } - browser.storage.local.set({"tf_options": oOptions}); - } - - apply () { - try { - const t0 = Date.now(); - //window.setCursor("wait"); // change pointer - this.resetProgressBar(); - let sText = this.xTextArea.value; - document.getElementById('grammalecte_tf_progressbar').max = 7; - let n1 = 0, n2 = 0, n3 = 0, n4 = 0, n5 = 0, n6 = 0, n7 = 0; - - // Restructuration - if (document.getElementById("o_group_struct").checked) { - if (document.getElementById("o_remove_hyphens_at_end_of_paragraphs").checked) { - [sText, n1] = this.removeHyphenAtEndOfParagraphs(sText); - document.getElementById('res_o_remove_hyphens_at_end_of_paragraphs').textContent = n1; - } - if (document.getElementById("o_merge_contiguous_paragraphs").checked) { - [sText, n1] = this.mergeContiguousParagraphs(sText); - document.getElementById('res_o_merge_contiguous_paragraphs').textContent = n1; - } - document.getElementById("o_group_struct").checked = false; - this.switchGroup("o_group_struct"); - } - document.getElementById('grammalecte_tf_progressbar').value = 1; - - // espaces surnuméraires - if (document.getElementById("o_group_ssp").checked) { - if (document.getElementById("o_end_of_paragraph").checked) { - [sText, n1] = this.formatText(sText, "end_of_paragraph"); - document.getElementById('res_o_end_of_paragraph').textContent = n1; - } - if (document.getElementById("o_between_words").checked) { - [sText, n1] = this.formatText(sText, "between_words"); - document.getElementById('res_o_between_words').textContent = n1; - } - if (document.getElementById("o_start_of_paragraph").checked) { - [sText, n1] = this.formatText(sText, "start_of_paragraph"); - document.getElementById('res_o_start_of_paragraph').textContent = n1; - } - if (document.getElementById("o_before_punctuation").checked) { - [sText, n1] = this.formatText(sText, "before_punctuation"); - document.getElementById('res_o_before_punctuation').textContent = n1; - } - if (document.getElementById("o_within_parenthesis").checked) { - [sText, n1] = this.formatText(sText, "within_parenthesis"); - document.getElementById('res_o_within_parenthesis').textContent = n1; - } - if (document.getElementById("o_within_square_brackets").checked) { - [sText, n1] = this.formatText(sText, "within_square_brackets"); - document.getElementById('res_o_within_square_brackets').textContent = n1; - } - if (document.getElementById("o_within_quotation_marks").checked) { - [sText, n1] = this.formatText(sText, "within_quotation_marks"); - document.getElementById('res_o_within_quotation_marks').textContent = n1; - } - document.getElementById("o_group_ssp").checked = false; - this.switchGroup("o_group_ssp"); - } - document.getElementById('grammalecte_tf_progressbar').value = 2; - - // espaces typographiques - if (document.getElementById("o_group_nbsp").checked) { - if (document.getElementById("o_nbsp_before_punctuation").checked) { - [sText, n1] = this.formatText(sText, "nbsp_before_punctuation"); - [sText, n2] = this.formatText(sText, "nbsp_repair"); - document.getElementById('res_o_nbsp_before_punctuation').textContent = n1 - n2; - } - if (document.getElementById("o_nbsp_within_quotation_marks").checked) { - [sText, n1] = this.formatText(sText, "nbsp_within_quotation_marks"); - document.getElementById('res_o_nbsp_within_quotation_marks').textContent = n1; - } - if (document.getElementById("o_nbsp_before_symbol").checked) { - [sText, n1] = this.formatText(sText, "nbsp_before_symbol"); - document.getElementById('res_o_nbsp_before_symbol').textContent = n1; - } - if (document.getElementById("o_nbsp_within_numbers").checked) { - [sText, n1] = this.formatText(sText, "nbsp_within_numbers"); - document.getElementById('res_o_nbsp_within_numbers').textContent = n1; - } - if (document.getElementById("o_nbsp_before_units").checked) { - [sText, n1] = this.formatText(sText, "nbsp_before_units"); - document.getElementById('res_o_nbsp_before_units').textContent = n1; - } - document.getElementById("o_group_nbsp").checked = false; - this.switchGroup("o_group_nbsp"); - } - document.getElementById('grammalecte_tf_progressbar').value = 3; - - // espaces manquants - if (document.getElementById("o_group_typo").checked) { - if (document.getElementById("o_ts_units").checked) { - [sText, n1] = this.formatText(sText, "ts_units"); - document.getElementById('res_o_ts_units').textContent = n1; - } - } - if (document.getElementById("o_group_space").checked) { - if (document.getElementById("o_add_space_after_punctuation").checked) { - [sText, n1] = this.formatText(sText, "add_space_after_punctuation"); - [sText, n2] = this.formatText(sText, "add_space_repair"); - document.getElementById('res_o_add_space_after_punctuation').textContent = n1 - n2; - } - if (document.getElementById("o_add_space_around_hyphens").checked) { - [sText, n1] = this.formatText(sText, "add_space_around_hyphens"); - document.getElementById('res_o_add_space_around_hyphens').textContent = n1; - } - document.getElementById("o_group_space").checked = false; - this.switchGroup("o_group_space"); - } - document.getElementById('grammalecte_tf_progressbar').value = 4; - - // suppression - if (document.getElementById("o_group_delete").checked) { - if (document.getElementById("o_erase_non_breaking_hyphens").checked) { - [sText, n1] = this.formatText(sText, "erase_non_breaking_hyphens"); - document.getElementById('res_o_erase_non_breaking_hyphens').textContent = n1; - } - document.getElementById("o_group_delete").checked = false; - this.switchGroup("o_group_delete"); - } - document.getElementById('grammalecte_tf_progressbar').value = 5; - - // signes typographiques - if (document.getElementById("o_group_typo").checked) { - if (document.getElementById("o_ts_apostrophe").checked) { - [sText, n1] = this.formatText(sText, "ts_apostrophe"); - document.getElementById('res_o_ts_apostrophe').textContent = n1; - } - if (document.getElementById("o_ts_ellipsis").checked) { - [sText, n1] = this.formatText(sText, "ts_ellipsis"); - document.getElementById('res_o_ts_ellipsis').textContent = n1; - } - if (document.getElementById("o_ts_dash_start").checked) { - if (document.getElementById("o_ts_m_dash_start").checked) { - [sText, n1] = this.formatText(sText, "ts_m_dash_start"); - } else { - [sText, n1] = this.formatText(sText, "ts_n_dash_start"); - } - document.getElementById('res_o_ts_dash_start').textContent = n1; - } - if (document.getElementById("o_ts_dash_middle").checked) { - if (document.getElementById("o_ts_m_dash_middle").checked) { - [sText, n1] = this.formatText(sText, "ts_m_dash_middle"); - } else { - [sText, n1] = this.formatText(sText, "ts_n_dash_middle"); - } - document.getElementById('res_o_ts_dash_middle').textContent = n1; - } - if (document.getElementById("o_ts_quotation_marks").checked) { - [sText, n1] = this.formatText(sText, "ts_quotation_marks"); - document.getElementById('res_o_ts_quotation_marks').textContent = n1; - } - if (document.getElementById("o_ts_spell").checked) { - [sText, n1] = this.formatText(sText, "ts_spell"); - document.getElementById('res_o_ts_spell').textContent = n1; - } - if (document.getElementById("o_ts_ligature").checked) { - // ligatures typographiques : fi, fl, ff, ffi, ffl, ft, st - if (document.getElementById("o_ts_ligature_do").checked) { - if (document.getElementById("o_ts_ligature_ffi").checked) { - [sText, n1] = this.formatText(sText, "ts_ligature_ffi_do"); - } - if (document.getElementById("o_ts_ligature_ffl").checked) { - [sText, n2] = this.formatText(sText, "ts_ligature_ffl_do"); - } - if (document.getElementById("o_ts_ligature_fi").checked) { - [sText, n3] = this.formatText(sText, "ts_ligature_fi_do"); - } - if (document.getElementById("o_ts_ligature_fl").checked) { - [sText, n4] = this.formatText(sText, "ts_ligature_fl_do"); - } - if (document.getElementById("o_ts_ligature_ff").checked) { - [sText, n5] = this.formatText(sText, "ts_ligature_ff_do"); - } - if (document.getElementById("o_ts_ligature_ft").checked) { - [sText, n6] = this.formatText(sText, "ts_ligature_ft_do"); - } - if (document.getElementById("o_ts_ligature_st").checked) { - [sText, n7] = this.formatText(sText, "ts_ligature_st_do"); - } - } - if (document.getElementById("o_ts_ligature_undo").checked) { - if (document.getElementById("o_ts_ligature_ffi").checked) { - [sText, n1] = this.formatText(sText, "ts_ligature_ffi_undo"); - } - if (document.getElementById("o_ts_ligature_ffl").checked) { - [sText, n2] = this.formatText(sText, "ts_ligature_ffl_undo"); - } - if (document.getElementById("o_ts_ligature_fi").checked) { - [sText, n3] = this.formatText(sText, "ts_ligature_fi_undo"); - } - if (document.getElementById("o_ts_ligature_fl").checked) { - [sText, n4] = this.formatText(sText, "ts_ligature_fl_undo"); - } - if (document.getElementById("o_ts_ligature_ff").checked) { - [sText, n5] = this.formatText(sText, "ts_ligature_ff_undo"); - } - if (document.getElementById("o_ts_ligature_ft").checked) { - [sText, n6] = this.formatText(sText, "ts_ligature_ft_undo"); - } - if (document.getElementById("o_ts_ligature_st").checked) { - [sText, n7] = this.formatText(sText, "ts_ligature_st_undo"); - } - } - document.getElementById('res_o_ts_ligature').textContent = n1 + n2 + n3 + n4 + n5 + n6 + n7; - } - document.getElementById("o_group_typo").checked = false; - this.switchGroup("o_group_typo"); - } - document.getElementById('grammalecte_tf_progressbar').value = 6; - - // divers - if (document.getElementById("o_group_misc").checked) { - if (document.getElementById("o_ordinals_no_exponant").checked) { - if (document.getElementById("o_ordinals_exponant").checked) { - [sText, n1] = this.formatText(sText, "ordinals_exponant"); - } else { - [sText, n1] = this.formatText(sText, "ordinals_no_exponant"); - } - document.getElementById('res_o_ordinals_no_exponant').textContent = n1; - } - if (document.getElementById("o_etc").checked) { - [sText, n1] = this.formatText(sText, "etc"); - document.getElementById('res_o_etc').textContent = n1; - } - if (document.getElementById("o_missing_hyphens").checked) { - [sText, n1] = this.formatText(sText, "missing_hyphens"); - document.getElementById('res_o_missing_hyphens').textContent = n1; - } - if (document.getElementById("o_ma_word").checked) { - [sText, n1] = this.formatText(sText, "ma_word"); - if (document.getElementById("o_ma_1letter_lowercase").checked) { - [sText, n1] = this.formatText(sText, "ma_1letter_lowercase"); - if (document.getElementById("o_ma_1letter_uppercase").checked) { - [sText, n1] = this.formatText(sText, "ma_1letter_uppercase"); - } - } - document.getElementById('res_o_ma_word').textContent = n1; - } - document.getElementById("o_group_misc").checked = false; - this.switchGroup("o_group_misc"); - } - document.getElementById('grammalecte_tf_progressbar').value = document.getElementById('grammalecte_tf_progressbar').max; - // end of processing - - //window.setCursor("auto"); // restore pointer - - const t1 = Date.now(); - document.getElementById('grammalecte_tf_time_res').textContent = this.getTimeRes((t1-t0)/1000); - this.xTextArea.value = sText; - } - catch (e) { - showError(e); - } - } - - formatText (sText, sOptName) { - let nCount = 0; - try { - if (!oReplTable.hasOwnProperty(sOptName)) { - console.log("# Error. TF: there is no option “" + sOptName+ "”."); - return [sText, nCount]; - } - for (let [zRgx, sRep] of oReplTable[sOptName]) { - nCount += (sText.match(zRgx) || []).length; - sText = sText.replace(zRgx, sRep); - } - } - catch (e) { - showError(e); - } - return [sText, nCount]; - } - - removeHyphenAtEndOfParagraphs (sText) { - let nCount = (sText.match(/-[  ]*\n/gm) || []).length; - sText = sText.replace(/-[  ]*\n/gm, ""); - return [sText, nCount]; - } - - mergeContiguousParagraphs (sText) { - let nCount = 0; - sText = sText.replace(/^[  ]+$/gm, ""); // clear empty paragraphs - let s = ""; - for (let sParagraph of this.getParagraph(sText)) { - if (sParagraph === "") { - s += "\n"; - } else { - s += sParagraph + " "; - nCount += 1; - } - } - s = s.replace(/ +/gm, " ").replace(/ $/gm, ""); - return [s, nCount]; - } - - * getParagraph (sText) { - // generator: returns paragraphs of text - let iStart = 0; - let iEnd = 0; - while ((iEnd = sText.indexOf("\n", iStart)) !== -1) { - yield sText.slice(iStart, iEnd); - iStart = iEnd + 1; - } - yield sText.slice(iStart); - } - - getTimeRes (n) { - // returns duration in seconds as string - if (n < 10) { - return n.toFixed(3).toString() + " s"; - } - if (n < 100) { - return n.toFixed(2).toString() + " s"; - } - if (n < 1000) { - return n.toFixed(1).toString() + " s"; - } - return n.toFixed().toString() + " s"; - } -} Index: gc_lang/fr/webext/manifest.json ================================================================== --- gc_lang/fr/webext/manifest.json +++ gc_lang/fr/webext/manifest.json @@ -38,23 +38,23 @@ }, "content_scripts": [ { "matches": [""], "css": [ - "content_scripts/panels_content.css", - "content_scripts/tf_content.css", - "content_scripts/gc_content.css", - "content_scripts/lxg_content.css", + "content_scripts/panel.css", + "content_scripts/panel_tf.css", + "content_scripts/panel_gc.css", + "content_scripts/panel_lxg.css", "content_scripts/wrapper.css", "3rd/font-awesome-4.7.0/css/font-awesome.min.css" ], "js": [ - "content_scripts/panels_content.js", + "content_scripts/panel.js", "grammalecte/fr/textformatter.js", - "content_scripts/tf_content.js", - "content_scripts/gc_content.js", - "content_scripts/lxg_content.js", + "content_scripts/panel_tf.js", + "content_scripts/panel_gc.js", + "content_scripts/panel_lxg.js", "content_scripts/wrapper.js", "content_scripts/init.js" ] } ],