275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
|
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
|
-
+
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
+
+
-
+
-
-
-
+
+
-
-
-
+
-
-
+
-
-
+
-
-
-
-
-
-
-
-
-
+
|
browser.runtime.onConnect.addListener(handleConnexion);
/*
Context Menu
*/
// Analyze
// Selected text
browser.contextMenus.create({ id: "rightClickLxgSelectedText", title: "Lexicographe (sélection)", contexts: ["selection"] });
browser.contextMenus.create({ id: "rightClickGCSelectedText", title: "Correction grammaticale (sélection)", contexts: ["selection"] });
browser.contextMenus.create({ id: "grammar_checker_editable", title: "Analyser cette zone de texte", contexts: ["editable"] });
browser.contextMenus.create({ id: "grammar_checker_selection", title: "Analyser la sélection", contexts: ["selection"] });
browser.contextMenus.create({ id: "separator_selection", type: "separator", contexts: ["selection"] });
// Editable content
browser.contextMenus.create({ id: "rightClickTFEditableNode", title: "Formateur de texte (zone de texte)", contexts: ["editable"] });
browser.contextMenus.create({ id: "rightClickLxgEditableNode", title: "Lexicographe (zone de texte)", contexts: ["editable"] });
browser.contextMenus.create({ id: "rightClickGCEditableNode", title: "Correction grammaticale (zone de texte)", contexts: ["editable"] });
browser.contextMenus.create({ id: "separator_editable", type: "separator", contexts: ["editable"] });
// Page
browser.contextMenus.create({ id: "rightClickLxgPage", title: "Lexicographe (page)", contexts: ["all"] }); // on all parts, due to unwanted selection
browser.contextMenus.create({ id: "rightClickGCPage", title: "Correction grammaticale (page)", contexts: ["all"] });
browser.contextMenus.create({ id: "separator_page", type: "separator", contexts: ["all"] });
browser.contextMenus.create({ id: "grammar_checker_page", title: "Analyser la page", contexts: ["all"] });
browser.contextMenus.create({ id: "separator_tools", type: "separator", contexts: ["all"] });
// Tools
browser.contextMenus.create({ id: "conjugueur_window", title: "Conjugueur [fenêtre]", contexts: ["all"] });
browser.contextMenus.create({ id: "conjugueur_tab", title: "Conjugueur [onglet]", contexts: ["all"] });
browser.contextMenus.create({ id: "conjugueur_window", title: "Conjugueur [fenêtre]", contexts: ["all"] });
//browser.contextMenus.create({ id: "dictionaries", title: "Dictionnaires", contexts: ["all"] });
browser.contextMenus.create({ id: "lexicon_editor", title: "Éditeur lexical", contexts: ["all"] });
// Rescan page
browser.contextMenus.create({ id: "separator_rescan", type: "separator", contexts: ["editable"] });
browser.contextMenus.create({ id: "rescanPage", title: "Rechercher à nouveau les zones de texte", contexts: ["editable"] });
browser.contextMenus.onClicked.addListener(function (xInfo, xTab) {
// xInfo = https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/contextMenus/OnClickData
// xTab = https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/tabs/Tab
// confusing: no way to get the node where we click?!
switch (xInfo.menuItemId) {
// editable node
// page
case "rightClickTFEditableNode":
// analyze
case "grammar_checker_editable":
case "rightClickLxgEditableNode":
case "rightClickGCEditableNode":
case "rightClickLxgPage":
case "grammar_checker_page":
case "rightClickGCPage":
sendCommandToTab(xInfo.menuItemId, xTab.id);
break;
// selected text
case "grammar_checker_selection":
case "rightClickGCSelectedText":
sendCommandToTab("rightClickGCSelectedText", xTab.id);
sendCommandToTab("grammar_checker_selection", xTab.id);
xGCEWorker.postMessage({
sCommand: "parseAndSpellcheck",
dParam: {sText: xInfo.selectionText, sCountry: "FR", bDebug: false, bContext: false},
dInfo: {iReturnPort: xTab.id}
});
break;
case "rightClickLxgSelectedText":
sendCommandToTab("rightClickLxgSelectedText", xTab.id);
xGCEWorker.postMessage({
sCommand: "getListOfTokens",
dParam: {sText: xInfo.selectionText},
dInfo: {iReturnPort: xTab.id}
});
break;
// conjugueur
// tools
case "conjugueur_window":
openConjugueurWindow();
break;
case "conjugueur_tab":
openConjugueurTab();
break;
case "lexicon_editor":
|
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
|
388
389
390
391
392
393
394
395
396
397
398
399
400
401
|
-
|
function sendCommandToTab (sCommand, iTab) {
let xTabPort = dConnx.get(iTab);
xTabPort.postMessage({sActionDone: sCommand, result: null, dInfo: null, bEnd: false, bError: false});
}
function sendCommandToCurrentTab (sCommand) {
console.log(sCommand);
if (bChrome) {
browser.tabs.query({ currentWindow: true, active: true }, (lTabs) => {
for (let xTab of lTabs) {
console.log(xTab);
browser.tabs.sendMessage(xTab.id, {sActionRequest: sCommand});
}
});
|