Index: gc_lang/fr/webext/content_scripts/modify_page.js ================================================================== --- gc_lang/fr/webext/content_scripts/modify_page.js +++ gc_lang/fr/webext/content_scripts/modify_page.js @@ -81,11 +81,11 @@ xToolbar.appendChild(xTFButton); let xLxgButton = document.createElement("div"); xLxgButton.textContent = "Analyser"; xLxgButton.style = sButtonStyle; xLxgButton.onclick = function() { - console.log("Analyser"); + createLxgPanel(xTextArea); }; xToolbar.appendChild(xLxgButton); let xGCButton = document.createElement("div"); xGCButton.textContent = "Corriger"; xGCButton.style = sButtonStyle; @@ -104,68 +104,50 @@ console.log("Conjugueur"); if (xConjPanel !== null) { xConjPanel.style.display = "block"; } else { // create the panel - xConjPanel = document.createElement("div"); - xConjPanel.style = "position: fixed; left: 50%; top: 50%; z-index: 100; height: 400px; margin-top: -200px; width: 600px; margin-left: -300px; border-radius: 10px;" - + " color: hsl(210, 10%, 4%); background-color: hsl(210, 20%, 90%); border: 10px solid hsla(210, 20%, 70%, .5);"; - xConjPanel.textContent = "Conjugueur"; - xConjPanel.setAttribute("draggable", true); - xConjPanel.appendChild(createCloseButton(xConjPanel)); + xConjPanel = createPanelFrame("conj_panel", "Conjugueur", 500, 900); document.body.appendChild(xConjPanel); } } function createTFPanel (xTextArea) { console.log("Formateur de texte"); + if (xTFPanel !== null) { + xTFPanel.style.display = "block"; + } else { + // create the panel + xTFPanel = createPanelFrame("tf_panel", "Formateur de texte", 800, 500); + xTFPanel.appendChild(createTextFormatter(xTextArea)); + document.body.appendChild(xTFPanel); + } } function createLxgPanel (xTextArea) { - console.log("Analyse"); + console.log("Lexicographe"); + if (xLxgPanel !== null) { + xLxgPanel.style.display = "block"; + } else { + // create the panel + xLxgPanel = createPanelFrame("lxg_panel", "Lexicographe", 400, 800); + document.body.appendChild(xLxgPanel); + } } function createGCPanel (oErrors) { console.log("Correction grammaticale"); if (xGCPanel !== null) { xGCPanel.style.display = "block"; } else { // create the panel - xGCPanel = document.createElement("div"); - xGCPanel.style = "position: fixed; left: 50%; top: 50%; z-index: 100; height: 400px; margin-top: -200px; width: 600px; margin-left: -300px; border-radius: 10px;" - + " color: hsl(210, 10%, 4%); background-color: hsl(210, 20%, 90%); border: 10px solid hsla(210, 20%, 70%, .5);"; - xGCPanel.textContent = JSON.stringify(oErrors); - xGCPanel.setAttribute("draggable", true); - xGCPanel.appendChild(createCloseButton(xGCPanel)); + xGCPanel = createPanelFrame("gc_panel", "Correcteur", 400, 800); + xGCPanel.appendChild(document.createTextNode(JSON.stringify(oErrors))); document.body.appendChild(xGCPanel); } } -function createCloseButton (xParentNode) { - let xButton = document.createElement("div"); - xButton.style = "float: right; width: 20px; padding: 5px 10px; color: hsl(210, 0%, 100%); text-align: center;" - + "font-size: 20px; font-weight: bold; background-color: hsl(0, 80%, 50%); border-radius: 0 0 0 3px; cursor: pointer;"; - xButton.textContent = "×"; - xButton.onclick = function () { - xParentNode.style.display = "none"; - } - return xButton; -} - -function loadImage (sContainerClass, sImagePath) { - let xRequest = new XMLHttpRequest(); - xRequest.open('GET', browser.extension.getURL("")+sImagePath, false); - xRequest.responseType = "arraybuffer"; - xRequest.send(); - let blobTxt = new Blob([xRequest.response], {type: 'image/png'}); - let img = document.createElement('img'); - img.src = (URL || webkitURL).createObjectURL(blobTxt); - Array.filter(document.getElementsByClassName(sContainerClass), function (oElem) { - oElem.appendChild(img); - }); -} - /* Simple message */ function handleMessage (oMessage, xSender, sendResponse) { ADDED gc_lang/fr/webext/content_scripts/panel_creator.js Index: gc_lang/fr/webext/content_scripts/panel_creator.js ================================================================== --- /dev/null +++ gc_lang/fr/webext/content_scripts/panel_creator.js @@ -0,0 +1,83 @@ +// JavaScript +// Panel creator + +"use strict"; + + +function createPanelFrame (sId, sTitle, nWidth, nHeight) { + try { + let xPanel = document.createElement("div"); + xPanel.style = "position: fixed; left: 50%; top: 50%; z-index: 100; border-radius: 10px;" + + "color: hsl(210, 10%, 4%); background-color: hsl(210, 20%, 90%); border: 10px solid hsla(210, 20%, 70%, .5); overflow: auto;" + + getPanelSize(nWidth, nHeight); + let xBar = document.createElement("div"); + xBar.style = "position: fixed; width: "+nWidth+"px ; background-color: hsl(210, 0%, 100%); border-bottom: 1px solid hsl(210, 10%, 50%); font-size: 20px;"; + xBar.appendChild(createCloseButton(xPanel)); + xBar.appendChild(createDiv(sId+"_title", "Grammalecte · " + sTitle)); + xPanel.appendChild(xBar); + xPanel.appendChild(createDiv(sId+"_empty_space", "", "", "height: 40px;")); // empty space to fill behind the title bar + return xPanel; + } + catch (e) { + showError(e); + } +} + +function getPanelSize (nWidth, nHeight) { + let s = "width: "+ nWidth.toString() + "px; height: " + nHeight.toString() + "px;"; + s += "margin-top: -" + (nHeight/2).toString() + "px; margin-left: -" + (nWidth/2).toString() + "px;"; + return s; +} + +function createCloseButton (xParentNode) { + let xButton = document.createElement("div"); + xButton.style = "float: right; padding: 2px 10px; color: hsl(210, 0%, 100%); text-align: center;" + + "font-size: 22px; font-weight: bold; background-color: hsl(0, 80%, 50%); border-radius: 0 0 0 3px; cursor: pointer;"; + xButton.textContent = "×"; + xButton.onclick = function () { + xParentNode.style.display = "none"; + } + return xButton; +} + + +/* + Common functions +*/ +function createDiv (sId, sContent, sClass="", sStyle="") { + let xDiv = document.createElement("div"); + xDiv.id = sId; + xDiv.className = sClass; + xDiv.style = sStyle; + xDiv.textContent = sContent; + return xDiv; +} + +function createCheckbox (sId, bDefault, sClass="") { + let xInput = document.createElement("input"); + xInput.type = "checkbox"; + xInput.id = sId; + xInput.className = sClass; + xInput.dataset.default = bDefault; + return xInput; +} + +function createLabel (sForId, sLabel, sClass="") { + let xLabel = document.createElement("label"); + xLabel.setAttribute("for", sForId); + xLabel.textContent = sLabel; + return xLabel; +} + +function loadImage (sContainerClass, sImagePath) { + let xRequest = new XMLHttpRequest(); + xRequest.open('GET', browser.extension.getURL("")+sImagePath, false); + xRequest.responseType = "arraybuffer"; + xRequest.send(); + let blobTxt = new Blob([xRequest.response], {type: 'image/png'}); + let img = document.createElement('img'); + img.src = (URL || webkitURL).createObjectURL(blobTxt); + Array.filter(document.getElementsByClassName(sContainerClass), function (oElem) { + oElem.appendChild(img); + }); +} ADDED gc_lang/fr/webext/content_scripts/text_formatter.js Index: gc_lang/fr/webext/content_scripts/text_formatter.js ================================================================== --- /dev/null +++ gc_lang/fr/webext/content_scripts/text_formatter.js @@ -0,0 +1,356 @@ +// JavaScript +// Text formatter + +"use strict"; + +function createTextFormatter (xTextArea) { + let xTFNode = document.createElement("div"); + try { + // Options + let xOptions = createDiv("tf_options", ""); + let xSSP = createFieldset("group_ssp", true, "Espaces surnuméraires"); + xSSP.appendChild(createOptionInputAndLabel("o_start_of_paragraph", true, "En début de paragraphe")); + xSSP.appendChild(createOptionInputAndLabel("o_end_of_paragraph", true, "En fin de paragraphe")); + xSSP.appendChild(createOptionInputAndLabel("o_between_words", true, "Entre les mots")); + xSSP.appendChild(createOptionInputAndLabel("o_before_punctuation", true, "Avant les points (.), les virgules (,)")); + xSSP.appendChild(createOptionInputAndLabel("o_within_parenthesis", true, "À l’intérieur des parenthèses")); + xSSP.appendChild(createOptionInputAndLabel("o_within_square_brackets", true, "À l’intérieur des crochets")); + xSSP.appendChild(createOptionInputAndLabel("o_within_quotation_marks", true, "À l’intérieur des guillemets “ et ”")); + let xSpace = createFieldset("group_space", true, "Espaces manquants"); + xSpace.appendChild(createOptionInputAndLabel("o_add_space_after_punctuation", true, "Après , ; : ? ! . …")); + xSpace.appendChild(createOptionInputAndLabel("o_add_space_around_hyphens", true, "Autour des tirets d’incise")); + let xNBSP = createFieldset("group_nbsp", true, "Espaces insécables"); + xNBSP.appendChild(createOptionInputAndLabel("o_nbsp_before_punctuation", true, "Avant : ; ? et !")); + xNBSP.appendChild(createOptionInputAndLabel("o_nbsp_within_quotation_marks", true, "Avec les guillemets « et »")); + xNBSP.appendChild(createOptionInputAndLabel("o_nbsp_before_symbol", true, "Avant % ‰ € $ £ ¥ ˚C")); + xNBSP.appendChild(createOptionInputAndLabel("o_nbsp_within_numbers", true, "À l’intérieur des nombres")); + xNBSP.appendChild(createOptionInputAndLabel("o_nbsp_before_units", true, "Avant les unités de mesure")); + let xDelete = createFieldset("group_delete", true, "Suppressions"); + xDelete.appendChild(createOptionInputAndLabel("o_erase_non_breaking_hyphens", true, "Tirets conditionnels")); + let xTypo = createFieldset("group_typo", true, "Signes typographiques"); + xTypo.appendChild(createOptionInputAndLabel("o_ts_apostrophe", true, "Apostrophe (’)")); + xTypo.appendChild(createOptionInputAndLabel("o_ts_ellipsis", true, "Points de suspension (…)")); + xTypo.appendChild(createOptionInputAndLabel("o_ts_dash_middle", true, "Tirets d’incise :")); + xTypo.appendChild(createOptionInputAndLabel("o_ts_dash_start", true, "Tirets en début de paragraphe :")); + xTypo.appendChild(createOptionInputAndLabel("o_ts_quotation_marks", true, "Modifier les guillemets droits (\" et ')")); + xTypo.appendChild(createOptionInputAndLabel("o_ts_units", true, "Points médians des unités (N·m, Ω·m…)")); + xTypo.appendChild(createOptionInputAndLabel("o_ts_spell", true, "Ligatures (cœur…) et diacritiques (ça, État…)")); + xTypo.appendChild(createOptionInputAndLabel("o_ts_ligature", true, "Ligatures")); + let xMisc = createFieldset("group_misc", true, "Divers"); + xMisc.appendChild(createOptionInputAndLabel("o_ordinals_no_exponant", true, "Ordinaux (15e, XXIe…)")); + xMisc.appendChild(createOptionInputAndLabel("o_etc", true, "Et cætera, etc.")); + xMisc.appendChild(createOptionInputAndLabel("o_missing_hyphens", true, "Traits d’union manquants")); + xMisc.appendChild(createOptionInputAndLabel("o_ma_word", true, "Apostrophes manquantes")); + let xStruct = createFieldset("group_struct", false, "Restructuration [!]"); + xStruct.appendChild(createOptionInputAndLabel("o_remove_hyphens_at_end_of_paragraphs", false, "Enlever césures en fin de ligne/paragraphe [!]")); + xStruct.appendChild(createOptionInputAndLabel("o_merge_contiguous_paragraphs", false, "Fusionner les paragraphes contigus [!]")); + xOptions.appendChild(xSSP); + xOptions.appendChild(xSpace); + xOptions.appendChild(xNBSP); + xOptions.appendChild(xDelete); + xOptions.appendChild(xTypo); + xOptions.appendChild(xMisc); + xOptions.appendChild(xStruct); + // Actions + let xActions = createDiv("tf_actions", ""); + let xPgBarBox = createDiv("tf_progressbarbox", ""); + xPgBarBox.innerHTML = ' '; + xActions.appendChild(createDiv("tf_reset", "Par défaut", "button blue")); + xActions.appendChild(xPgBarBox); + xActions.appendChild(createDiv("tf_apply", "Appliquer", "button green")); + xActions.appendChild(createDiv("infomsg", "blabla")); + // create result + xTFNode.appendChild(xOptions); + xTFNode.appendChild(xActions); + } + catch (e) { + //console.error(e); + showError(e); + } + return xTFNode; +} + +function createFieldset (sId, bDefault, sLabel) { + let xFieldset = document.createElement("fieldset"); + xFieldset.id = sId; + xFieldset.className = "groupblock"; + let xLegend = document.createElement("legend"); + let xInput = createCheckbox("o_"+sId, bDefault, "option"); + let xLabel = createLabel(xInput.id, sLabel); + // create result + xLegend.appendChild(xInput); + xLegend.appendChild(xLabel); + xFieldset.appendChild(xLegend); + return xFieldset; +} + +function createOptionInputAndLabel (sId, bDefault, sLabel) { + let xOption = document.createElement("div"); + xOption.className = "blockopt underline"; + let xInput = createCheckbox(sId, bDefault, "option"); + let xLabel = createLabel(sId, sLabel, "opt_lbl largew"); + let xResult = createDiv("res_"+sId, "", "result fright"); + // create result + xOption.appendChild(xResult); + xOption.appendChild(xInput); + xOption.appendChild(xLabel); + return xOption; +} + +let sTFinnerHTML = ' \ +