Grammalecte  Changes On Branch webext_sharedworker

Changes In Branch webext_sharedworker Excluding Merge-Ins

This is equivalent to a diff from 08f0167b9e to d51f7da951

2017-08-11
16:33
[fx] Pas mal de simplifications dans le code, mais le SharedWorker ne se partage toujours pas... Leaf check-in: d51f7da951 user: IllusionPerdu tags: fx, webext_sharedworker
10:44
[fx] Le SharedWorker ne se partage pas dans toutes les fenêtres... Estce à cause de la bidouille ??? check-in: c262fc885d user: IllusionPerdu tags: fx, webext_sharedworker
2017-08-10
14:08
Create new branch named "webext_sharedworker" check-in: 976290fcbe user: IllusionPerdu tags: webext_sharedworker
09:59
[fx] content-script interface + remove SharedWorker check-in: e026bff1c5 user: olr tags: fx, webext2
2017-08-09
19:33
[fx] Correct the intialisation of the SharedWorker check-in: 08f0167b9e user: IllusionPerdu tags: fx, webext2
18:11
[fx] SharedWorker attempt (not working in content script) + lexicographer panel check-in: 4e34f03093 user: olr tags: fx, webext2

Modified gc_lang/fr/webext/background.js from [eb2f1b3278] to [f938801ed1].

1

2
3
4
5
6
7
8
9
10
11
12



13
14
15
16
17
18
19

1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17
18
19
20
21
-
+










-
+
+
+







// Background 
// Background

"use strict";

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 Worker("gce_worker.js");
//let xGCEWorker = new Worker("gce_worker.js");
var xGCESharedWorker = xGCESharedWorker || new SharedWorker(browser.extension.getURL("gce_sharedworker.js"), {type:"classic", credentials:"omit", name:"GrammarWorker"});
var xGCEWorker = xGCESharedWorker.port;

xGCEWorker.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");
53
54
55
56
57
58
59
60

61
62
63
64
65
66
67
55
56
57
58
59
60
61

62
63
64
65
66
67
68
69







-
+







                console.log("Unknown command: " + e.data[0]);
        }
    }
    catch (e) {
        showError(e);
    }
};

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


/*
    Messages from the extension (not the Worker)
*/
function handleMessage (oRequest, xSender, sendResponse) {
154
155
156
157
158
159
160
161

162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
156
157
158
159
160
161
162

163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182

















































































-
+



















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
        case "conjugueur_tab":
            xConjTab = browser.tabs.create({
                url: browser.extension.getURL("panel/conjugueur.html"),
                pinned: true
            });
            xConjTab.then(onCreated, onError);
            break;
    }    
    }
});


async function newwin () {
    console.log("Async on");
    const getActive = browser.tabs.query({ currentWindow: true, active: true, });
    const xWindowInfo = await browser.windows.getLastFocused();
    // the pop-up will not resize itself as the panel would, so the dimensions can be passed as query params 'w' and 'h'
    const width = 710, height = 980; // the maximum size for panels is somewhere around 700x800. Firefox needs some additional pixels: 14x42 for FF54 on Win 10 with dpi 1.25
    const left = Math.round(xWindowInfo.left + xWindowInfo.width - width - 25);
    const top = Math.round(xWindowInfo.top + 74); // the actual frame height of the main window varies, but 74px should place the pop-up at the bottom if the button
    const xWin = await browser.windows.create({
        type: 'panel', url: browser.extension.getURL("panel/conjugueur.html"), top: top, left: left, width: width, height: height,
    });
    browser.windows.update(xWin.id, { top:top, left:left, }); // firefox currently ignores top and left in .create(), so move it here
    console.log("Async done");
}

//newwin();


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

xGCESharedWorker.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 (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]);
                break;
            case "fulltests_result":
                console.log("TESTS RESULTS (SHARE)");
                console.log(e.data[1]);
                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"),
                });
                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);
    }
};

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


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

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

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

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


*/

