170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
}
return xNode;
}
catch (e) {
showError(e);
}
},
getCaretPosition: function (xElement) {
// JS awfulness again.
// recepie from https://stackoverflow.com/questions/4811822/get-a-ranges-start-and-end-offsets-relative-to-its-parent-container
let nCaretOffsetStart = 0;
let nCaretOffsetEnd = 0;
let xSelection = window.getSelection();
|
>
>
>
>
>
>
>
>
>
>
>
>
>
|
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
|
}
return xNode;
}
catch (e) {
showError(e);
}
},
findOriginEditableNode: function (xNode) {
if (!xNode) {
return null;
}
if (xNode.tagName == "TEXTAREA" || xNode.tagName == "INPUT" || xNode.tagName == "IFRAME") {
return xNode;
}
const findNode = function (xNode) {
return (!xNode.parentNode.isContentEditable) ? xNode : findNode(xNode.parentNode);
}
return findNode(xNode);
},
getCaretPosition: function (xElement) {
// JS awfulness again.
// recepie from https://stackoverflow.com/questions/4811822/get-a-ranges-start-and-end-offsets-relative-to-its-parent-container
let nCaretOffsetStart = 0;
let nCaretOffsetEnd = 0;
let xSelection = window.getSelection();
|
274
275
276
277
278
279
280
281
282
283
284
285
286
287
|
Send messages to the background
object {
sCommand: the action to perform
oParam: parameters necessary for the execution of the action
oInfo: all kind of informations that needs to be sent back (usually to know where to use the result)
}
*/
parseAndSpellcheck: function (sText, sDestination) {
this.xConnect.postMessage({
sCommand: "parseAndSpellcheck",
oParam: { sText: sText, sCountry: "FR", bDebug: false, bContext: false },
oInfo: { sDestination: sDestination }
});
},
|
>
>
>
>
>
>
>
|
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
|
Send messages to the background
object {
sCommand: the action to perform
oParam: parameters necessary for the execution of the action
oInfo: all kind of informations that needs to be sent back (usually to know where to use the result)
}
*/
checkConnection: function () {
if (!this.xConnect) {
this.xConnect = browser.runtime.connect({name: "content-script port"});
}
},
parseAndSpellcheck: function (sText, sDestination) {
this.xConnect.postMessage({
sCommand: "parseAndSpellcheck",
oParam: { sText: sText, sCountry: "FR", bDebug: false, bContext: false },
oInfo: { sDestination: sDestination }
});
},
|
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
|
/*
Commands received from the context menu
(Context menu are initialized in background)
*/
// Grammar checker commands
case "grammar_checker_editable":
if (oGrammalecte.xRightClickedNode !== null) {
oGrammalecte.startGCPanel(oGrammalecte.xRightClickedNode);
} else {
oGrammalecte.showMessage("Erreur. Le node sur lequel vous avez cliqué n’a pas pu être identifié. Sélectionnez le texte à corriger et relancez le correcteur via le menu contextuel.");
}
break;
case "grammar_checker_page":
oGrammalecte.startGCPanel(oGrammalecte.getPageText());
break;
|
>
|
|
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
|
/*
Commands received from the context menu
(Context menu are initialized in background)
*/
// Grammar checker commands
case "grammar_checker_editable":
if (oGrammalecte.xRightClickedNode !== null) {
let xNode = oGrammalecte.findOriginEditableNode(oGrammalecte.xRightClickedNode);
oGrammalecte.startGCPanel(xNode);
} else {
oGrammalecte.showMessage("Erreur. Le node sur lequel vous avez cliqué n’a pas pu être identifié. Sélectionnez le texte à corriger et relancez le correcteur via le menu contextuel.");
}
break;
case "grammar_checker_page":
oGrammalecte.startGCPanel(oGrammalecte.getPageText());
break;
|
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
|
/*
Other messages from background
*/
listen2: function () {
browser.runtime.onMessage.addListener(function (oMessage) {
let {sActionRequest} = oMessage;
let xActiveNode = document.activeElement;
switch (sActionRequest) {
/*
Commands received from the keyboard (shortcuts)
*/
case "shortcutGrammarChecker":
if (xActiveNode && (xActiveNode.tagName == "TEXTAREA" || xActiveNode.tagName == "INPUT" || xActiveNode.isContentEditable)) {
oGrammalecte.startGCPanel(xActiveNode);
|
|
|
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
|
/*
Other messages from background
*/
listen2: function () {
browser.runtime.onMessage.addListener(function (oMessage) {
let {sActionRequest} = oMessage;
let xActiveNode = oGrammalecte.findOriginEditableNode(document.activeElement);
switch (sActionRequest) {
/*
Commands received from the keyboard (shortcuts)
*/
case "shortcutGrammarChecker":
if (xActiveNode && (xActiveNode.tagName == "TEXTAREA" || xActiveNode.tagName == "INPUT" || xActiveNode.isContentEditable)) {
oGrammalecte.startGCPanel(xActiveNode);
|