Move and rename utilStringHashCode
options.js is the only place it's used.
This commit is contained in:
parent
51e17b35e3
commit
cdd817a0e1
@ -15,14 +15,23 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* global
|
|
||||||
* utilStringHashCode
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Generic options functions
|
* 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) {
|
function optionsGenericApplyUpdates(options, updates) {
|
||||||
const targetVersion = updates.length;
|
const targetVersion = updates.length;
|
||||||
const currentVersion = options.version;
|
const currentVersion = options.version;
|
||||||
@ -63,12 +72,12 @@ const profileOptionsVersionUpdates = [
|
|||||||
options.anki.fieldTemplates = null;
|
options.anki.fieldTemplates = null;
|
||||||
},
|
},
|
||||||
(options) => {
|
(options) => {
|
||||||
if (utilStringHashCode(options.anki.fieldTemplates) === 1285806040) {
|
if (optionsGetStringHashCode(options.anki.fieldTemplates) === 1285806040) {
|
||||||
options.anki.fieldTemplates = null;
|
options.anki.fieldTemplates = null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
(options) => {
|
(options) => {
|
||||||
if (utilStringHashCode(options.anki.fieldTemplates) === -250091611) {
|
if (optionsGetStringHashCode(options.anki.fieldTemplates) === -250091611) {
|
||||||
options.anki.fieldTemplates = null;
|
options.anki.fieldTemplates = null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -87,7 +96,7 @@ const profileOptionsVersionUpdates = [
|
|||||||
(options) => {
|
(options) => {
|
||||||
// Version 12 changes:
|
// Version 12 changes:
|
||||||
// The preferred default value of options.anki.fieldTemplates has been changed to null.
|
// 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;
|
options.anki.fieldTemplates = null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -58,19 +58,6 @@ function utilBackgroundFunctionIsolate(func) {
|
|||||||
return backgroundPage.utilFunctionIsolate(func);
|
return backgroundPage.utilFunctionIsolate(func);
|
||||||
}
|
}
|
||||||
|
|
||||||
function utilStringHashCode(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 utilBackend() {
|
function utilBackend() {
|
||||||
const backend = chrome.extension.getBackgroundPage().yomichanBackend;
|
const backend = chrome.extension.getBackgroundPage().yomichanBackend;
|
||||||
if (!backend.isPrepared) {
|
if (!backend.isPrepared) {
|
||||||
|
Loading…
Reference in New Issue
Block a user