Added gc_lang/fr/webext/content_scripts/communicate.html version [2013884bde].







1
2
3
4
5
6
+
+
+
+
+
+
<html>
    <head>
        <script src="/content_scripts/communicate.js"></script>
    </head>
    <body></body>
</html>

Added gc_lang/fr/webext/content_scripts/communicate.js version [5abad65778].







































































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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


console.log('[Iframe] Loaded');
/*console.log(self);
console.log(browser);
console.log(location);
console.log(window.parent.location);*/

var sPathOrigin,
    sPathExtension = browser.extension.getURL("");

/*
    Worker (separate thread to avoid freezing Firefox)
*/
var xGCESharedWorker = xGCESharedWorker || new SharedWorker(browser.extension.getURL("gce_sharedworker.js"), {type:"classic", credentials:"omit", name:"GrammarWorker"});
var xGCEWorker = xGCESharedWorker.port;

xGCESharedWorker.onerror = function(e) {
    console.log('There is an error with your worker!');
    console.log(typeof(e));
    console.log(e);
}

xGCEWorker.onmessage = function (e) {
    // https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent
    try {
        // On retransmet directement le message à la page
        console.log("[Iframe] send from Message Worker ",sPathExtension);
        window.postMessage({SharedWorker: e.data}, sPathExtension);
    }
    catch (e) {
        console.error(e);
    }
};
xGCEWorker.start();

console.log("[Iframe] [worker]");
console.log(xGCESharedWorker);

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

xGCEWorker.postMessage(["init", {sExtensionPath: browser.extension.getURL(""), sOptions: "", sContext: "Firefox"}]);
//xGCEWorker.postMessage(["parse", {sText: "Vas... J’en aie mare...", sCountry: "FR", bDebug: false, bContext: false}]);
//xGCEWorker.postMessage(["parseAndSpellcheck", {sText: oRequest.sText, sCountry: "FR", bDebug: false, bContext: false}]);
//xGCEWorker.postMessage(["getListOfTokens", {sText: oRequest.sText}]);
//xGCEWorker.postMessage(["textToTest", {sText: oRequest.sText, sCountry: "FR", bDebug: false, bContext: false}]);
//xGCEWorker.postMessage(["fullTests"]);


console.log('[Iframe] Set receivedMessageWeb');
function receivedMessageWeb (oEvent) {
    // Pour être sûr que ça vient bien de notre iframe ;)
    if (typeof oEvent.data.sPage !== "undefined" && oEvent.data.sPage === oEvent.origin) {
        console.log('[Iframe] Create the Sharedworker ', oEvent.origin);
        sPathOrigin = oEvent.origin;
    } else if (sPathOrigin === oEvent.origin && typeof oEvent.data.SharedWorker === "undefined") {
        console.log('[Iframe] received (no SharedWorker):', oEvent, oEvent.origin);
        // Les messages reçus maintenant ont un SharedWorker fonctionnel
        // On transmet au SharedWorker uniquement si ça vient de la page web et on s’assure que ce n’est pas une réponse du SharedWorker.
        // TODO: Établir un protocole de communication afin de traiter uniquement les messages utiles
        console.log('[Iframe] exec command with SharedWorker');
        xGCEWorker.postMessage(oEvent.data);
        console.log('[Iframe] end send message to worker');
    }
}

window.addEventListener("message", receivedMessageWeb, false);

console.log('[Iframe] END');

Modified gc_lang/fr/webext/content_scripts/modify_page.js from [a5f9d0af95] to [f0b77e9ea3].

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
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
140
141



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169


170


171
172







173
174
175
176
177
178
179
180
181
182
183
184
185
186






187
188
189





190
191
192
193
194

195







196


197
198

199






200
201
202
203
204
205
206
207
208
209
210
211
212



213
214
215
216
217
218
219




-





+
+

-
+

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

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




-
-
+
-
-


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


-
-
-
-
-
+
+
+


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


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







// 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) {
    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);
