Grammalecte  Check-in [3d4e5a9e46]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:[fx][bug?] copy text to clipboard
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | fx
Files: files | file ages | folders
SHA3-256:3d4e5a9e46349fb73096c1efcd18f0f2761c24c5181f2847c82a41461a88d4a2
User & Date: olr 2019-05-12 18:33:04
Context
2019-05-12
18:57
[fx] update manifest.json check-in: 49d3639117 user: olr tags: fx, trunk
18:33
[fx][bug?] copy text to clipboard check-in: 3d4e5a9e46 user: olr tags: fx, trunk
17:00
[fr] faux positif check-in: a82ca1439e user: olr tags: fr, trunk
Changes

Changes to gc_lang/fr/webext/content_scripts/init.js.

221
222
223
224
225
226
227














228
229
230
231
232
233
234
            }
            return xNode;
        }
        catch (e) {
            showError(e);
        }
    },















    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;
        let nCaretOffsetEnd = 0;
        let xSelection = window.getSelection();







>
>
>
>
>
>
>
>
>
>
>
>
>
>







221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
            }
            return xNode;
        }
        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;
        let nCaretOffsetEnd = 0;
        let xSelection = window.getSelection();

Changes to gc_lang/fr/webext/content_scripts/panel_gc.js.

382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
    }

    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";
            let sText = "";
            // 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);
            window.setTimeout(() => { xClipboardButton.textContent = "πŸ“‹"; }, 2000);
        }
        catch (e) {
            showError(e);
        }
        this.stopWaitIcon();
    }







<
<
<
<
<
<
<
<
<
<
<
<











|







382
383
384
385
386
387
388












389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
    }

    addMessageToGCPanel (sMessage) {
        let xNode = oGrammalecte.createNode("div", {className: "grammalecte_panel_flow_message", textContent: sMessage});
        this.xParagraphList.appendChild(xNode);
    }













    copyTextToClipboard () {
        this.startWaitIcon();
        try {
            let xClipboardButton = this.xParent.getElementById("grammalecte_clipboard_button");
            xClipboardButton.textContent = "β‡’ presse-papiers";
            let sText = "";
            // 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";
            }
            oGrammalecte.sendTextToClipboard(sText);
            window.setTimeout(() => { xClipboardButton.textContent = "πŸ“‹"; }, 2000);
        }
        catch (e) {
            showError(e);
        }
        this.stopWaitIcon();
    }