diff options
Diffstat (limited to 'ext/bg/js/util.js')
-rw-r--r-- | ext/bg/js/util.js | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js index f44582eb..216cef3f 100644 --- a/ext/bg/js/util.js +++ b/ext/bg/js/util.js @@ -26,6 +26,43 @@ function utilIsolate(data) { return JSON.parse(JSON.stringify(data)); } +function utilSetEqual(setA, setB) { + if (setA.size !== setB.size) { + return false; + } + + for (const value of setA) { + if (!setB.has(value)) { + return false; + } + } + + return true; +} + +function utilSetIntersection(setA, setB) { + return new Set( + [...setA].filter(value => setB.has(value)) + ); +} + +function utilSetDifference(setA, setB) { + return new Set( + [...setA].filter(value => !setB.has(value)) + ); +} + +function utilStringHashCode(string) { + let hashCode = 0; + + for (let i = 0, charCode = string.charCodeAt(i); i < string.length; charCode = string.charCodeAt(++i)) { + hashCode = ((hashCode << 5) - hashCode) + charCode; + hashCode |= 0; + } + + return hashCode; +} + function utilBackend() { return chrome.extension.getBackgroundPage().yomichan_backend; } @@ -38,12 +75,12 @@ function utilAnkiGetDeckNames() { return utilBackend().anki.getDeckNames(); } -function utilAnkiGetModelFieldNames(modelName) { - return utilBackend().anki.getModelFieldNames(modelName); +function utilDatabaseSummarize() { + return utilBackend().translator.database.summarize(); } -function utilDatabaseGetTitles() { - return utilBackend().translator.database.getTitles(); +function utilAnkiGetModelFieldNames(modelName) { + return utilBackend().anki.getModelFieldNames(modelName); } function utilDatabasePurge() { |