function receivedMessageFromIframe (oEvent) {
    if (typeof oEvent.data.SharedWorker !== "undefined") {
        console.log('[Web] received (from iframe (Sharedworker)):', oEvent);
        let [sCommand, answer] = oEvent.data.SharedWorker;
        console.log(sCommand);
        switch (sCommand) {
            case "grammar_errors":
                console.log(answer.aGrammErr);
                for (let oErr of answer.aGrammErr) {
                    console.log(oErr);
                }
                break;
        }
    }
}

/*
* Inject a script to page site to define extension path
*/
/*var xScript = document.createElement('script');
xScript.textContent = 'var sExtensionPath = "'+browser.extension.getURL("")+'";';
document.body.appendChild(xScript);*/


/*
* Creation d'une iframe pour communiquer entre la page visitée et le Shareworker
*/
var sFrameID = browser.extension.getURL("").split('/')[2];
var xIframe = document.createElement('iframe');
let xFrameContent = null;
xIframe.id = sFrameID;
xIframe.src = browser.extension.getURL('content_scripts/communicate.html');
xIframe.hidden = true;
xIframe.onload= function () {
    console.log('[Web] Init protocol de communication');
    //var xFrameContent = xIframe.contentWindow;
    xFrameContent = document.getElementById(sFrameID).contentWindow;
    xFrameContent.addEventListener("message", receivedMessageFromIframe, false);
    try {
        //La frame est chargé on envoie l'initialisation du Sharedworker
        console.log('[Web] Initialise the worker :s');
        console.log('[Web] Domaine ext: '+browser.extension.getURL(""));
        xFrameContent.postMessage({sPage: location.origin.trim("/")}, browser.extension.getURL(""));
        //Un petit test pour débogage ;)
        console.log('[Web] Test the worker :s');
        //xFrameContent.postMessage(["parse", {sText: "Vas... J’en aie mare...", sCountry: "FR", bDebug: false, bContext: false}], browser.extension.getURL(""));
        //Un test qui envoie a tout le monde
        xFrameContent.postMessage(["all", {}], browser.extension.getURL(""));
        //Un test qui envoie aux autres
        xFrameContent.postMessage(["other", {}], browser.extension.getURL(""));
    }
    catch (e) {
        console.error(e);
}

    }
}
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 (SHARE)");
                console.log(e.data[1].aGrammErr);
                //browser.runtime.sendMessage({sCommand: "grammar_errors", aGrammErr: e.data[1].aGrammErr});
                break;
document.body.appendChild(xIframe);


function loadImage (sContainerClass, sImagePath) {
    let xRequest;
    xRequest = new XMLHttpRequest();
    xRequest.open('GET', browser.extension.getURL("")+sImagePath, false);
    xRequest.responseType = "arraybuffer";
    xRequest.send();
    let blobTxt = new Blob([xRequest.response], {type: 'image/png'});
    let img = document.createElement('img');
            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;
    img.src = (URL || webkitURL).createObjectURL(blobTxt);
    Array.filter(document.getElementsByClassName(sContainerClass), function (oElem) {
        oElem.appendChild(img);
    });
}


            case "text_to_test_result":
                console.log("TESTS RESULTS (SHARE)");
                console.log(e.data[1]);
                break;
            case "fulltests_result":
                console.log("TESTS RESULTS (SHARE)");
                console.log(e.data[1]);
                break;
            case "options":
console.log('[Web] La suite des initialisations');

let nWrapper = 0;
let xConjPanel = null;
let xTFPanel = null;
let xLxgPanel = null;
let xGCPanel = null;

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

