aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/options.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-04-18 14:12:41 -0400
committerGitHub <noreply@github.com>2020-04-18 14:12:41 -0400
commit106172e2c1261f2d685802280af580c70ac4580b (patch)
tree1e96325ee884db8c946e7401882fd7b46f3552e8 /ext/bg/js/options.js
parent9e7750125c40d1c4121e8d015957606721bede7c (diff)
parentcdd817a0e1c573b24114836a389236f49dd9b279 (diff)
Merge pull request #447 from toasted-nutbread/util-conversions
Util conversions
Diffstat (limited to 'ext/bg/js/options.js')
-rw-r--r--ext/bg/js/options.js23
1 files changed, 16 insertions, 7 deletions
diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js
index f3e5f60d..da26b628 100644
--- a/ext/bg/js/options.js
+++ b/ext/bg/js/options.js
@@ -15,14 +15,23 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-/* global
- * utilStringHashCode
- */
-
/*
* Generic options functions
*/
+function optionsGetStringHashCode(string) {
+ let hashCode = 0;
+
+ if (typeof string !== 'string') { return hashCode; }
+
+ 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 optionsGenericApplyUpdates(options, updates) {
const targetVersion = updates.length;
const currentVersion = options.version;
@@ -63,12 +72,12 @@ const profileOptionsVersionUpdates = [
options.anki.fieldTemplates = null;
},
(options) => {
- if (utilStringHashCode(options.anki.fieldTemplates) === 1285806040) {
+ if (optionsGetStringHashCode(options.anki.fieldTemplates) === 1285806040) {
options.anki.fieldTemplates = null;
}
},
(options) => {
- if (utilStringHashCode(options.anki.fieldTemplates) === -250091611) {
+ if (optionsGetStringHashCode(options.anki.fieldTemplates) === -250091611) {
options.anki.fieldTemplates = null;
}
},
@@ -87,7 +96,7 @@ const profileOptionsVersionUpdates = [
(options) => {
// Version 12 changes:
// The preferred default value of options.anki.fieldTemplates has been changed to null.
- if (utilStringHashCode(options.anki.fieldTemplates) === 1444379824) {
+ if (optionsGetStringHashCode(options.anki.fieldTemplates) === 1444379824) {
options.anki.fieldTemplates = null;
}
},