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
|
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: "",
|
>
|
>
|
>
>
|
|
>
|
|
>
>
>
>
|
|
<
<
|
|
<
|
<
|
<
<
|
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
|
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;
}
else if (this.oDictionaries && this.oDictionaries.hasOwnProperty(sName)) {
//console.log(this.oDictionaries[sName]);
return this.oDictionaries[sName];
}
return null;
},
saveDictionary: function (sName, oJSON) {
console.log(sName);
if (sName == "__personal__") {
browser.runtime.sendMessage({ sCommand: "setDictionary", dParam: {sDictionary: "personal", oDict: oJSON}, dInfo: {} });
browser.storage.local.set({ "personal_dictionary": oJSON });
}
else {
this.oDictionaries[sName] = oJSON;
browser.storage.local.set({ "shared_dictionaries": this.oDictionaries });
}
}
}
const oBinaryDict = {
oIBDAWG: null,
sName: "",
|