function createWrapper (xTextArea) {
    try {
        let xParentElement = xTextArea.parentElement;
        let xWrapper = document.createElement("div");
        xWrapper.style = "padding: 5px; color: hsl(210, 10%, 90%); background-color: hsl(210, 50%, 50%); border-radius: 3px;";
        xWrapper.id = nWrapper + 1;
        nWrapper += 1;
        xParentElement.insertBefore(xWrapper, xTextArea);
        xWrapper.appendChild(xTextArea); // move textarea in wrapper
        let xToolbar = createWrapperToolbar(xTextArea);
        xWrapper.appendChild(xToolbar);
        loadImage("GrammalecteTitle", "img/logo-16.png");
    }
    catch (e) {
                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"),
                });
                xLxgTab.then(onCreated, onError);
                break;
            case "error":
                console.log("ERROR (SHARE)");
                console.log(e.data[1]);
                break;
        showError(e);
    }
}


let sButtonStyle = "display: inline-block; padding: 0 5px; margin-left: 5px; background-color: hsl(210, 50%, 60%); border-radius: 2px; cursor: pointer;";

function createWrapperToolbar (xTextArea) {
    try {
        let xToolbar = document.createElement("div");
        xToolbar.style = "display: flex; justify-content: flex-end; margin-top: 5px; padding: 5px 10px;";
        /*let xLogo = document.createElement("img");
        xLogo.src = browser.extension.getURL("img/logo-16.png");
        xTitle.appendChild(xLogo);*/

        let xImage = document.createElement("span");
        xImage.className = "GrammalecteTitle";
        xToolbar.appendChild(xImage);

        xToolbar.appendChild(document.createTextNode("Grammalecte"));
        let xConjButton = document.createElement("div");
        xConjButton.textContent = "Conjuguer";
        xConjButton.style = sButtonStyle;
        xConjButton.onclick = function() {
            createConjPanel();
            default:
                console.log("Unknown command (SHARE): " + e.data[0]);
        }
        };
        xToolbar.appendChild(xConjButton);
        let xTFButton = document.createElement("div");
        xTFButton.textContent = "Formater";
        xTFButton.style = sButtonStyle;
        xTFButton.onclick = function() {
            createTFPanel(xTextArea);
        };
        xToolbar.appendChild(xTFButton);
        let xLxgButton = document.createElement("div");
        xLxgButton.textContent = "Analyser";
        xLxgButton.style = sButtonStyle;
        xLxgButton.onclick = function() {
            createLxgPanel(xTextArea);
        };
        xToolbar.appendChild(xLxgButton);
        let xGCButton = document.createElement("div");
        xGCButton.textContent = "Corriger";
        xGCButton.style = sButtonStyle;
        xGCButton.onclick = function() {
            createGCPanel(xTextArea);
        };
        xToolbar.appendChild(xGCButton);
        return xToolbar;
    }
    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]");

function createConjPanel () {
    console.log("Conjugueur");
    if (xConjPanel !== null) {
        xConjPanel.style.display = "block";
    } else {
        // create the panel
        xConjPanel = document.createElement("div");
        xConjPanel.style = "position: fixed; left: 50%; top: 50%; z-index: 100; height: 400px; margin-top: -200px; width: 600px; margin-left: -300px; border-radius: 10px;"
                         + " color: hsl(210, 10%, 4%); background-color: hsl(210, 20%, 90%); border: 10px solid hsla(210, 20%, 70%, .5);";
        xConjPanel.textContent = "Conjugueur";
        xConjPanel.setAttribute("draggable", true);
        xConjPanel.appendChild(createCloseButton(xConjPanel));
        document.body.appendChild(xConjPanel);
    }
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 createTFPanel (xTextArea) {
    console.log("Formateur de texte");
}

function createGCButton (xActiveTextZone) {
function createLxgPanel (xTextArea) {
    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);
    console.log("Analyse");
    };
    xParentElement.insertBefore(xGCButton, xActiveTextZone);
}

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

function change (param) {
    console.log("Correction grammaticale");
    xFrameContent.postMessage(["parse", {sText: xTextArea.value, sCountry: "FR", bDebug: false, bContext: false}], browser.extension.getURL(""));
}

