Grammalecte  Diff

Differences From Artifact [a5f9d0af95]:

To Artifact [649173c95f]:


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






28
29

30
31
32
33
34
35
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
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
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
28


29
30
31
32
33
34
35

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




-





+
+

-
+

-
-
-
+
+
-
-
-
+
+
-
-
-
-
+


+
+
+
+
+
+
+
-
-
+
+
+
+
+
+

-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
+
-
-
-
-
+
+
+
-
-
-
+
+
+
-
-
+
-
-
+
-
-
-
-
-


-
+







// Modify page

"use strict";

console.log("Content script [start]");

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

console.log("Content script [start]");

/*
    Worker (separate thread to avoid freezing Firefox)
* Pour effectuer différent action sur la page en cours
*/
let xGCEWorker = new SharedWorker(browser.extension.getURL("../gce_sharedworker.js"));

xGCEWorker.onerror = function(e) {
function receivedMessageIframe (oEvent) {
    if ( typeof oEvent.data.SharedWorker !== "undefined" ) {
    console.log('There is an error with your worker!');
    console.log(typeof(e));
    console.log(e);
        //C'est ici que les action devront être effectuées
        console.log('[Web] received (from iframe (Sharedworker)):', oEvent);
    for (let sParam in e) {
        console.log(sParam);
        console.log(e.sParam);
    }
    }    
}

/*
* Creation d'une iframe pour communiquer entre la page visitée et le Shareworker
*/
var iframe = document.createElement('iframe');
iframe.id = "GrammaFrameModule";
iframe.src = browser.extension.getURL('content_scripts/comunicate.html');
iframe.hidden = true;
xGCEWorker.port.onmessage = function (e) {
    // https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent
iframe.onload= function() {
    console.log('[Web] Init protocol de communication');
    //var iframeContent = iframe.contentWindow;
    var iframeContent = document.getElementById("GrammaFrameModule").contentWindow;
    iframeContent.addEventListener("message", receivedMessageIframe, false);

    try {
        switch (e.data[0]) {
        //La frame est chargé on envoie l'initialisation du Sharedworker
            case "grammar_errors":
                console.log("GRAMMAR ERRORS (SHARE)");
                console.log(e.data[1].aGrammErr);
                //browser.runtime.sendMessage({sCommand: "grammar_errors", aGrammErr: e.data[1].aGrammErr});
                break;
            case "spelling_and_grammar_errors":
                console.log("SPELLING AND GRAMMAR ERRORS (SHARE)");
                console.log(e.data[1].aSpellErr);
                console.log(e.data[1].aGrammErr);
                break;
            case "text_to_test_result":
                console.log("TESTS RESULTS (SHARE)");
                console.log(e.data[1]);
        console.log('[Web] Initialise the worker :s');
                break;
            case "fulltests_result":
                console.log("TESTS RESULTS (SHARE)");
                console.log(e.data[1]);
        console.log('[Web] Domaine ext: '+browser.extension.getURL(''));
                break;
            case "options":
                console.log("OPTIONS (SHARE)");
                console.log(e.data[1]);
                break;
            case "tokens":
                console.log("TOKENS (SHARE)");
                console.log(e.data[1]);
                let xLxgTab = browser.tabs.create({
                    url: browser.extension.getURL("panel/lexicographer.html"),
        iframeContent.postMessage({sPath:browser.extension.getURL(''), sPage:location.origin.trim("/")}, browser.extension.getURL('') );
                });
                xLxgTab.then(onCreated, onError);
                break;
            case "error":
                console.log("ERROR (SHARE)");
                console.log(e.data[1]);
                break;
            default:
                console.log("Unknown command (SHARE): " + e.data[0]);
        }
    }
   

    catch (e) {
        showError(e);
    }
};

        //Un petit test pour débogage ;)
console.log("Content script [worker]");
console.log(xGCEWorker);


        console.log('[Web] Test the worker :s');
        iframeContent.postMessage(["parse", {sText: "Vas... J’en aie mare...", sCountry: "FR", bDebug: false, bContext: false}], browser.extension.getURL(''));
    }
//xGCEWorker.port.start();
//console.log("Content script [port started]");

    catch (e) {
        console.error(e);
    }
//xGCEWorker.port.postMessage(["init", {sExtensionPath: browser.extension.getURL("."), sOptions: "", sContext: "Firefox"}]);

}
console.log("Content script [worker initialzed]");

document.body.appendChild(iframe);
xGCEWorker.port.postMessage(["parse", {sText: "Vas... J’en aie mare...", sCountry: "FR", bDebug: false, bContext: false}]);
//xGCEWorker.port.postMessage(["parseAndSpellcheck", {sText: oRequest.sText, sCountry: "FR", bDebug: false, bContext: false}]);
//xGCEWorker.port.postMessage(["getListOfTokens", {sText: oRequest.sText}]);
//xGCEWorker.port.postMessage(["textToTest", {sText: oRequest.sText, sCountry: "FR", bDebug: false, bContext: false}]);
//xGCEWorker.port.postMessage(["fullTests"]);



console.log('[Web] La suite des initialisations');
function wrapTextareas() {;
    let lNode = document.getElementsByTagName("textarea");
    for (let xNode of lNode) {
        createGCButton(xNode);
    }
}