Grammalecte  Check-in [49c4a65f72]

Overview
Comment:[fx] copy text to clipboard
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | fx | webext2
Files: files | file ages | folders
SHA3-256: 49c4a65f72c5a97549c40f0ed54d1ed087b399d0f30eace41740072553d6c631
User & Date: olr on 2017-08-29 06:18:42
Other Links: branch diff | manifest | tags
Context
2017-08-29
09:49
[fx] default gc options check-in: 6524138639 user: olr tags: fx, webext2
06:18
[fx] copy text to clipboard check-in: 49c4a65f72 user: olr tags: fx, webext2
2017-08-28
15:57
[fx] use dataset check-in: 3472c83094 user: olr tags: fx, webext2
Changes

Modified gc_lang/fr/webext/content_scripts/gc_content.js from [6462f47783] to [acc5b2167c].

199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
    freeParagraph (xParagraph) {
        xParagraph.contentEditable = "true";
        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();
            this.recheckParagraph(parseInt(sErrorId.slice(0, sErrorId.indexOf("-"))));
        }
        catch (e) {
            showError(e);
        }
    }

    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();
        }
        catch (e) {
            showError(e);







<


<














<

<







199
200
201
202
203
204
205

206
207

208
209
210
211
212
213
214
215
216
217
218
219
220
221

222

223
224
225
226
227
228
229
    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);
243
244
245
246
247
248
249
250













251
252
253
254
255
256
257
258
259
260

261
262
263
264
265
266
267
268
269

270
271
272
273
274
275
276
    }

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

    copyToClipboard () {













        this.startWaitIcon();
        try {
            let xClipboardButton = document.getElementById("grammalecte_clipboard_button");
            xClipboardButton.textContent = "copie en cours…";
            let sText = "";
            for (let xNode of document.getElementById("grammalecte_paragraph_list").getElementsByClassName("grammalecte_paragraph")) {
                sText += xNode.textContent + "\n";
            }
            self.port.emit('copyToClipboard', sText);
            xClipboardButton.textContent = "-> presse-papiers";

            window.setTimeout(function() { xClipboardButton.textContent = "∑"; } , 3000);
        }
        catch (e) {
            console.log(e.lineNumber + ": " +e.message);
        }
        this.stopWaitIcon();
    }
}




class GrammalecteTooltip {

    constructor (xContentNode) {
        this.xTooltip = createNode("div", {id: "grammalecte_tooltip"});
        this.xTooltipArrow = createNode("img", {







|
>
>
>
>
>
>
>
>
>
>
>
>
>



|

|


<
|
>
|


|



|

>







239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267

268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
    }

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

    _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 = "->>";
            let sText = "";
            for (let xNode of document.getElementsByClassName("grammalecte_paragraph")) {
                sText += xNode.textContent + "\n";
            }

            xClipboardButton.textContent = "OK";
            this._copyToClipboard(sText);
            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", {

Modified gc_lang/fr/webext/content_scripts/panels_content.css from [4b186e5716] to [4620d0a4ab].

71
72
73
74
75
76
77














78
79
80
81
82
83
84
85
86
87
88
89
90
91
    display: inline-block;
    padding: 0 10px;
}

.grammalecte_panel_commands {
    float: right;
}














.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%);
    text-align: center;
    cursor: pointer;
}
.grammalecte_move_button:hover {
    background-color: hsl(180, 100%, 60%);
}
.grammalecte_close_button {







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






|







71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
    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 {
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
*/
.grammalecte_spinner {
    visibility: hidden;
    width: 40px;
    height: 40px;
    position: absolute;
    top: 2px;
    right: 150px;
}
.grammalecte_spinner .bounce1,
.grammalecte_spinner .bounce2 {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background-color: hsl(0, 50%, 75%);







|







130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
*/
.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%);

Modified gc_lang/fr/webext/content_scripts/panels_content.js from [df3e50c05e] to [51927cd000].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// JavaScript
// Panel creator

"use strict";

console.log("[Content script] Panel creator");


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();
        this.xPanelNode = this._createPanel(sTitle);
        this.center();












<







1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
// JavaScript
// Panel creator

"use strict";

console.log("[Content script] Panel creator");


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();
37
38
39
40
41
42
43



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58






59
60
61
62
63
64
65
            showError(e);
        }
    }

    _createButtons () {
        let xButtonLine = createNode("div", {className: "grammalecte_panel_commands"});
        xButtonLine.appendChild(this.xWaitIcon);



        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;
    }







    _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;
    }








>
>
>















>
>
>
>
>
>







36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
            showError(e);
        }
    }

    _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;
    }

Modified gc_lang/fr/webext/panel/main.js from [bc8475212d] to [235cf872b7].

116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
    document.getElementById("tests_result").textContent = sText;
}

function setGCOptions () {
    let xPromise = browser.storage.local.get("gc_options");
    xPromise.then(
        function (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;
                    }
                }
            }
        },
        function (e) {
            showError(e);
        }
    );
}







|













116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
    document.getElementById("tests_result").textContent = sText;
}

function setGCOptions () {
    let xPromise = browser.storage.local.get("gc_options");
    xPromise.then(
        function (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;
                    }
                }
            }
        },
        function (e) {
            showError(e);
        }
    );
}