Index: gc_lang/fr/webext/content_scripts/init.js ================================================================== --- gc_lang/fr/webext/content_scripts/init.js +++ gc_lang/fr/webext/content_scripts/init.js @@ -223,10 +223,24 @@ } catch (e) { showError(e); } }, + + sendTextToClipboard (sText) { + // recipe from https://github.com/mdn/webextensions-examples/blob/master/context-menu-copy-link-with-types/clipboard-helper.js + // It doesn’t seem to work anymore + //console.log(sText); + 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"); + }, getCaretPosition (xElement) { // JS awfulness again. // recepie from https://stackoverflow.com/questions/4811822/get-a-ranges-start-and-end-offsets-relative-to-its-parent-container let nCaretOffsetStart = 0; Index: gc_lang/fr/webext/content_scripts/panel_gc.js ================================================================== --- gc_lang/fr/webext/content_scripts/panel_gc.js +++ gc_lang/fr/webext/content_scripts/panel_gc.js @@ -384,22 +384,10 @@ addMessageToGCPanel (sMessage) { let xNode = oGrammalecte.createNode("div", {className: "grammalecte_panel_flow_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 = this.xParent.getElementById("grammalecte_clipboard_button"); xClipboardButton.textContent = "⇒ presse-papiers"; @@ -407,11 +395,11 @@ // Quand c'est dans un shadow "this.xParent.getElementsByClassName" n'existe pas. let xElem = this.xParent.getElementById("grammalecte_gc_panel"); for (let xNode of xElem.getElementsByClassName("grammalecte_paragraph")) { sText += xNode.textContent + "\n"; } - this._copyToClipboard(sText); + oGrammalecte.sendTextToClipboard(sText); window.setTimeout(() => { xClipboardButton.textContent = "📋"; }, 2000); } catch (e) { showError(e); }