function createCloseButton (xParentNode) {
    let xButton = document.createElement("div");
    xButton.style = "float: right; width: 20px; padding: 5px 10px; color: hsl(210, 0%, 100%); text-align: center;"
                  + "font-size: 20px; font-weight: bold; background-color: hsl(0, 80%, 50%); border-radius: 0 0 0 3px; cursor: pointer;";
    xButton.textContent = "×";
    xButton.onclick = function () {
        xParentNode.style.display = "none";
    }
    return xButton;
    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.
*/

Modified gc_lang/fr/webext/gce_sharedworker.js from [9a703895dc] to [7892fc1e3d].

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
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155







+
+
+
+
+
+
+
+
-
+

-
+

-
+
+

-
+
+
+


+



-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+
+
+
+
+
+
+


-
+

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









/*
    Message Event Object
    https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent
*/

function showError (e) {
    for (let sParam in e) {
        console.log(sParam);
        console.log(e[sParam]);
    }
}

var xListPort = xListPort || [];
let xPort = null;
//var xPort = null;

onconnect = function(e) {
self.addEventListener("connect", function(e){
    console.log("START CONNECTION");
    xPort = e.ports[0];
    var xPort = e.ports[0];
    xListPort.push(xPort);

    xPort.onmessage = function (e) {

    xPort.addEventListener("message", function(e){
        console.log("[Sharedworker] ONMESSAGE");
        console.log(e);
        console.log(e.data[0]);
        let oReplyToSend;
        let oParam = e.data[1];
        switch (e.data[0]) {
            case "init":
                loadGrammarChecker(oParam.sExtensionPath, oParam.sOptions, oParam.sContext);
                oReplyToSend = loadGrammarChecker(oParam.sExtensionPath, oParam.sOptions, oParam.sContext);
                break;
            case "parse":
                parse(oParam.sText, oParam.sCountry, oParam.bDebug, oParam.bContext);
                oReplyToSend = parse(oParam.sText, oParam.sCountry, oParam.bDebug, oParam.bContext);
                break;
            case "parseAndSpellcheck":
                parseAndSpellcheck(oParam.sText, oParam.sCountry, oParam.bDebug, oParam.bContext);
                oReplyToSend = parseAndSpellcheck(oParam.sText, oParam.sCountry, oParam.bDebug, oParam.bContext);
                break;
            case "getOptions":
                getOptions();
                oReplyToSend = getOptions();
                break;
            case "getDefaultOptions":
                getDefaultOptions();
                oReplyToSend = getDefaultOptions();
                break;
            case "setOptions":
                setOptions(oParam.sOptions);
                oReplyToSend = setOptions(oParam.sOptions);
                break;
            case "setOption":
                setOption(oParam.sOptName, oParam.bValue);
                oReplyToSend = setOption(oParam.sOptName, oParam.bValue);
                break;
            case "resetOptions":
                resetOptions();
                oReplyToSend = resetOptions();
                break;
            case "textToTest":
                textToTest(oParam.sText, oParam.sCountry, oParam.bDebug, oParam.bContext);
                oReplyToSend = textToTest(oParam.sText, oParam.sCountry, oParam.bDebug, oParam.bContext);
                break;
            case "fullTests":
                fullTests();
                oReplyToSend = fullTests();
                break;
            case "getListOfTokens":
                getListOfTokens(oParam.sText);
                oReplyToSend = getListOfTokens(oParam.sText);
                break;
            case "other":
                oReplyToSend = "Message to Other";
                break;
            case "all":
                oReplyToSend = "Message to All";
                break;
            default:
                console.log("Unknown command: " + e.data[0]);
                console.log("Unknown command: " + showError(e.data[0]));
        }
    }
    //xPort.start();
}

        console.log("[Sharedworker PortList] ",xListPort,this);
        if ( e.data[0] == "all" ) {
            console.log("[Sharedworker All] Number of client: "+xListPort.length);
            xListPort.forEach(function(client){
                client.postMessage(oReplyToSend);
            });
        } else if ( e.data[0] == "other" ) {
            console.log("[Sharedworker Other] Number of client: "+xListPort.length);
            xListPort.forEach(function(client){
                if (client !== this){
                    client.postMessage(oReplyToSend);
                }
            });
        } else {
            console.log("[Sharedworker Direct reply]");
            this.postMessage(oReplyToSend);
        }

    });
    xPort.start();
});


let oDict = null;
let oTokenizer = null;
let oLxg = null;
let oTest = null;

128
129
130
131
132
133
134
135

136
137

138
139
140
141

142
143
144
145
146
147

148
149
150
151
152
153

154
155
156
157

158
159
160
161

162
163
164
165
166

167
168
169
170
171

172
173
174
175
176

177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192

193
194
195
196
197
198
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
234

235
236
237
238

239
240
165
166
167
168
169
170
171

172
173

174
175
176
177

178
179
180
181
182
183

184
185
186
187
188
189

190
191
192
193

194
195
196
197

198
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
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







-
+

-
+



-
+





-
+





-
+



-
+



-
+




-
+




-
+




-
+















-
+
-






-
+




-
+
-











-
+















-
+



-
+


        oDict = gc_engine.getDictionary();
        oTest = new TestGrammarChecking(gc_engine, sExtensionPath+"/grammalecte/fr/tests_data.json");
        oLxg = new Lexicographe(oDict);
        if (sGCOptions !== "") {
            gc_engine.setOptions(helpers.objectToMap(JSON.parse(sGCOptions)));
        }
        oTokenizer = new Tokenizer("fr");
        tests();
        //tests();
        // we always retrieve options from the gc_engine, for setOptions filters obsolete options
        xPort.postMessage(["options", gc_engine.getOptions().gl_toString()]);
        return ["options", gc_engine.getOptions().gl_toString()];
    }
    catch (e) {
        console.error(e.fileName + "\n" + e.name + "\nline: " + e.lineNumber + "\n" + e.message);
        xPort.postMessage(["error", e.message]);
        return ["error", e.message];
    }
}

