︙ | | | ︙ | |
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
Common functions
*/
function showError (e) {
console.error(e.fileName + "\n" + e.name + "\nline: " + e.lineNumber + "\n" + e.message);
}
function createNode (sType, oAttr, oDataset=null) {
try {
let xNode = document.createElement(sType);
Object.assign(xNode, oAttr);
if (oDataset) {
Object.assign(xNode.dataset, oDataset);
}
return xNode;
|
|
|
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
Common functions
*/
function showError (e) {
console.error(e.fileName + "\n" + e.name + "\nline: " + e.lineNumber + "\n" + e.message);
}
function createNode (sType, oAttr, oDataset=null) {
try {
let xNode = document.createElement(sType);
Object.assign(xNode, oAttr);
if (oDataset) {
Object.assign(xNode.dataset, oDataset);
}
return xNode;
|
︙ | | | ︙ | |
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
|
catch (e) {
showError(e);
}
}
}
const oDictHandler = {
oDictionaries: null,
oPersonalDictionary: null,
loadDictionaries: function () {
if (bChrome) {
browser.storage.local.get("shared_dictionaries", this._loadDictionaries.bind(this));
browser.storage.local.get("personal_dictionary", this._loadDictionaries.bind(this));
return;
}
let xPromise = browser.storage.local.get("shared_dictionaries");
xPromise.then(this._loadDictionaries.bind(this), showError);
let xPromise2 = browser.storage.local.get("personal_dictionary");
xPromise2.then(this._loadDictionaries.bind(this), showError);
},
_loadDictionaries: function (oResult) {
if (oResult.hasOwnProperty("shared_dictionaries")) {
this.oDictionaries = oResult.shared_dictionaries;
}
if (oResult.hasOwnProperty("personal_dictionary")) {
this.oPersonalDictionary = oResult.personal_dictionary;
oBinaryDict.load("__personal__");
}
},
getDictionary: function (sName) {
if (sName == "__personal__") {
return this.oPersonalDictionary;
}
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
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
|
catch (e) {
showError(e);
}
}
}
const oDictHandler = {
oDictionaries: {},
oPersonalDictionary: null,
lCreatedDictionaries: [],
xDicSelector: document.getElementById("dic_selector"),
loadDictionaries: function () {
if (bChrome) {
browser.storage.local.get("shared_dictionaries", this._loadDictionaries.bind(this));
browser.storage.local.get("personal_dictionary", this._loadDictionaries.bind(this));
browser.storage.local.get("created_dictionaries_list", this._loadDictionaries.bind(this));
return;
}
let xPromise = browser.storage.local.get("shared_dictionaries");
xPromise.then(this._loadDictionaries.bind(this), showError);
let xPromise2 = browser.storage.local.get("personal_dictionary");
xPromise2.then(this._loadDictionaries.bind(this), showError);
let xPromise3 = browser.storage.local.get("created_dictionaries_list");
xPromise3.then(this._loadDictionaries.bind(this), showError);
},
_loadDictionaries: function (oResult) {
if (oResult.hasOwnProperty("shared_dictionaries")) {
this.oDictionaries = oResult.shared_dictionaries;
}
if (oResult.hasOwnProperty("personal_dictionary")) {
this.oPersonalDictionary = oResult.personal_dictionary;
oBinaryDict.load("__personal__");
}
if (oResult.hasOwnProperty("created_dictionaries_list")) {
this.lCreatedDictionaries = oResult.created_dictionaries_list;
for (let sDicName of this.lCreatedDictionaries) {
let xOption = createNode("option", {value: sDicName, textContent: sDicName});
this.xDicSelector.appendChild(xOption);
}
}
},
addDictionary: function (sDicName) {
if (!this.oDictionaries.hasOwnProperty(sDicName)) {
let xOption = createNode("option", {value: sDicName, textContent: sDicName});
this.xDicSelector.appendChild(xOption);
this.xDicSelector.selectedIndex = this.xDicSelector.options.length-1;
this.lCreatedDictionaries.push(sDicName);
browser.storage.local.set({ "created_dictionaries_list": this.lCreatedDictionaries });
}
},
deleteDictionary: function (sDicName) {
this.saveDictionary(sDicName, null);
if (sDicName != "__personal__") {
let iDict = this.lCreatedDictionaries.indexOf(sDicName);
if (iDict > -1) {
this.lCreatedDictionaries.splice(iDict, 1);
}
browser.storage.local.set({ "created_dictionaries_list": this.lCreatedDictionaries });
for (let xNode of this.xDicSelector.childNodes) {
if (xNode.value == sDicName) {
this.xDicSelector.removeChild(xNode);
}
}
this.xDicSelector.selectedIndex = 0;
oBinaryDict.load("__personal__");
}
},
getDictionary: function (sName) {
if (sName == "__personal__") {
return this.oPersonalDictionary;
}
|
︙ | | | ︙ | |
571
572
573
574
575
576
577
578
579
580
581
582
583
584
|
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);
|
>
>
>
>
>
>
>
>
>
>
>
>
>
|
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
|
this.parseDict(oJSON);
} else {
oLexiconTable.clear();
this.setDictData(0, "[néant]");
hideElement("save_button");
}
},
newDictionary: function () {
this.oIBDAWG = null;
this.sName = document.getElementById("new_dictionary_name").value;
this.sDescription = document.getElementById("new_dictionary_description").value;
oDictHandler.addDictionary(this.sName);
oLexiconTable.clear();
this.setDictData(0, "[néant]");
hideElement("save_button");
document.getElementById("new_dictionary_name").value = "";
document.getElementById("new_dictionary_description").value = "";
hideElement("new_dictionary_section")
},
parseDict: function (oJSON) {
try {
this.oIBDAWG = new IBDAWG(oJSON);
}
catch (e) {
console.error(e);
|
︙ | | | ︙ | |
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
|
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);
document.getElementById("new_dictionary_button").addEventListener("click", () => { switchDisplay("new_dictionary_section"); }, false);
document.getElementById("delete_dictionary_button").addEventListener("click", () => { this.delete() }, 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, this.sDescription, xProgressNode);
|
|
>
|
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
|
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);
document.getElementById("new_dictionary_button").addEventListener("click", () => { switchDisplay("new_dictionary_section"); }, false);
document.getElementById("delete_dictionary_button").addEventListener("click", () => { this.delete(); }, false);
document.getElementById("create_dictionary_button").addEventListener("click", () => { this.newDictionary(); }, 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, this.sDescription, xProgressNode);
|
︙ | | | ︙ | |
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
|
}
hideElement("save_button");
},
delete: function () {
if (confirm("Voulez-vous effacer le dictionnaire “"+this.sName+"” ?")) {
oLexiconTable.clear();
oDictHandler.saveDictionary(this.sName, null);
this.setDictData(0, "[néant]");
if (this.sName != "__personal__") {
this.load("__personal__");
}
}
},
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 });
|
<
|
<
<
|
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
|
}
hideElement("save_button");
},
delete: function () {
if (confirm("Voulez-vous effacer le dictionnaire “"+this.sName+"” ?")) {
oLexiconTable.clear();
this.setDictData(0, "[néant]");
oDictHandler.deleteDictionary(this.sName);
}
},
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 });
|
︙ | | | ︙ | |