Index: gc_lang/fr/webext/content_scripts/gc_content.js ================================================================== --- gc_lang/fr/webext/content_scripts/gc_content.js +++ gc_lang/fr/webext/content_scripts/gc_content.js @@ -201,14 +201,12 @@ document.getElementById("grammalecte_check"+xParagraph.dataset.para_num).textContent = "Réanalyser"; } applySuggestion (sNodeSuggId) { // sugg try { - console.log(sNodeSuggId); let sErrorId = document.getElementById(sNodeSuggId).dataset.error_id; //let sParaNum = sErrorId.slice(0, sErrorId.indexOf("-")); - console.log("grammalecte_err"+sErrorId); let xNodeErr = document.getElementById("grammalecte_err" + sErrorId); xNodeErr.textContent = document.getElementById(sNodeSuggId).textContent; xNodeErr.className = "corrected"; xNodeErr.removeAttribute("style"); this.oTooltip.hide(); @@ -219,13 +217,11 @@ } } ignoreError (sIgnoreButtonId) { // ignore try { - console.log(sIgnoreButtonId); let sErrorId = document.getElementById(sIgnoreButtonId).dataset.error_id; - console.log("grammalecte_err"+sErrorId); let xNodeErr = document.getElementById("grammalecte_err" + sErrorId); this.aIgnoredErrors.add(xNodeErr.dataset.ignored_key); xNodeErr.className = "ignored"; this.oTooltip.hide(); } @@ -245,30 +241,44 @@ addMessage (sMessage) { let xNode = createNode("div", {className: "grammalecte_gc_panel_message", textContent: sMessage}); this.xParagraphList.appendChild(xNode); } - copyToClipboard () { + _copyToClipboard (sText) { + // recipie 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 = "copie en cours…"; + xClipboardButton.textContent = "->>"; let sText = ""; - for (let xNode of document.getElementById("grammalecte_paragraph_list").getElementsByClassName("grammalecte_paragraph")) { + for (let xNode of document.getElementsByClassName("grammalecte_paragraph")) { sText += xNode.textContent + "\n"; } - self.port.emit('copyToClipboard', sText); - xClipboardButton.textContent = "-> presse-papiers"; - window.setTimeout(function() { xClipboardButton.textContent = "∑"; } , 3000); + xClipboardButton.textContent = "OK"; + this._copyToClipboard(sText); + window.setTimeout(function() { xClipboardButton.textContent = "∑"; } , 2000); } catch (e) { - console.log(e.lineNumber + ": " +e.message); + showError(e); } this.stopWaitIcon(); } -} + +} class GrammalecteTooltip { constructor (xContentNode) { Index: gc_lang/fr/webext/content_scripts/panels_content.css ================================================================== --- gc_lang/fr/webext/content_scripts/panels_content.css +++ gc_lang/fr/webext/content_scripts/panels_content.css @@ -73,17 +73,31 @@ } .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(210, 0%, 100%); + color: hsl(180, 0%, 100%); text-align: center; cursor: pointer; } .grammalecte_move_button:hover { background-color: hsl(180, 100%, 60%); @@ -118,11 +132,11 @@ visibility: hidden; width: 40px; height: 40px; position: absolute; top: 2px; - right: 150px; + right: 180px; } .grammalecte_spinner .bounce1, .grammalecte_spinner .bounce2 { width: 100%; height: 100%; Index: gc_lang/fr/webext/content_scripts/panels_content.js ================================================================== --- gc_lang/fr/webext/content_scripts/panels_content.js +++ gc_lang/fr/webext/content_scripts/panels_content.js @@ -8,11 +8,10 @@ class GrammalectePanel { constructor (sId, sTitle, nWidth, nHeight, bFlexible=true) { this.sId = sId; - this.sContentId = sId+"_content"; this.nWidth = nWidth; this.nHeight = nHeight; this.bFlexible = bFlexible; this.xPanelContent = createNode("div", {className: "grammalecte_panel_content"}); this.xWaitIcon = this._createWaitIcon(); @@ -39,10 +38,13 @@ } _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")); @@ -54,10 +56,16 @@ 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; Index: gc_lang/fr/webext/panel/main.js ================================================================== --- gc_lang/fr/webext/panel/main.js +++ gc_lang/fr/webext/panel/main.js @@ -118,11 +118,11 @@ function setGCOptions () { let xPromise = browser.storage.local.get("gc_options"); xPromise.then( function (dSavedOptions) { - console.log(dSavedOptions); + //console.log(dSavedOptions); if (dSavedOptions.hasOwnProperty("gc_options")) { for (let [sOpt, bVal] of dSavedOptions.gc_options) { if (document.getElementById("option_"+sOpt)) { document.getElementById("option_"+sOpt).checked = bVal; }