function parse (sText, sCountry, bDebug, bContext) {
    let aGrammErr = gc_engine.parse(sText, sCountry, bDebug, bContext);
    xPort.postMessage(["grammar_errors", {aGrammErr: aGrammErr}]);
    return ["grammar_errors", {aGrammErr: aGrammErr}];
}

function parseAndSpellcheck (sText, sCountry, bDebug, bContext) {
    let aGrammErr = gc_engine.parse(sText, sCountry, bDebug, bContext);
    let aSpellErr = oTokenizer.getSpellingErrors(sText, oDict);
    xPort.postMessage(["spelling_and_grammar_errors", {aGrammErr: aGrammErr, aSpellErr: aSpellErr}]);
    return ["spelling_and_grammar_errors", {aGrammErr: aGrammErr, aSpellErr: aSpellErr}];
}

function getOptions () {
    xPort.postMessage(["options", gc_engine.getOptions().gl_toString()]);
    return ["options", gc_engine.getOptions().gl_toString()];
}

function getDefaultOptions () {
    xPort.postMessage(["options", gc_engine.getDefaultOptions().gl_toString()]);
    return ["options", gc_engine.getDefaultOptions().gl_toString()];
}

function setOptions (sGCOptions) {
    gc_engine.setOptions(helpers.objectToMap(JSON.parse(sGCOptions)));
    xPort.postMessage(["options", gc_engine.getOptions().gl_toString()]);
    return ["options", gc_engine.getOptions().gl_toString()];
}

function setOption (sOptName, bValue) {
    gc_engine.setOptions(new Map([ [sOptName, bValue] ]));
    xPort.postMessage(["options", gc_engine.getOptions().gl_toString()]);
    return ["options", gc_engine.getOptions().gl_toString()];
}

function resetOptions () {
    gc_engine.resetOptions();
    xPort.postMessage(["options", gc_engine.getOptions().gl_toString()]);
    return ["options", gc_engine.getOptions().gl_toString()];
}

