Grammalecte  Check-in [d33b55a9be]

Overview
Comment:[fx] gc panel: websites exception list for writing within page
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | fx
Files: files | file ages | folders
SHA3-256: d33b55a9be857050d07f0e3f6ab60b7dcb89e460c8dc80faa0a3e62584bd13d6
User & Date: olr on 2020-08-17 14:09:18
Other Links: manifest | tags
Context
2020-08-17
17:15
[fr] ajustements check-in: b9e7b70689 user: olr tags: trunk, fr
14:09
[fx] gc panel: websites exception list for writing within page check-in: d33b55a9be user: olr tags: trunk, fx
2020-08-16
10:33
[fr] ajustements check-in: 1476def50f user: olr tags: trunk, fr
Changes

Modified gc_lang/fr/config.ini from [7da15f3bb0] to [ea7393db43].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[args]
lang = fr
lang_name = French
locales = fr_FR fr_BE fr_CA fr_CH fr_LU fr_BF fr_BJ fr_CD fr_CI fr_CM fr_MA fr_ML fr_MU fr_NE fr_RE fr_SN fr_TG
country_default = FR
name = Grammalecte
implname = grammalecte
# always use 3 numbers for version: x.y.z
version = 1.12
author = Olivier R.
provider = Grammalecte.net
link = https://grammalecte.net
description = Correcteur grammatical, orthographique et typographique pour le français.
extras = README_fr.txt
logo = logo.png









|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[args]
lang = fr
lang_name = French
locales = fr_FR fr_BE fr_CA fr_CH fr_LU fr_BF fr_BJ fr_CD fr_CI fr_CM fr_MA fr_ML fr_MU fr_NE fr_RE fr_SN fr_TG
country_default = FR
name = Grammalecte
implname = grammalecte
# always use 3 numbers for version: x.y.z
version = 1.12.0
author = Olivier R.
provider = Grammalecte.net
link = https://grammalecte.net
description = Correcteur grammatical, orthographique et typographique pour le français.
extras = README_fr.txt
logo = logo.png

Modified gc_lang/fr/webext/content_scripts/editor.js from [5de9b2b371] to [9139e703d3].

1
2
3
4
5
6
7













8
9
10
11
12
13
14
// JavaScript

// Editor for HTML page


"use strict";















