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
|
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
|
-
+
-
+
-
+
-
+
-
+
-
+
|
/*
Context Menu
*/
// Editable content
browser.contextMenus.create({
id: "getListOfTokensForEditable",
id: "rightClickLxgEditableNode",
title: "Lexicographe (zone de texte)",
contexts: ["editable"]
});
browser.contextMenus.create({
id: "parseAndSpellcheckForEditable",
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: "getListOfTokensForPage",
id: "rightClickLxgPage",
title: "Lexicographe (page)",
contexts: ["all"]
});
browser.contextMenus.create({
id: "parseAndSpellcheckForPage",
id: "rightClickGCPage",
title: "Correction grammaticale (page)",
contexts: ["all"]
});
browser.contextMenus.create({
id: "separator_page",
type: "separator",
contexts: ["all"]
});
// Selected text
browser.contextMenus.create({
id: "getListOfTokensForSelection",
id: "getListOfTokensFromSelectedText",
title: "Lexicographe (sélection)",
contexts: ["selection"]
});
browser.contextMenus.create({
id: "parseAndSpellcheckForSelection",
id: "parseAndSpellcheckSelectedText",
title: "Correction grammaticale (sélection)",
contexts: ["selection"]
});
browser.contextMenus.create({
id: "separator_selection",
type: "separator",
|
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
|
262
263
264
265
266
267
268
269
270
271
272
273
274
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
|
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
|
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 "rightClickGCEditableNode":
case "rightClickLxgEditableNode":
case "rightClickGCPage":
case "rightClickLxgPage":
sendCommandToTab(xInfo.menuItemId, xTab.id);
break;
// selected text
case "rightClickGCSelectedText":
sendCommandToTab("rightClickGCSelectedText", xTab.id);
xGCEWorker.postMessage({
case "parseAndSpellcheck":
parseAndSpellcheckSelectedText(xTab.id, xInfo.selectionText);
sCommand: "parseAndSpellcheck",
dParam: {sText: xInfo.selectionText, sCountry: "FR", bDebug: false, bContext: false},
dInfo: {iReturnPort: iTab}
});
break;
case "rightClickLxgSelectedText":
sendCommandToTab("rightClickLxgSelectedText", xTab.id);
xGCEWorker.postMessage({
case "getListOfTokens":
getListOfTokensFromSelectedText(xTab.id, xInfo.selectionText);
sCommand: "getListOfTokens",
dParam: {sText: xInfo.selectionText},
dInfo: {iReturnPort: iTab}
});
break;
// conjugueur
case "conjugueur_window":
openConjugueurWindow();
break;
case "conjugueur_tab":
openConjugueurTab();
break;
// rescan page
case "rescanPage":
let xPort = dConnx.get(xTab.id);
xPort.postMessage({sActionDone: "rescanPage"});
break;
default:
console.log("[Background] Unknown menu id: " + xInfo.menuItemId);
console.log(xInfo);
|
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
345
346
347
348
|
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
|
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
+
-
-
-
-
-
-
|
if (bChrome) {
// JS crap again. Chrome can’t store Map object.
dOptions = helpers.mapToObject(dOptions);
}
browser.storage.local.set({"gc_options": dOptions});
}
function parseAndSpellcheckSelectedText (iTab, sText) {
// send message to the tab
let xTabPort = dConnx.get(iTab);
xTabPort.postMessage({sActionDone: "openGCPanel", result: null, dInfo: null, bEnd: false, bError: false});
// send command to the worker
xGCEWorker.postMessage({
sCommand: "parseAndSpellcheck",
dParam: {sText: sText, sCountry: "FR", bDebug: false, bContext: false},
dInfo: {iReturnPort: iTab}
});
}
function sendCommandToTab (sCommand, iTab) {
function getListOfTokensFromSelectedText (iTab, sText) {
// send message to the tab
let xTabPort = dConnx.get(iTab);
xTabPort.postMessage({sActionDone: "openLxgPanel", result: null, dInfo: null, bEnd: false, bError: false});
xTabPort.postMessage({sActionDone: sCommand, result: null, dInfo: null, bEnd: false, bError: false});
// send command to the worker
xGCEWorker.postMessage({
sCommand: "getListOfTokens",
dParam: {sText: sText},
dInfo: {iReturnPort: iTab}
});
}
function openConjugueurTab () {
if (bChrome) {
browser.tabs.create({
url: browser.extension.getURL("panel/conjugueur.html")
});
|