diff options
author | Alex Yatskov <FooSoft@users.noreply.github.com> | 2019-09-15 11:34:34 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-15 11:34:34 -0700 |
commit | 58778612778df944628b4697dc51caccbeb22f79 (patch) | |
tree | 9310c68c2a8a5604a0ee6ca78ecfaa937f165abe | |
parent | e4fa658295e2149c63a51d623773bf348f21f0c5 (diff) | |
parent | 6358b655aef94279133550c93a944dbe785cee44 (diff) |
Merge pull request #213 from toasted-nutbread/options-isolation
Isolate options objects created via settings.js
-rw-r--r-- | ext/bg/js/settings.js | 20 | ||||
-rw-r--r-- | ext/bg/js/util.js | 5 |
2 files changed, 17 insertions, 8 deletions
diff --git a/ext/bg/js/settings.js b/ext/bg/js/settings.js index 7f3e5c69..3d581ba5 100644 --- a/ext/bg/js/settings.js +++ b/ext/bg/js/settings.js @@ -60,7 +60,7 @@ async function formRead(options) { const optionsAnkiEnableOld = options.anki.enable; options.anki.enable = $('#anki-enable').prop('checked'); - options.anki.tags = $('#card-tags').val().split(/[,; ]+/); + options.anki.tags = utilBackgroundIsolate($('#card-tags').val().split(/[,; ]+/)); options.anki.sentenceExt = parseInt($('#sentence-detection-extent').val(), 10); options.anki.server = $('#interface-server').val(); options.anki.screenshot.format = $('#screenshot-format').val(); @@ -70,20 +70,20 @@ async function formRead(options) { if (optionsAnkiEnableOld && !ankiErrorShown()) { options.anki.terms.deck = $('#anki-terms-deck').val(); options.anki.terms.model = $('#anki-terms-model').val(); - options.anki.terms.fields = ankiFieldsToDict($('#terms .anki-field-value')); + options.anki.terms.fields = utilBackgroundIsolate(ankiFieldsToDict($('#terms .anki-field-value'))); options.anki.kanji.deck = $('#anki-kanji-deck').val(); options.anki.kanji.model = $('#anki-kanji-model').val(); - options.anki.kanji.fields = ankiFieldsToDict($('#kanji .anki-field-value')); + options.anki.kanji.fields = utilBackgroundIsolate(ankiFieldsToDict($('#kanji .anki-field-value'))); } options.general.mainDictionary = $('#dict-main').val(); $('.dict-group').each((index, element) => { const dictionary = $(element); - options.dictionaries[dictionary.data('title')] = { + options.dictionaries[dictionary.data('title')] = utilBackgroundIsolate({ priority: parseInt(dictionary.find('.dict-priority').val(), 10), enabled: dictionary.find('.dict-enabled').prop('checked'), allowSecondarySearches: dictionary.find('.dict-allow-secondary-searches').prop('checked') - }; + }); }); } @@ -426,7 +426,7 @@ async function onDictionaryPurge(e) { await utilDatabasePurge(); const optionsContext = getOptionsContext(); const options = await apiOptionsGet(optionsContext); - options.dictionaries = {}; + options.dictionaries = utilBackgroundIsolate({}); options.general.mainDictionary = ''; await settingsSaveOptions(); @@ -468,7 +468,11 @@ async function onDictionaryImport(e) { const summary = await utilDatabaseImport(e.target.files[0], updateProgress, exceptions); const optionsContext = getOptionsContext(); const options = await apiOptionsGet(optionsContext); - options.dictionaries[summary.title] = {enabled: true, priority: 0, allowSecondarySearches: false}; + options.dictionaries[summary.title] = utilBackgroundIsolate({ + enabled: true, + priority: 0, + allowSecondarySearches: false + }); if (summary.sequenced && options.general.mainDictionary === '') { options.general.mainDictionary = summary.title; } @@ -621,7 +625,7 @@ async function onAnkiModelChanged(e) { const optionsContext = getOptionsContext(); const options = await apiOptionsGet(optionsContext); await formRead(options); - options.anki[tabId].fields = {}; + options.anki[tabId].fields = utilBackgroundIsolate({}); await settingsSaveOptions(); ankiSpinnerShow(true); diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js index 79229229..73a8396f 100644 --- a/ext/bg/js/util.js +++ b/ext/bg/js/util.js @@ -26,6 +26,11 @@ function utilIsolate(data) { return JSON.parse(JSON.stringify(data)); } +function utilBackgroundIsolate(data) { + const backgroundPage = chrome.extension.getBackgroundPage(); + return backgroundPage.utilIsolate(data); +} + function utilSetEqual(setA, setB) { if (setA.size !== setB.size) { return false; |