Grammalecte  Diff

Differences From Artifact [0d51f6815a]:

To Artifact [a278d60ca9]:



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




import { echo } from "../mymodule";



echo("CONTENT SCRIPRT!!!");



function handleMessage2 (oRequest, xSender, sendResponse) {








  console.log(`[Content script] received: ${oRequest.content}`);





  change(request.myparam);














































  //browser.runtime.onMessage.removeListener(handleMessage);


  sendResponse({response: "response from content script"});

































}

function removeEverything () {
  while (document.body.firstChild) {
    document.body.firstChild.remove();
  }
}

function change (param) {
  document.getElementById("title").setAttribute("background-color", "#809060");
  console.log("param: " + param);
  document.getElementById("title").setAttribute("background-color", "#FF0000");
}


/*
  Assign do_something() as a listener for messages from the extension.
*/









browser.runtime.onMessage.addListener(handleMessage2);



>
|
>

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



|
|
|



|
|
|




|

>
>
>
>
>
>
>
>
>

>
>
>
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// 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);
}

/*
    Worker (separate thread to avoid freezing Firefox)
*/
let xGCEWorker = new SharedWorker("../gce_sharedworker.js");

xGCEWorker.onerror = function(e) {
    console.log('There is an error with your worker!');
    console.log(typeof(e));
    console.log(e);
    for (let sParam in e) {
        console.log(sParam);
        console.log(e.sParam);
    }
}

xGCEWorker.port.onmessage = function (e) {
    // https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent
    try {
        switch (e.data[0]) {
            case "grammar_errors":
                console.log("GRAMMAR ERRORS");
                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");
                console.log(e.data[1].aSpellErr);
                console.log(e.data[1].aGrammErr);
                break;
            case "text_to_test_result":
                console.log("TESTS RESULTS");
                console.log(e.data[1]);
                break;
            case "fulltests_result":
                console.log("TESTS RESULTS");
                console.log(e.data[1]);
                break;
            case "options":
                console.log("OPTIONS");
                console.log(e.data[1]);
                break;
            case "tokens":
                console.log("TOKENS");
                console.log(e.data[1]);
                let xLxgTab = browser.tabs.create({
                    url: browser.extension.getURL("panel/lexicographer.html"),
                });
                xLxgTab.then(onCreated, onError);
                break;
            case "error":
                console.log("ERROR");
                console.log(e.data[1]);
                break;
            default:
                console.log("Unknown command: " + e.data[0]);
        }
    }
    catch (e) {
        showError(e);
    }
};

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


//xGCEWorker.port.start();
//console.log("Content script [port started]");

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

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

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"]);



function wrapTextareas() {;
    let lNode = document.getElementsByTagName("textarea");
    for (let xNode of lNode) {
        createGCButton(xNode);
    }
}

function createGCButton (xActiveTextZone) {
    let xParentElement = xActiveTextZone.parentElement;
    let xGCButton = document.createElement("div");
    xGCButton.textContent = "@";
    xGCButton.title = "Grammalecte"
    xGCButton.style = "padding: 5px; color: #FFF; background-color: hsla(210, 50%, 50%, 80%); border-radius: 3px; cursor: pointer";
    xGCButton.onclick = function() {
        console.log(xActiveTextZone.value);
    };
    xParentElement.insertBefore(xGCButton, xActiveTextZone);
}

function removeEverything () {
    while (document.body.firstChild) {
        document.body.firstChild.remove();
    }
}

function change (param) {
    document.getElementById("title").setAttribute("background-color", "#809060");
    console.log("param: " + param);
    document.getElementById("title").setAttribute("background-color", "#FF0000");
}


/*
    Assign do_something() as a listener for messages from the extension.
*/


function handleMessage2 (oRequest, xSender, sendResponse) {
    console.log(`[Content script] received: ${oRequest.content}`);
    change(request.myparam);
    //browser.runtime.onMessage.removeListener(handleMessage);
    sendResponse({response: "response from content script"});
}

browser.runtime.onMessage.addListener(handleMessage2);


wrapTextareas();