/*
    Text Editor
*/
var oGrammalecteTextEditor = {

    dParagraphs: new Map(),







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







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// JavaScript

// Editor for HTML page


"use strict";


// Exception list
var oGrammalecteExclusions = new Set([
    "twitter.com"
]);


var oGrammalecteMessages = {
    "no_text_area": "⛔ Aucun champ textuel défini. Les changements ne seront pas répercutés sur la zone d’où le texte a été extrait.",
    "format_warning": "❗ La zone de texte est un champ textuel enrichi. Les éléments de formatage direct (non textuels) sont susceptibles d’être effacés lors de la correction.",
    "excluded_site": "⛔ Renvoyer les corrections sur ce site s’avère difficile à cause des interférences possibles. La zone d’où a été extrait le texte ne sera pas modifiée. Vous pouvez copier le texte dans le presse-papiers avec le bouton 📋 ci-dessus."
};


/*
    Text Editor
*/
var oGrammalecteTextEditor = {

    dParagraphs: new Map(),
64
65
66
67
68
69
70

71
72
73
74
75
76
77
    Editor for HTML page (Thunderbird or Iframe)
*/
class HTMLPageEditor {

	constructor (xWhat, xResultNode=null, bCheckSignature=true) {
        this.xWhat = xWhat;
        this.bIframe = false;

        //console.log(xWhat);
        if (xWhat.tagName  &&  xWhat.tagName == "IFRAME") {
            // iframe
            this.xDocument = xWhat.contentWindow.document;
            this.bIframe = true;
        }
        else if (xWhat instanceof HTMLDocument) {







>







77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
    Editor for HTML page (Thunderbird or Iframe)
*/
class HTMLPageEditor {

	constructor (xWhat, xResultNode=null, bCheckSignature=true) {
        this.xWhat = xWhat;
        this.bIframe = false;
        this.bWrite = !oGrammalecteExclusions.has(document.location.host);
        //console.log(xWhat);
        if (xWhat.tagName  &&  xWhat.tagName == "IFRAME") {
            // iframe
            this.xDocument = xWhat.contentWindow.document;
            this.bIframe = true;
        }
        else if (xWhat instanceof HTMLDocument) {
90
91
92
93
94
95
96


97




98
99
100
101
102
103
104
            this.xResultNode = xResultNode;
            this.bResultInEvent = true;
        }
        this.lNode = [];
        this.bCheckSignature = bCheckSignature;
        this._lParsableNodes = ["P", "LI", "H1", "H2", "H3", "H4", "H5", "H6"];
        this._lRootNodes = ["DIV", "UL", "OL"];


        oGrammalecte.oGCPanel.addMessageToGCPanel("❗ Les éléments de formatage direct (non textuels) sont susceptibles d’être effacés lors de la correction.");




        let sText = this.getTextFromPage();
        oGrammalecteTextEditor.loadText(sText);
    }

    * _getParsableNodes (xRootNode) {
        // recursive function
        try {







>
>
|
>
>
>
>







104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
            this.xResultNode = xResultNode;
            this.bResultInEvent = true;
        }
        this.lNode = [];
        this.bCheckSignature = bCheckSignature;
        this._lParsableNodes = ["P", "LI", "H1", "H2", "H3", "H4", "H5", "H6"];
        this._lRootNodes = ["DIV", "UL", "OL"];
        if (!this.bWrite) {
            // we don’t write back to the page
            oGrammalecte.oGCPanel.addMessageToGCPanel(oGrammalecteMessages["excluded_site"]);
            oGrammalecte.oGCPanel.highlightClipboardButton();
        } else {
            oGrammalecte.oGCPanel.addMessageToGCPanel(oGrammalecteMessages["format_warning"]);
        }
        let sText = this.getTextFromPage();
        oGrammalecteTextEditor.loadText(sText);
    }

    * _getParsableNodes (xRootNode) {
        // recursive function
        try {
176
177
178
179
180
181
182



183
184
185
186
187
188
189

    loadText (sText) {
        oGrammalecteTextEditor.loadText(sText);
        this.write();
    }

    write () {



        for (let [i, sParagraph] of oGrammalecteTextEditor.getParagraphs()) {
            if (i < this.lNode.length) {
                this.lNode[iParagraph].textContent = sParagraph;
            }
        }
    }








>
>
>







196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212

    loadText (sText) {
        oGrammalecteTextEditor.loadText(sText);
        this.write();
    }

    write () {
        if (!this.bWrite) {
            return;
        }
        for (let [i, sParagraph] of oGrammalecteTextEditor.getParagraphs()) {
            if (i < this.lNode.length) {
                this.lNode[iParagraph].textContent = sParagraph;
            }
        }
    }

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
234
235
236
237
238
239
240
241
242
243
244
245
246

247
248
249
250
251
252
253
254
255
256
257
258
    Editor for TextNode (Textarea or editable node)
*/
class TextNodeEditor {

    constructor (what, xResultNode=null) {
        this.xNode = null;
        this.bTextArea = false;

        this.bResultInEvent = false; // if true, the node content is not modified, but an event is dispatched on the node with the modified text
        this.xResultNode = null; // only useful for text analysed without node
        if (xResultNode instanceof HTMLElement) {
            this.xResultNode = xResultNode;
            this.bResultInEvent = true;
        }
        if (typeof(what) == "string") {
            // SIMPLE TEXT
            if (!this.xResultNode) {
                oGrammalecte.oGCPanel.addMessageToGCPanel("⛔ Aucun champ textuel défini. Les changements ne seront pas répercutés sur la zone d’où le texte a été extrait.");
            }
            this.loadText(what);
        }
        else if (what.nodeType && what.nodeType === 1) {
            // NODE
            this.xNode = what;
            this.bResultInEvent = Boolean(this.xNode.dataset.grammalecte_result_via_event && this.xNode.dataset.grammalecte_result_via_event == "true");
            this.bTextArea = (this.xNode.tagName == "TEXTAREA" || this.xNode.tagName == "INPUT");
            if (this.bTextArea) {
                // text area
                this.xNode.disabled = true;
                this.loadText(this.xNode.value);
            }
            else {
                // editable node


                oGrammalecte.oGCPanel.addMessageToGCPanel("❗ La zone de texte analysée est un champ textuel enrichi susceptible de contenir des éléments non textuels qui seront effacés lors de la correction.");




                this.loadText(this.xNode.innerText);
            }
        }
    }

    loadText (sText) {
        // function also used by the text formatter
        oGrammalecteTextEditor.loadText(sText);
        this.write();
    }

    clear () {
        if (this.xNode !== null) {
            this.xNode.disabled = false;

            this.bTextArea = false;
            this.bResultInEvent = false;
            this.xNode = null;
            this.xResultNode = null;
        }
        oGrammalecteTextEditor.clear();
    }

    getText () {
        return oGrammalecteTextEditor.getText();
    }








>









|















>
>
|
>
>
>
>














>
|
|
|
|
<







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
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
287
288
    Editor for TextNode (Textarea or editable node)
*/
class TextNodeEditor {

    constructor (what, xResultNode=null) {
        this.xNode = null;
        this.bTextArea = false;
        this.bWrite = !oGrammalecteExclusions.has(document.location.host);
        this.bResultInEvent = false; // if true, the node content is not modified, but an event is dispatched on the node with the modified text
        this.xResultNode = null; // only useful for text analysed without node
        if (xResultNode instanceof HTMLElement) {
            this.xResultNode = xResultNode;
            this.bResultInEvent = true;
        }
        if (typeof(what) == "string") {
            // SIMPLE TEXT
            if (!this.xResultNode) {
                oGrammalecte.oGCPanel.addMessageToGCPanel(oGrammalecteMessages["no_text_area"]);
            }
            this.loadText(what);
        }
        else if (what.nodeType && what.nodeType === 1) {
            // NODE
            this.xNode = what;
            this.bResultInEvent = Boolean(this.xNode.dataset.grammalecte_result_via_event && this.xNode.dataset.grammalecte_result_via_event == "true");
            this.bTextArea = (this.xNode.tagName == "TEXTAREA" || this.xNode.tagName == "INPUT");
            if (this.bTextArea) {
                // text area
                this.xNode.disabled = true;
                this.loadText(this.xNode.value);
            }
            else {
                // editable node
                if (!this.bWrite) {
                    // we don’t write back to the page
                    oGrammalecte.oGCPanel.addMessageToGCPanel(oGrammalecteMessages["excluded_site"]);
                    oGrammalecte.oGCPanel.highlightClipboardButton();
                } else {
                    oGrammalecte.oGCPanel.addMessageToGCPanel(oGrammalecteMessages["format_warning"]);
                }
                this.loadText(this.xNode.innerText);
            }
        }
    }

    loadText (sText) {
        // function also used by the text formatter
        oGrammalecteTextEditor.loadText(sText);
        this.write();
    }

    clear () {
        if (this.xNode !== null) {
            this.xNode.disabled = false;
        }
        this.bTextArea = false;
        this.bResultInEvent = false;
        this.xNode = null;
        this.xResultNode = null;

        oGrammalecteTextEditor.clear();
    }

    getText () {
        return oGrammalecteTextEditor.getText();
    }

268
269
270
271
272
273
274



275
276
277
278
279
280
281
    _eraseNodeContent () {
        while (this.xNode.firstChild) {
            this.xNode.removeChild(this.xNode.firstChild);
        }
    }

    write () {



        if (this.xNode !== null) {
            if (this.bResultInEvent) {
                const xEvent = new CustomEvent("GrammalecteResult", { detail: JSON.stringify({ sType: "text", sText: oGrammalecteTextEditor.getText() }) });
                this.xNode.dispatchEvent(xEvent);
                //console.log("[Grammalecte debug] Text sent to xNode via event:", xEvent.detail);
            }
            else if (this.bTextArea) {







>
>
>







298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
    _eraseNodeContent () {
        while (this.xNode.firstChild) {
            this.xNode.removeChild(this.xNode.firstChild);
        }
    }

    write () {
        if (!this.bWrite) {
            return;
        }
        if (this.xNode !== null) {
            if (this.bResultInEvent) {
                const xEvent = new CustomEvent("GrammalecteResult", { detail: JSON.stringify({ sType: "text", sText: oGrammalecteTextEditor.getText() }) });
                this.xNode.dispatchEvent(xEvent);
                //console.log("[Grammalecte debug] Text sent to xNode via event:", xEvent.detail);
            }
            else if (this.bTextArea) {

Modified gc_lang/fr/webext/content_scripts/panel.css from [a49b50b4b7] to [0ba5c9a9a4].

67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
    padding: 1px 10px;
    font-family: "Trebuchet MS", "Fira Sans", "Ubuntu Condensed", "Liberation Sans", sans-serif;
    font-size: 14px;
    font-weight: bold;
    text-align: center;
    cursor: pointer;
}
div.grammalecte_copy_button {
    border-radius: 2px;
    color: hsla(210, 0%, 100%, .4);
    margin-right: 10px;
}
div.grammalecte_copy_button:hover {
    background-color: hsl(210, 50%, 55%);
    color: hsla(210, 0%, 100%, 1);
}
div.grammalecte_move_button {
    padding: 1px 5px;
    border-radius: 16px;
    color: hsl(180, 0%, 100%);







|




|







67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
    padding: 1px 10px;
    font-family: "Trebuchet MS", "Fira Sans", "Ubuntu Condensed", "Liberation Sans", sans-serif;
    font-size: 14px;
    font-weight: bold;
    text-align: center;
    cursor: pointer;
}
div.grammalecte_clipboard_button {
    border-radius: 2px;
    color: hsla(210, 0%, 100%, .4);
    margin-right: 10px;
}
div.grammalecte_clipboard_button:hover {
    background-color: hsl(210, 50%, 55%);
    color: hsla(210, 0%, 100%, 1);
}
div.grammalecte_move_button {
    padding: 1px 5px;
    border-radius: 16px;
    color: hsl(180, 0%, 100%);
211
212
213
214
215
216
217





218










219
220
221
222
223
224
225
    background-color: hsl(210, 40%, 82%);
    color: hsl(210, 20%, 30%);
    font-family: "Trebuchet MS", "Fira Sans", "Ubuntu Condensed", "Liberation Sans", sans-serif;
    font-size: 14px;
}




















/*
    Spinner
*/
div.grammalecte_spinner {
    visibility: hidden;







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







211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
    background-color: hsl(210, 40%, 82%);
    color: hsl(210, 20%, 30%);
    font-family: "Trebuchet MS", "Fira Sans", "Ubuntu Condensed", "Liberation Sans", sans-serif;
    font-size: 14px;
}


/*
    Clipboard animation
*/
div.grammalecte_clipboard_animation {
    animation: grammalecte-clipboard-animation 7s 1;
}

@keyframes grammalecte-clipboard-animation {
    0%      { color: hsla(210, 0%, 100%, .4); background-color: hsla(210, 100%, 80%, .1); }
    10%     { color: hsla(210, 0%, 100%, 1); background-color: hsla(210, 100%, 80%, .9); }
    30%     { color: hsla(210, 0%, 100%, 1); background-color: hsla(210, 100%, 80%, .1); }
    50%     { color: hsla(210, 0%, 100%, 1); background-color: hsla(210, 100%, 80%, .9); }
    70%     { color: hsla(210, 0%, 100%, 1); background-color: hsla(210, 100%, 80%, .1); }
    90%     { color: hsla(210, 0%, 100%, 1); background-color: hsla(210, 100%, 80%, .9); }
    100%    { color: hsla(210, 0%, 100%, .4); background-color: hsla(210, 100%, 80%, 0); }
}


/*
    Spinner
*/
div.grammalecte_spinner {
    visibility: hidden;

Modified gc_lang/fr/webext/content_scripts/panel.js from [6b216971bf] to [01269ca544].

90
91
92
93
94
95
96
97
98
99
100
101
102
103
104

    _createWaitIcon () {
        let xWaitIcon = oGrammalecte.createNode("div", {className: "grammalecte_spinner"});
        return xWaitIcon;
    }

    _createCopyButton () {
        let xButton = oGrammalecte.createNode("div", {id: "grammalecte_clipboard_button", className: "grammalecte_panel_button grammalecte_copy_button", textContent: "📋", title: "Copier le contenu de l’éditeur dans le presse-papiers"});
        xButton.onclick = () => { this.copyTextToClipboard(); };
        return xButton;
    }

    _createMoveButton (sAction, sLabel, sTitle) {
        let xButton = oGrammalecte.createNode("div", {className: "grammalecte_panel_button grammalecte_move_button grammalecte_move_button_"+sAction, textContent: sLabel, title: sTitle});
        xButton.onclick = () => { this[sAction](); };







|







90
91
92
93
94
95
96
97
98
99
100
101
102
103
104

    _createWaitIcon () {
        let xWaitIcon = oGrammalecte.createNode("div", {className: "grammalecte_spinner"});
        return xWaitIcon;
    }

    _createCopyButton () {
        let xButton = oGrammalecte.createNode("div", {id: "grammalecte_clipboard_button", className: "grammalecte_panel_button grammalecte_clipboard_button", textContent: "📋", title: "Copier le contenu de l’éditeur dans le presse-papiers"});
        xButton.onclick = () => { this.copyTextToClipboard(); };
        return xButton;
    }

    _createMoveButton (sAction, sLabel, sTitle) {
        let xButton = oGrammalecte.createNode("div", {className: "grammalecte_panel_button grammalecte_move_button grammalecte_move_button_"+sAction, textContent: sLabel, title: sTitle});
        xButton.onclick = () => { this[sAction](); };
249
250
251
252
253
254
255







256
257
258
259
260
261
262
        this.xWaitIcon.style.visibility = "visible";
    }

    stopWaitIcon () {
        this.bWorking = false;
        this.xWaitIcon.style.visibility = "hidden";
    }








    showMessage (sMessage, sActionMessage="", sActionName="") {
        this.xPanelMessageBlock.style.display = "block";
        this.xPanelMessage.textContent = sMessage;
        if (sActionMessage) {
            this.xPanelMessageActionButton.textContent = sActionMessage;
            this.xPanelMessageActionButton.style.display = "block";







>
>
>
>
>
>
>







249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
        this.xWaitIcon.style.visibility = "visible";
    }

    stopWaitIcon () {
        this.bWorking = false;
        this.xWaitIcon.style.visibility = "hidden";
    }

    highlightClipboardButton () {
        console.log("$$$$");
        this.xClipboardButton.classList.remove("grammalecte_clipboard_animation");
        this.xClipboardButton.classList.add("grammalecte_clipboard_animation");
        console.log("$$$$");
    }

    showMessage (sMessage, sActionMessage="", sActionName="") {
        this.xPanelMessageBlock.style.display = "block";
        this.xPanelMessage.textContent = sMessage;
        if (sActionMessage) {
            this.xPanelMessageActionButton.textContent = sActionMessage;
            this.xPanelMessageActionButton.style.display = "block";