function tests () {
    console.log(conj.getConj("devenir", ":E", ":2s"));
    console.log(mfsp.getMasForm("emmerdeuse", true));
    console.log(mfsp.getMasForm("pointilleuse", false));
    console.log(phonet.getSimil("est"));
    let aRes = gc_engine.parse("Je suit...");
    for (let oErr of aRes) {
        console.log(text.getReadableError(oErr));
    }
}

function textToTest (sText, sCountry, bDebug, bContext) {
    if (!gc_engine || !oDict) {
        xPort.postMessage(["error", "# Error: grammar checker or dictionary not loaded."]);
        return ["error", "# Error: grammar checker or dictionary not loaded."];
        return;
    }
    let aGrammErr = gc_engine.parse(sText, sCountry, bDebug, bContext);
    let sMsg = "";
    for (let oErr of aGrammErr) {
        sMsg += text.getReadableError(oErr) + "\n";
    }
    xPort.postMessage(["text_to_test_result", sMsg]);
    return ["text_to_test_result", sMsg];
}

function fullTests (sGCOptions='{"nbsp":true, "esp":true, "unit":true, "num":true}') {
    if (!gc_engine || !oDict) {
        xPort.postMessage(["error", "# Error: grammar checker or dictionary not loaded."]);
        return ["error", "# Error: grammar checker or dictionary not loaded."];
        return;
    }
    let dMemoOptions = gc_engine.getOptions();
    if (sGCOptions) {
        gc_engine.setOptions(helpers.objectToMap(JSON.parse(sGCOptions)));
    }
    let sMsg = "";
    for (let sRes of oTest.testParse()) {
        sMsg += sRes + "\n";
        console.log(sRes);
    }
    gc_engine.setOptions(dMemoOptions);
    xPort.postMessage(["fulltests_result", sMsg]);
    return ["fulltests_result", sMsg];
}


// Lexicographer

function getListOfTokens (sText) {
    try {
        let aElem = [];
        let aRes = null;
        for (let oToken of oTokenizer.genTokens(sText)) {
            aRes = oLxg.getInfoForToken(oToken);
            if (aRes) {
                aElem.push(aRes);
            }
        }
        xPort.postMessage(["tokens", aElem]);
        return ["tokens", aElem];
    }
    catch (e) {
        helpers.logerror(e);
        xPort.postMessage(["error", e.message]);
        return ["error", e.message];
    }
}

Modified gc_lang/fr/webext/manifest.json from [1400a7a766] to [a125616a8e].

40
41
42
43
44
45
46
47




48
49
50
51
52
53
54
40
41
42
43
44
45
46

47
48
49
50
51
52
53
54
55
56
57







-
+
+
+
+







    }
  ],
  "web_accessible_resources": [
    "grammalecte/_dictionaries/French.json",
    "grammalecte/fr/conj_data.json",
    "grammalecte/fr/mfsp_data.json",
    "grammalecte/fr/phonet_data.json",
    "grammalecte/fr/tests_data.json"
    "grammalecte/fr/tests_data.json",
    "content_scripts/communicate.html",
    "content_scripts/communicate.js",
    "img/logo-16.png"
  ],
  "permissions": [
    "activeTab",
    "contextMenus"
  ],
  "chrome_settings_overrides": {
    "search_provider": {

Modified gc_lang/fr/webext/panel/main.html from [152e200e98] to [6809bc8ca4].

34
35
36
37
38
39
40

41
42
43
44
45
46
47
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48







+







      </div>
      -->

      <div id="page">

        <section id="home_page" class="page">
          <h1>GRAMMALECTE</h1>
          <a href="https://www.dicollecte.org/test.html">TEST TEXTAREA</a>
        </section>

        <section id="gc_page" class="page">
          <h1>CORRECTEUR GRAMMATICAL</h1>
          <div id="paragraphs_list"></div>
        </section>