aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/util.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-11-04 08:18:49 -0700
committerAlex Yatskov <alex@foosoft.net>2017-11-04 08:18:49 -0700
commitd505edb94b27ecd8cbaaecd11cbebfbe12b16164 (patch)
tree44ab656f33f7eedb0e4e0c9e31e0ccceffb069e0 /ext/bg/js/util.js
parent5c0d1cc6dae358dd2c04bdaac8f30cebfad5466d (diff)
parentdcef7ce3774a3dcc8e7bee0bc17398251523451e (diff)
Merge branch 'dev'
Diffstat (limited to 'ext/bg/js/util.js')
-rw-r--r--ext/bg/js/util.js45
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() {