Grammalecte  Diff

Differences From Artifact [e1f7754754]:

To Artifact [83ad0c7397]:


11
12
13
14
15
16
17

18
19
20
21
22
23
24
    No SharedWorker, no images allowed for now…
*/

"use strict";


function showError (e) {

    console.error(e.fileName + "\n" + e.name + "\nline: " + e.lineNumber + "\n" + e.message);
}

// Chrome don’t follow the W3C specification:
// https://browserext.github.io/browserext/
let bChrome = false;
if (typeof(browser) !== "object") {







>







11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
    No SharedWorker, no images allowed for now…
*/

"use strict";


function showError (e) {
    // console can’t display error objects from content scripts
    console.error(e.fileName + "\n" + e.name + "\nline: " + e.lineNumber + "\n" + e.message);
}

// Chrome don’t follow the W3C specification:
// https://browserext.github.io/browserext/
let bChrome = false;
if (typeof(browser) !== "object") {
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99

100
101
102
103
104
105
106
107
108
109
110
111
112
113
114

115
116
117
118
119
120
121
    },

    _prepareButtons: function (oOptions) {
        if (oOptions.hasOwnProperty("ui_options")) {
            this.oOptions = oOptions.ui_options;
            // textarea
            for (let xNode of document.getElementsByTagName("textarea")) {
                if (xNode.dataset.grammalecte_callbutton && document.getElementById(xNode.dataset.grammalecte_callbutton)) {
                    let xButton = document.getElementById(xNode.dataset.grammalecte_callbutton)
                    xButton.onclick = () => {
                        oGrammalecte.startGCPanel(xNode);
                    };
                    this.lButton.push(xButton);
                    this.nButton += 1;
                }
                else if (this.oOptions.textarea  &&  xNode.style.display !== "none" && xNode.style.visibility !== "hidden" && xNode.getAttribute("spellcheck") !== "false") {

                    this.lButton.push(new GrammalecteButton(this.nButton, xNode));
                    this.nButton += 1;
                }
            }
            // editable nodes
            for (let xNode of document.querySelectorAll("[contenteditable]")) {
                if (xNode.dataset.grammalecte_callbutton && document.getElementById(xNode.dataset.grammalecte_callbutton)) {
                    let xButton = document.getElementById(xNode.dataset.grammalecte_callbutton)
                    xButton.onclick = () => {
                        oGrammalecte.startGCPanel(xNode);
                    };
                    this.lButton.push(xButton);
                    this.nButton += 1;
                }
                else if (this.oOptions.editablenode  &&  xNode.style.display !== "none" && xNode.style.visibility !== "hidden") {

                    this.lButton.push(new GrammalecteButton(this.nButton, xNode));
                    this.nButton += 1;
                }
            }
        }
    },








<
<
<
<
<
<
<
<
|
>






<
<
<
<
<
<
<
<
|
>







85
86
87
88
89
90
91








92
93
94
95
96
97
98
99








100
101
102
103
104
105
106
107
108
    },

    _prepareButtons: function (oOptions) {
        if (oOptions.hasOwnProperty("ui_options")) {
            this.oOptions = oOptions.ui_options;
            // textarea
            for (let xNode of document.getElementsByTagName("textarea")) {








                if (this.oOptions.textarea  &&  xNode.style.display !== "none" && xNode.style.visibility !== "hidden" && xNode.getAttribute("spellcheck") !== "false"
                    && !(xNode.dataset.grammalecte_button  &&  xNode.dataset.grammalecte_button == "false")) {
                    this.lButton.push(new GrammalecteButton(this.nButton, xNode));
                    this.nButton += 1;
                }
            }
            // editable nodes
            for (let xNode of document.querySelectorAll("[contenteditable]")) {








                if (this.oOptions.editablenode  &&  xNode.style.display !== "none" && xNode.style.visibility !== "hidden"
                    && !(xNode.dataset.grammalecte_button  &&  xNode.dataset.grammalecte_button == "false")) {
                    this.lButton.push(new GrammalecteButton(this.nButton, xNode));
                    this.nButton += 1;
                }
            }
        }
    },

383
384
385
386
387
388
389









390
391
392
393
394
395
396
397
398



































399
400
401
402
403
404
405
            break;
        case "grammar_checker_page":
            oGrammalecte.startGCPanel(oGrammalecte.getPageText());
            break;
        case "grammar_checker_selection":
            oGrammalecte.startGCPanel(result, false); // result is the selected text
            // selected text is sent to the GC worker in the background script.









            break;
        // rescan page command
        case "rescanPage":
            oGrammalecte.rescanPage();
            break;
        default:
            console.log("[Content script] Unknown command: " + sActionDone);
    }
});





































/*
    Other messages from background
*/
browser.runtime.onMessage.addListener(function (oMessage) {
    let {sActionRequest} = oMessage;







>
>
>
>
>
>
>
>
>









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







370
371
372
373
374
375
376
377
378
379
380
381
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
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
            break;
        case "grammar_checker_page":
            oGrammalecte.startGCPanel(oGrammalecte.getPageText());
            break;
        case "grammar_checker_selection":
            oGrammalecte.startGCPanel(result, false); // result is the selected text
            // selected text is sent to the GC worker in the background script.
            break;
        case "grammar_checker_iframe":
            console.log("[Grammalecte] selected iframe: ", result);
            if (document.activeElement.tagName == "IFRAME") {
                //console.log(document.activeElement.id); frameId given by result is different than frame.id
                oGrammalecte.startGCPanel(document.activeElement.contentWindow.document.body.innerText);
            } else {
                oGrammalecte.showMessage("Erreur. Le cadre sur lequel vous avez cliqué n’a pas pu être identifié. Sélectionnez le texte à corriger et relancez le correcteur via le menu contextuel.");
            }
            break;
        // rescan page command
        case "rescanPage":
            oGrammalecte.rescanPage();
            break;
        default:
            console.log("[Content script] Unknown command: " + sActionDone);
    }
});



/*
    Callable API for the webpage.
    The API script must be injected this way to be callable by the page
*/
let xScriptGrammalecteAPI = document.createElement("script");
xScriptGrammalecteAPI.src = browser.extension.getURL("content_scripts/api.js");
document.documentElement.appendChild(xScriptGrammalecteAPI);

document.addEventListener("GrammalecteCall", function (xEvent) {
    // GrammalecteCall events are dispatched by functions in the API
    try {
        let oCommand = xEvent.detail;
        switch (oCommand.sCommand) {
            case "parseNode":
                if (oCommand.xNode) {
                    oGrammalecte.startGCPanel(oCommand.xNode);
                }
                break;
            case "parseText":
                if (oCommand.sText) {
                    oGrammalecte.startGCPanel(oCommand.sText);
                }
                break;
            default:
                console.log("[Grammalecte] Event: Unknown command", oCommand.sCommand);
        }
    }
    catch (e) {
        showError(e);
    }
});



/*
    Other messages from background
*/
browser.runtime.onMessage.addListener(function (oMessage) {
    let {sActionRequest} = oMessage;