1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
-
+
|
// JavaScript
"use strict";
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
//const Cu = Components.utils;
//const { require } = Cu.import("resource://gre/modules/commonjs/toolkit/require.js", {});
const { BasePromiseWorker } = ChromeUtils.import('resource://gre/modules/PromiseWorker.jsm', {});
const Task = ChromeUtils.import("resource://gre/modules/Task.jsm").Task;
const prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService).getBranch("extensions.grammarchecker.");
//const text = require("resource://grammalecte/text.js");
|
︙ | | |
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
-
|
}
return nParagraph;
}).then(function (res) {
that.setInfo("Nombre de paragraphes analysés : " + res);
}, function (e) {
that.setInfo("Erreur : " + e.message);
console.error(e);
// Cu.reportError(e);
});
},
createResultNode: function (xEditor, sParagraph, iParagraph, aGrammErr, aSpellErr) {
let xResultNode = document.createElement("div");
xResultNode.setAttribute("id", "resnode" + iParagraph);
this.fillResultNode(xResultNode, xEditor, sParagraph, iParagraph, aGrammErr, aSpellErr);
return xResultNode;
|
︙ | | |
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
-
|
}
}, function (res) {
xResultNode.textContent = "Erreur: " + res;
});
}
catch (e) {
console.error(e);
// Cu.reportError(e);
}
},
fillResultNode: function (xResultNode, xEditor, sParagraph, iParagraph, aGrammErr, aSpellErr) {
try {
if (aGrammErr.length === 0 && aSpellErr.length === 0) {
return null;
}
|
︙ | | |
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
243
244
245
246
247
248
249
250
251
252
253
254
255
256
|
-
|
xResultNode.appendChild(xParagraphNode);
for (let xNode of lNodeError) {
xResultNode.appendChild(xNode);
}
}
catch (e) {
console.error(e);
// Cu.reportError(e);
xResultNode.textContent = "# Error: " + e.message;
}
},
_createNodeGCErrorDescription: function (xEditor, nError, dErr, iParagraph) {
let xNodeDiv = document.createElement("div");
let that = this;
// message
|
︙ | | |
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
|
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
|
-
-
-
-
-
|
xNavBar.currentSet = aSet.join(",");
document.persist(xNavBar.id, "currentset");
try {
BrowserToolboxCustomizeDone(true);
}
catch (e) {
console.error(e);
// Cu.reportError(e);
}
}
},
clearPreview: function() {
let xPreview = document.getElementById("grammalecte-errors");
while (xPreview.firstChild) {
xPreview.removeChild(xPreview.firstChild);
};
let xEditor = GetCurrentEditor();
if (xEditor != null) {
try {
xEditor.QueryInterface(Ci.nsIEditorStyleSheets);
xEditor.addOverrideStyleSheet("chrome://grammarchecker/content/overlay.css");
}
catch (e) {
console.error(e);
// Cu.reportError(e);
}
}
this.setInfo("[vide]");
},
setInfo: function (sText) {
document.getElementById("grammalecte-info").textContent = sText;
},
openPanel: function () {
document.getElementById("textformatter-splitter").setAttribute("state", "collapsed");
document.getElementById("grammarchecker-splitter").setAttribute("state", "open");
},
closePanel: function () {
document.getElementById("grammarchecker-splitter").setAttribute("state", "collapsed");
},
openDialog: function (sWhat, sName="", sOptions="") {
try {
window.openDialog(sWhat, sName, sOptions);
}
catch (e) {
console.error(e);
// Cu.reportError(e);
}
},
openInTabURL: function (sURL) {
// method found in S3.Google.Translator
try {
let xWM = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
let xWin = xWM.getMostRecentWindow("mail:3pane");
let xTabmail = xWin.document.getElementById('tabmail');
xWin.focus();
if (xTabmail) {
xTabmail.openTab('contentTab', { contentPage: sURL });
}
}
catch (e) {
console.error(e);
// Cu.reportError(e);
}
},
openInBrowserURL: function (sURL) {
// method found in S3.Google.Translator
try {
openURL(sURL);
}
catch (e) {
console.error(e);
// Cu.reportError(e);
}
},
onParseText: function (e) {
this.parse();
},
onClosePanel: function (e) {
this.closePanel();
|
︙ | | |
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
|
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
|
-
-
-
|
},
_setDictionary: function (sDicName, sOptName) {
try {
oSpellControl.setExtensionDictFolder(sDicName, prefs.getBoolPref(sOptName));
}
catch (e) {
console.error(e);
// Cu.reportError(e);
}
}
}
var oTextFormatter = {
init: function () {
try {
this.closePanel();
let sTFOptions = prefs.getCharPref("sTFOptions");
if (sTFOptions !== "") {
this.setOptionsInPanel(JSON.parse(sTFOptions));
this.resetProgressBar();
} else {
this.reset();
}
}
catch (e) {
console.error(e);
// Cu.reportError(e);
}
},
apply: function () {
try {
this.saveOptions();
this.resetProgressBar();
let xEditor = new Editor();
let sText = xEditor.getContent();
let iParagraph = 0;
sText = this.applyOptions(sText);
for (let sParagraph of text.getParagraph(sText)) {
xEditor.writeParagraph(iParagraph, sParagraph);
iParagraph += 1;
}
}
catch (e) {
console.error(e);
// Cu.reportError(e);
}
},
saveOptions: function () {
let oOptions = {};
for (let xNode of document.getElementsByClassName("option")) {
oOptions[xNode.id] = xNode.checked;
}
|
︙ | | |
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
|
597
598
599
600
601
602
603
604
605
606
607
608
609
610
|
-
|
if (xNode.id.startsWith("o_group_")) {
this.switchGroup(xNode.id);
}
}
}
catch (e) {
console.error(e);
// Cu.reportError(e);
}
},
resetProgressBar: function () {
document.getElementById('progressbar').value = 0;
document.getElementById('time_res').textContent = "";
},
getTimeRes: function (n) {
|
︙ | | |
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
|
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
|
-
-
|
//window.setCursor("auto"); // restore pointer
const t1 = Date.now();
document.getElementById('time_res').textContent = this.getTimeRes((t1-t0)/1000);
}
catch (e) {
console.error(e);
// Cu.reportError(e);
}
return sText;
},
formatText: function (sText, sOptName) {
let nCount = 0;
try {
if (!oReplTable.hasOwnProperty(sOptName)) {
console.log("# Error. TF: there is no option “" + sOptName+ "”.");
return [sText, nCount];
}
for (let [zRgx, sRep] of oReplTable[sOptName]) {
nCount += (sText.match(zRgx) || []).length;
sText = sText.replace(zRgx, sRep);
}
}
catch (e) {
console.error(e);
// Cu.reportError(e);
}
return [sText, nCount];
}
}
/* EVENTS */
|
︙ | | |