︙ | | | ︙ | |
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
|
xGCEWorker.postMessage({
sCommand: "setDictionaryOnOff",
dParam: { sDictionary: sDictionary, bActivate: bActivate },
dInfo: {}
});
}
function initSCOptions (dSavedOptions) {
if (!dSavedOptions.hasOwnProperty("sc_options")) {
browser.storage.local.set({"sc_options": {
extended: true,
community: true,
personal: true
}});
setDictionaryOnOff("extended", true);
setDictionaryOnOff("community", true);
setDictionaryOnOff("personal", true);
} else {
let dOptions = dSavedOptions.sc_options;
setDictionaryOnOff("extended", dOptions["extended"]);
setDictionaryOnOff("community", dOptions["community"]);
setDictionaryOnOff("personal", dOptions["personal"]);
}
}
function setDictionary (sDictionary, oDictionary) {
xGCEWorker.postMessage({
sCommand: "setDictionary",
dParam: { sDictionary: sDictionary, oDict: oDictionary },
dInfo: {}
});
}
function setSpellingDictionary (dSavedDictionary) {
if (dSavedDictionary.hasOwnProperty("oExtendedDictionary")) {
setDictionary("extended", dSavedDictionary["oExtendedDictionary"]);
}
if (dSavedDictionary.hasOwnProperty("oCommunityDictionary")) {
setDictionary("community", dSavedDictionary["oCommunityDictionary"]);
}
if (dSavedDictionary.hasOwnProperty("oPersonalDictionary")) {
setDictionary("personal", dSavedDictionary["oPersonalDictionary"]);
}
}
function init () {
if (bChrome) {
browser.storage.local.get("gc_options", initGrammarChecker);
browser.storage.local.get("ui_options", initUIOptions);
browser.storage.local.get("oExtendedDictionary", setSpellingDictionary);
browser.storage.local.get("oCommunityDictionary", setSpellingDictionary);
browser.storage.local.get("oPersonalDictionary", setSpellingDictionary);
browser.storage.local.get("sc_options", initSCOptions);
return;
}
browser.storage.local.get("gc_options").then(initGrammarChecker, showError);
browser.storage.local.get("ui_options").then(initUIOptions, showError);
browser.storage.local.get("oExtendedDictionary").then(setSpellingDictionary, showError);
browser.storage.local.get("oCommunityDictionary").then(setSpellingDictionary, showError);
browser.storage.local.get("oPersonalDictionary").then(setSpellingDictionary, showError);
browser.storage.local.get("sc_options").then(initSCOptions, showError);
}
init();
browser.runtime.onInstalled.addListener(function (oDetails) {
|
|
|
<
<
<
|
|
|
|
>
>
>
|
>
|
|
|
|
|
|
|
|
|
|
|
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
|
xGCEWorker.postMessage({
sCommand: "setDictionaryOnOff",
dParam: { sDictionary: sDictionary, bActivate: bActivate },
dInfo: {}
});
}
function initSCOptions (oData) {
if (!oData.hasOwnProperty("sc_options")) {
browser.storage.local.set({"sc_options": {
extended: true,
community: true,
personal: true
}});
setDictionaryOnOff("community", true);
setDictionaryOnOff("personal", true);
} else {
setDictionaryOnOff("community", oData.sc_options["community"]);
setDictionaryOnOff("personal", oData.sc_options["personal"]);
}
}
function setDictionary (sDictionary, oDictionary) {
xGCEWorker.postMessage({
sCommand: "setDictionary",
dParam: { sDictionary: sDictionary, oDict: oDictionary },
dInfo: {}
});
}
function setSpellingDictionaries (oData) {
if (oData.hasOwnProperty("oPersonalDictionary")) {
// deprecated (to be removed in 2020)
console.log("personal dictionary migration");
browser.storage.local.set({ "personal_dictionary": oData["oPersonalDictionary"] });
setDictionary("personal", oData["oPersonalDictionary"]);
browser.storage.local.remove("oPersonalDictionary");
}
if (oData.hasOwnProperty("personal_dictionary")) {
setDictionary("personal", oData["personal_dictionary"]);
}
if (oData.hasOwnProperty("community_dictionary")) {
setDictionary("community", oData["community_dictionary"]);
}
}
function init () {
if (bChrome) {
browser.storage.local.get("gc_options", initGrammarChecker);
browser.storage.local.get("ui_options", initUIOptions);
browser.storage.local.get("personal_dictionary", setSpellingDictionaries);
browser.storage.local.get("community_dictionary", setSpellingDictionaries);
browser.storage.local.get("oPersonalDictionary", setSpellingDictionaries); // deprecated
browser.storage.local.get("sc_options", initSCOptions);
return;
}
browser.storage.local.get("gc_options").then(initGrammarChecker, showError);
browser.storage.local.get("ui_options").then(initUIOptions, showError);
browser.storage.local.get("personal_dictionary").then(setSpellingDictionaries, showError);
browser.storage.local.get("community_dictionary").then(setSpellingDictionaries, showError);
browser.storage.local.get("oPersonalDictionary").then(setSpellingDictionaries, showError); // deprecated
browser.storage.local.get("sc_options").then(initSCOptions, showError);
}
init();
browser.runtime.onInstalled.addListener(function (oDetails) {
|
︙ | | | ︙ | |
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
|
case "setDictionary":
case "setDictionaryOnOff":
xGCEWorker.postMessage(oRequest);
break;
case "openURL":
browser.tabs.create({url: dParam.sURL});
break;
default:
console.log("[background] Unknown command: " + sCommand);
console.log(oRequest);
}
//sendResponse({response: "response from background script"});
}
browser.runtime.onMessage.addListener(handleMessage);
function handleConnexion (xPort) {
let iPortId = xPort.sender.tab.id; // identifier for the port: each port can be found at dConnx[iPortId]
dConnx.set(iPortId, xPort);
xPort.onMessage.addListener(function (oRequest) {
let {sCommand, dParam, dInfo} = oRequest;
switch (sCommand) {
case "parse":
case "parseAndSpellcheck":
|
>
>
>
>
>
>
>
>
>
>
|
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
|
case "setDictionary":
case "setDictionaryOnOff":
xGCEWorker.postMessage(oRequest);
break;
case "openURL":
browser.tabs.create({url: dParam.sURL});
break;
case "openConjugueurTab":
openConjugueurTab();
break;
case "openLexiconEditor":
openLexiconEditor(dParam["dictionary"]);
break;
case "openDictionaries":
openDictionaries();
break;
default:
console.log("[background] Unknown command: " + sCommand);
console.log(oRequest);
}
//sendResponse({response: "response from background script"});
}
browser.runtime.onMessage.addListener(handleMessage);
function handleConnexion (xPort) {
// Messages from tabs
let iPortId = xPort.sender.tab.id; // identifier for the port: each port can be found at dConnx[iPortId]
dConnx.set(iPortId, xPort);
xPort.onMessage.addListener(function (oRequest) {
let {sCommand, dParam, dInfo} = oRequest;
switch (sCommand) {
case "parse":
case "parseAndSpellcheck":
|
︙ | | | ︙ | |
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
|
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"] });
// Conjugueur
browser.contextMenus.create({ id: "conjugueur_window", title: "Conjugueur [fenêtre]", contexts: ["all"] });
browser.contextMenus.create({ id: "conjugueur_tab", title: "Conjugueur [onglet]", 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
|
|
>
>
|
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
|
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"] });
// 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: "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
|
︙ | | | ︙ | |
321
322
323
324
325
326
327
328
329
330
331
332
333
334
|
// 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);
|
>
>
>
>
>
>
|
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
|
// conjugueur
case "conjugueur_window":
openConjugueurWindow();
break;
case "conjugueur_tab":
openConjugueurTab();
break;
case "lexicon_editor":
openLexiconEditor();
break;
case "dictionaries":
openDictionaries();
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);
|
︙ | | | ︙ | |
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
|
switch (sCommand) {
case "conjugueur_tab":
openConjugueurTab();
break;
case "conjugueur_window":
openConjugueurWindow();
break;
case "lex_editor":
openLexEditor();
break;
}
});
/*
Actions
*/
function storeGCOptions (dOptions) {
if (dOptions instanceof Map) {
dOptions = helpers.mapToObject(dOptions);
}
browser.storage.local.set({"gc_options": dOptions});
}
function sendCommandToTab (sCommand, iTab) {
let xTabPort = dConnx.get(iTab);
xTabPort.postMessage({sActionDone: sCommand, result: null, dInfo: null, bEnd: false, bError: false});
}
function openLexEditor () {
if (bChrome) {
browser.tabs.create({
url: browser.extension.getURL("panel/lex_editor.html")
});
return;
}
let xLexEditor = browser.tabs.create({
url: browser.extension.getURL("panel/lex_editor.html")
});
xLexEditor.then(onCreated, onError);
}
function openConjugueurTab () {
if (bChrome) {
browser.tabs.create({
url: browser.extension.getURL("panel/conjugueur.html")
});
return;
}
let xConjTab = browser.tabs.create({
url: browser.extension.getURL("panel/conjugueur.html")
});
xConjTab.then(onCreated, onError);
}
function openConjugueurWindow () {
if (bChrome) {
browser.windows.create({
url: browser.extension.getURL("panel/conjugueur.html"),
type: "popup",
width: 710,
height: 980
});
return;
}
let xConjWindow = browser.windows.create({
url: browser.extension.getURL("panel/conjugueur.html"),
type: "popup",
width: 710,
height: 980
});
xConjWindow.then(onCreated, onError);
}
function onCreated (xWindowInfo) {
//console.log(`Created window: ${xWindowInfo.id}`);
}
function onError (error) {
console.log(`Error: ${error}`);
}
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
|
|
>
>
>
>
>
>
>
>
>
|
|
|
<
>
|
|
|
|
|
|
>
>
>
>
>
>
>
>
<
<
<
<
<
|
|
|
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
|
switch (sCommand) {
case "conjugueur_tab":
openConjugueurTab();
break;
case "conjugueur_window":
openConjugueurWindow();
break;
case "lexicon_editor":
openLexiconEditor();
break;
case "dictionaries":
openDictionaries();
break;
}
});
/*
Tabs
*/
let nTabLexiconEditor = null;
let nTabDictionaries = null;
let nTabConjugueur = null;
browser.tabs.onRemoved.addListener(function (nTabId, xRemoveInfo) {
switch (nTabId) {
case nTabLexiconEditor: nTabLexiconEditor = null; break;
case nTabDictionaries: nTabDictionaries = null; break;
case nTabConjugueur: nTabConjugueur = null; break;
}
});
/*
Actions
*/
function storeGCOptions (dOptions) {
if (dOptions instanceof Map) {
dOptions = helpers.mapToObject(dOptions);
}
browser.storage.local.set({"gc_options": dOptions});
}
function sendCommandToTab (sCommand, iTab) {
let xTabPort = dConnx.get(iTab);
xTabPort.postMessage({sActionDone: sCommand, result: null, dInfo: null, bEnd: false, bError: false});
}
function openLexiconEditor (sName="__personal__") {
if (nTabLexiconEditor === null) {
if (bChrome) {
browser.tabs.create({
url: browser.extension.getURL("panel/lex_editor.html")
}, onLexiconEditorOpened);
return;
}
let xLexEditor = browser.tabs.create({
url: browser.extension.getURL("panel/lex_editor.html")
});
xLexEditor.then(onLexiconEditorOpened, onError);
}
else {
browser.tabs.update(nTabLexiconEditor, {active: true});
}
}
function onLexiconEditorOpened (xTab) {
nTabLexiconEditor = xTab.id;
}
function openDictionaries () {
if (nTabDictionaries === null) {
if (bChrome) {
browser.tabs.create({
url: browser.extension.getURL("panel/dictionaries.html")
}, onDictionariesOpened);
return;
}
let xLexEditor = browser.tabs.create({
url: browser.extension.getURL("panel/dictionaries.html")
});
xLexEditor.then(onDictionariesOpened, onError);
}
else {
browser.tabs.update(nTabDictionaries, {active: true});
}
}
function onDictionariesOpened (xTab) {
nTabDictionaries = xTab.id;
}
function openConjugueurTab () {
if (nTabDictionaries === null) {
if (bChrome) {
browser.tabs.create({
url: browser.extension.getURL("panel/conjugueur.html")
}, onConjugueurOpened);
return;
}
let xConjTab = browser.tabs.create({
url: browser.extension.getURL("panel/conjugueur.html")
});
xConjTab.then(onConjugueurOpened, onError);
}
else {
browser.tabs.update(nTabConjugueur, {active: true});
}
}
function onConjugueurOpened (xTab) {
nTabConjugueur = xTab.id;
}
function openConjugueurWindow () {
if (bChrome) {
browser.windows.create({
url: browser.extension.getURL("panel/conjugueur.html"),
type: "popup",
width: 710,
height: 980
});
return;
}
let xConjWindow = browser.windows.create({
url: browser.extension.getURL("panel/conjugueur.html"),
type: "popup",
width: 710,
height: 980
});
}
function onError (e) {
console.error(e);
}
|