478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
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
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
|
try {
oLexiconTable.addEntries(this.createFlexLemmaTagArray());
oGenWordsTable.clear();
document.getElementById("lemma").value = "";
document.getElementById("lemma").focus();
this.hideAllSections();
hideElement("editor");
showElement("save_button");
this.clear();
this.cMainTag = "";
}
catch (e) {
showError(e);
}
}
}
const oBinaryDict = {
oIBDAWG: null,
load: function () {
if (bChrome) {
browser.storage.local.get("oPersonalDictionary", this._load.bind(this));
return;
}
let xPromise = browser.storage.local.get("oPersonalDictionary");
xPromise.then(this._load.bind(this), showError);
},
_load: function (oResult) {
if (!oResult.hasOwnProperty("oPersonalDictionary")) {
hideElement("export_button");
return;
}
let oJSON = oResult.oPersonalDictionary;
if (oJSON) {
this.__load(oJSON);
} else {
oLexiconTable.clear();
this.setDictData(0, "[néant]");
}
},
__load: function (oJSON) {
try {
this.oIBDAWG = new IBDAWG(oJSON);
}
catch (e) {
console.error(e);
this.setDictData(0, "#Erreur. Voir la console.");
return;
}
let lEntry = [];
for (let aRes of this.oIBDAWG.select()) {
lEntry.push(aRes);
}
oLexiconTable.fill(lEntry);
this.setDictData(this.oIBDAWG.nEntry, this.oIBDAWG.sDate);
},
save: function (oJSON) {
browser.storage.local.set({ "oPersonalDictionary": oJSON });
browser.runtime.sendMessage({ sCommand: "setDictionary", dParam: {sDictionary: "personal", oDict: oJSON}, dInfo: {} });
},
import: function () {
let xInput = document.getElementById("import_input");
let xFile = xInput.files[0];
let xURL = URL.createObjectURL(xFile);
let sJSON = helpers.loadFile(xURL);
if (sJSON) {
try {
let oJSON = JSON.parse(sJSON);
this.__load(oJSON);
this.save(oJSON);
}
catch (e) {
console.error(e);
this.setDictData(0, "#Erreur. Voir la console.");
return;
}
} else {
this.setDictData(0, "[néant]");
this.save(null);
}
},
setDictData: function (nEntries, sDate) {
document.getElementById("dic_num_entries").textContent = nEntries;
document.getElementById("dic_save_date").textContent = sDate;
if (nEntries == 0) {
hideElement("export_button");
} else {
showElement("export_button");
}
},
listen: function () {
document.getElementById("save_button").addEventListener("click", () => { this.build(); }, false);
document.getElementById("export_button").addEventListener("click", () => { this.export(); }, false);
document.getElementById("import_input").addEventListener("change", () => { this.import(); }, false);
},
build: function () {
let xProgressNode = document.getElementById("wait_progress");
let lEntry = oLexiconTable.getEntries();
if (lEntry.length > 0) {
let oDAWG = new DAWG(lEntry, "S", "fr", "Français", "fr.personal", xProgressNode);
let oJSON = oDAWG.createBinaryJSON(1);
this.save(oJSON);
this.oIBDAWG = new IBDAWG(oJSON);
this.setDictData(this.oIBDAWG.nEntry, this.oIBDAWG.sDate);
} else {
this.setDictData(0, "[néant]");
this.save(null);
}
hideElement("save_button");
},
export: function () {
let xBlob = new Blob([ JSON.stringify(this.oIBDAWG.getJSON()) ], {type: 'application/json'});
let sURL = URL.createObjectURL(xBlob);
browser.downloads.download({ filename: "fr.personal.json", url: sURL, saveAs: true });
}
}
const oSearch = {
oSpellChecker: null,
|
|
|
<
<
|
|
|
|
|
|
|
>
>
>
>
>
|
>
>
>
>
>
|
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
|
<
|
<
<
<
|
|
|
>
|
|
>
<
|
|
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
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
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
|
try {
oLexiconTable.addEntries(this.createFlexLemmaTagArray());
oGenWordsTable.clear();
document.getElementById("lemma").value = "";
document.getElementById("lemma").focus();
this.hideAllSections();
hideElement("editor");
showElement("save_button", "inline-block");
this.clear();
this.cMainTag = "";
}
catch (e) {
showError(e);
}
}
}
const oDictHandler = {
oDictionaries: null,
loadDictionaries: function () {
if (bChrome) {
browser.storage.local.get("dictionaries", this._loadDictionaries.bind(this));
return;
}
let xPromise = browser.storage.local.get("dictionaries");
xPromise.then(this._loadDictionaries.bind(this), showError);
},
_loadDictionaries: function (oResult) {
if (!oResult.hasOwnProperty("dictionaries")) {
return;
}
this.oDictionaries = oResult.dictionaries;
oBinaryDict.load("__personal__");
},
getDictionary: function (sName) {
if (this.oDictionaries && this.oDictionaries.hasOwnProperty(sName)) {
//console.log(this.oDictionaries[sName]);
return this.oDictionaries[sName];
}
return null;
},
saveDictionary: function (sName, oJSON) {
this.oDictionaries[sName] = oJSON;
if (sName == "__personal__") {
browser.runtime.sendMessage({ sCommand: "setDictionary", dParam: {sDictionary: "personal", oDict: oJSON}, dInfo: {} });
}
else if (sName == "__community__") {
browser.runtime.sendMessage({ sCommand: "setDictionary", dParam: {sDictionary: "community", oDict: oJSON}, dInfo: {} });
}
else {
// TODO: merge sub-dictionaries
}
this.storeDictionaries();
},
storeDictionaries: function () {
browser.storage.local.set({ "dictionaries": this.oDictionaries });
}
}
const oBinaryDict = {
oIBDAWG: null,
sName: null,
load: function (sName) {
console.log("lexicon editor, load: " + sName);
this.sName = sName;
let oJSON = oDictHandler.getDictionary(sName);
if (oJSON) {
this.parseDict(oJSON);
} else {
oLexiconTable.clear();
this.setDictData(0, "[néant]");
hideElement("save_button");
}
},
parseDict: function (oJSON) {
try {
this.oIBDAWG = new IBDAWG(oJSON);
}
catch (e) {
console.error(e);
this.setDictData(0, "#Erreur. Voir la console.");
return;
}
let lEntry = [];
for (let aRes of this.oIBDAWG.select()) {
lEntry.push(aRes);
}
oLexiconTable.fill(lEntry);
this.setDictData(this.oIBDAWG.nEntry, this.oIBDAWG.sDate);
hideElement("save_button");
},
import: function () {
let xInput = document.getElementById("import_input");
let xFile = xInput.files[0];
let xURL = URL.createObjectURL(xFile);
let sJSON = helpers.loadFile(xURL);
if (sJSON) {
try {
let oJSON = JSON.parse(sJSON);
this.parseDict(oJSON);
oDictHandler.saveDictionary(this.sName, oJSON);
}
catch (e) {
console.error(e);
this.setDictData(0, "#Erreur. Voir la console.");
return;
}
} else {
this.setDictData(0, "[néant]");
oDictHandler.saveDictionary(this.sName, null);
}
},
setDictData: function (nEntries, sDate) {
document.getElementById("dic_num_entries").textContent = nEntries;
document.getElementById("dic_save_date").textContent = sDate;
if (nEntries == 0) {
hideElement("export_button");
} else {
showElement("export_button");
}
},
listen: function () {
document.getElementById("dic_selector").addEventListener("change", () => {this.load(document.getElementById("dic_selector").value)}, false);
document.getElementById("save_button").addEventListener("click", () => { this.build(); }, false);
document.getElementById("export_button").addEventListener("click", () => { this.export(); }, false);
document.getElementById("import_input").addEventListener("change", () => { this.import(); }, false);
},
build: function () {
let xProgressNode = document.getElementById("wait_progress");
let lEntry = oLexiconTable.getEntries();
if (lEntry.length > 0) {
let oDAWG = new DAWG(lEntry, "S", "fr", "Français", this.sName, xProgressNode);
let oJSON = oDAWG.createBinaryJSON(1);
oDictHandler.saveDictionary(this.sName, oJSON);
this.oIBDAWG = new IBDAWG(oJSON);
this.setDictData(this.oIBDAWG.nEntry, this.oIBDAWG.sDate);
} else {
oDictHandler.saveDictionary(this.sName, null);
this.setDictData(0, "[néant]");
}
hideElement("save_button");
},
export: function () {
let xBlob = new Blob([ JSON.stringify(this.oIBDAWG.getJSON()) ], {type: 'application/json'});
let sURL = URL.createObjectURL(xBlob);
browser.downloads.download({ filename: "fr."+this.sName+".json", url: sURL, saveAs: true });
}
}
const oSearch = {
oSpellChecker: null,
|
662
663
664
665
666
667
668
669
670
671
672
673
|
const oLexiconTable = new Table("lexicon_table", ["Flexions", "Lemmes", "Étiquettes"], "wait_progress", "num_entries");
const oSearchTable = new Table("search_table", ["Flexions", "Lemmes", "Étiquettes"], "wait_progress", "search_num_entries", false);
const oTagsTable = new Table("tags_table", ["Étiquette", "Signification"], "wait_progress", "", false);
oTagsInfo.load();
oSearch.load();
oBinaryDict.load();
oBinaryDict.listen();
oGenerator.listen();
oTabulations.listen();
oSearch.listen();
|
|
|
699
700
701
702
703
704
705
706
707
708
709
710
|
const oLexiconTable = new Table("lexicon_table", ["Flexions", "Lemmes", "Étiquettes"], "wait_progress", "num_entries");
const oSearchTable = new Table("search_table", ["Flexions", "Lemmes", "Étiquettes"], "wait_progress", "search_num_entries", false);
const oTagsTable = new Table("tags_table", ["Étiquette", "Signification"], "wait_progress", "", false);
oTagsInfo.load();
oSearch.load();
oDictHandler.loadDictionaries();
oBinaryDict.listen();
oGenerator.listen();
oTabulations.listen();
oSearch.listen();
|