summaryrefslogtreecommitdiff
path: root/ext/bg/js
diff options
context:
space:
mode:
authorsiikamiika <siikamiika@users.noreply.github.com>2017-10-18 23:40:56 +0300
committersiikamiika <siikamiika@users.noreply.github.com>2017-10-18 23:40:56 +0300
commit7e556e8d32251844723d665cec54a9a69ad94e76 (patch)
tree7d535fdf8c9ddbd748214821429d76513cc26e83 /ext/bg/js
parentb59980067a7698199d2466ecbeebc6ad5253ed02 (diff)
field template fixup for modified templates only
Diffstat (limited to 'ext/bg/js')
-rw-r--r--ext/bg/js/options.js14
-rw-r--r--ext/bg/js/util.js15
2 files changed, 24 insertions, 5 deletions
diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js
index c56c1945..00981096 100644
--- a/ext/bg/js/options.js
+++ b/ext/bg/js/options.js
@@ -269,11 +269,15 @@ function optionsVersion(options) {
}
options.general.compactTags = false;
options.general.compactGlossaries = false;
- options.anki.fieldTemplates = '{{#if merge}}\n' +
- optionsFieldTemplates() +
- '\n{{else}}\n' +
- options.anki.fieldTemplates +
- '\n{{/if}}';
+ if (utilStringHashCode(options.anki.fieldTemplates) !== -1895236672) { // a3c8508031a1073629803d0616a2ee416cd3cccc
+ options.anki.fieldTemplates = '{{#if merge}}\n' +
+ optionsFieldTemplates() +
+ '\n{{else}}\n' +
+ options.anki.fieldTemplates +
+ '\n{{/if}}';
+ } else {
+ options.anki.fieldTemplates = optionsFieldTemplates();
+ }
}
];
diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js
index 9a3a2a3e..88d96688 100644
--- a/ext/bg/js/util.js
+++ b/ext/bg/js/util.js
@@ -52,6 +52,21 @@ function utilSetDifference(setA, setB) {
);
}
+function utilStringHashCode(string) {
+ let hashCode = 0;
+
+ if (string.length === 0) {
+ return hashCode;
+ }
+
+ for (let i = 0, charCode = string.charCodeAt(i); i < string.length; i++) {
+ hashCode = ((hashCode << 5) - hashCode) + charCode;
+ hashCode |= 0;
+ }
+
+ return hashCode;
+}
+
function utilBackend() {
return chrome.extension.getBackgroundPage().yomichan_backend;
}