Grammalecte  Diff

Differences From Artifact [eb2f1b3278]:

To Artifact [fcd118d7b1]:


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
    Worker (separate thread to avoid freezing Firefox)
*/
let xGCEWorker = new Worker("gce_worker.js");

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

                browser.runtime.sendMessage({sCommand: "text_to_test_result", sResult: e.data[1]});
                break;
            case "fulltests_result":
                console.log("TESTS RESULTS");
                browser.runtime.sendMessage({sCommand: "fulltests_result", sResult: 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;
                break;
            case "error":
                console.log("ERROR");
                console.log(e.data[1]);
                break;
            default:
                console.log("Unknown command: " + e.data[0]);

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


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


/*
    Messages from the extension (not the Worker)
*/
function handleMessage (oRequest, xSender, sendResponse) {
    //console.log(xSender);
    switch(oRequest.sCommand) {
        case "parse":
            xGCEWorker.postMessage(["parse", {sText: oRequest.sText, sCountry: "FR", bDebug: false, bContext: false}]);
            break;
        case "parse_and_spellcheck":
            xGCEWorker.postMessage(["parseAndSpellcheck", {sText: oRequest.sText, sCountry: "FR", bDebug: false, bContext: false}]);
            break;
        case "get_list_of_tokens":
            xGCEWorker.postMessage(["getListOfTokens", {sText: oRequest.sText}]);
            break;
        case "text_to_test":
            xGCEWorker.postMessage(["textToTest", {sText: oRequest.sText, sCountry: "FR", bDebug: false, bContext: false}]);
            break;
        case "fulltests":
            xGCEWorker.postMessage(["fullTests"]);
            break;
    }
    //sendResponse({response: "response from background script"});
}

browser.runtime.onMessage.addListener(handleMessage);








>
|
|
>
>
>

|
<

|

|
|

|
>
|

|
|
|

|
>
>
>



|








<
<
<
<

|
>







>
|









|


|


|


|


|







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
    Worker (separate thread to avoid freezing Firefox)
*/
let xGCEWorker = new Worker("gce_worker.js");

xGCEWorker.onmessage = function (e) {
    // https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent
    try {
        let {sActionDone, result, dInfo, bError} = e.data;
        switch (sActionDone) {
            case "init":
                console.log("INIT DONE");
                break;
            case "parse":
                console.log("GRAMMAR ERRORS");
                console.log(result);

                break;
            case "parseAndSpellcheck":
                console.log("SPELLING AND GRAMMAR ERRORS");
                console.log(result.aSpellErr);
                console.log(result.aGrammErr);
                break;
            case "textToTest":
                console.log("TEXT TO TEXT RESULTS");
                browser.runtime.sendMessage({sCommand: "text_to_test_result", sResult: result});
                break;
            case "fullTests":
                console.log("FULL TESTS RESULTS");
                browser.runtime.sendMessage({sCommand: "fulltests_result", sResult: result});
                break;
            case "getOptions":
            case "getDefaultOptions":
            case "setOptions":
            case "setOption":
                console.log("OPTIONS");
                console.log(e.data[1]);
                break;
            case "getListOfTokens":
                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;
                break;




            default:
                console.log("Unknown command: " + sActionDone);
                console.log(result);
        }
    }
    catch (e) {
        showError(e);
    }
};


xGCEWorker.postMessage({sCommand: "init", dParam: {sExtensionPath: browser.extension.getURL("."), sOptions: "", sContext: "Firefox"}, dInfo: {}});


/*
    Messages from the extension (not the Worker)
*/
function handleMessage (oRequest, xSender, sendResponse) {
    //console.log(xSender);
    switch(oRequest.sCommand) {
        case "parse":
            xGCEWorker.postMessage({sCommand: "parse", dParam: {sText: oRequest.sText, sCountry: "FR", bDebug: false, bContext: false}, dInfo: {}});
            break;
        case "parse_and_spellcheck":
            xGCEWorker.postMessage({sCommand: "parseAndSpellcheck", dParam: {sText: oRequest.sText, sCountry: "FR", bDebug: false, bContext: false}, dInfo: {}});
            break;
        case "get_list_of_tokens":
            xGCEWorker.postMessage({sCommand: "getListOfTokens", dParam: {sText: oRequest.sText}, dInfo: {}});
            break;
        case "text_to_test":
            xGCEWorker.postMessage({sCommand: "textToTest", dParam: {sText: oRequest.sText, sCountry: "FR", bDebug: false, bContext: false}, dInfo: {}});
            break;
        case "fulltests":
            xGCEWorker.postMessage({sCommand: "fullTests", dParam: {}, dInfo: {}});
            break;
    }
    //sendResponse({response: "response from background script"});
}

browser.runtime.onMessage.addListener(handleMessage);

112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
browser.contextMenus.create({
    id: "conjugueur_tab",
    title: "Conjugueur [onglet]",
    contexts: ["all"]
});

function onCreated(windowInfo) {
  console.log(`Created window: ${windowInfo.id}`);
}

function onError(error) {
  console.log(`Error: ${error}`);
}

let xConjWindow = null;
let xConjTab = null;

browser.contextMenus.onClicked.addListener(function (xInfo, xTab) {
    // xInfo = https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/contextMenus/OnClickData







|



|







117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
browser.contextMenus.create({
    id: "conjugueur_tab",
    title: "Conjugueur [onglet]",
    contexts: ["all"]
});

function onCreated(windowInfo) {
    console.log(`Created window: ${windowInfo.id}`);
}

function onError(error) {
    console.log(`Error: ${error}`);
}

let xConjWindow = null;
let xConjTab = null;

browser.contextMenus.onClicked.addListener(function (xInfo, xTab) {
    // xInfo = https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/contextMenus/OnClickData
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
            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"]);


*/







>



<











<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
164
165
166
167
168
169
170
171
172
173
174

175
176
177
178
179
180
181
182
183
184
185










































































            xConjTab.then(onCreated, onError);
            break;
    }    
});


async function newwin () {
    // test for popup window-like, which doesn’t close when losing the focus
    console.log("Async on");
    const getActive = browser.tabs.query({ currentWindow: true, active: true, });
    const xWindowInfo = await browser.windows.getLastFocused();

    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();