diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2020-07-26 16:53:24 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-26 16:53:24 -0400 |
commit | 104650627d0dea207b5803f89d648a4363d6af8d (patch) | |
tree | 901e8d845bc262702d6fd11e9af929e44ed1e2d6 /ext/bg | |
parent | fca00045978003056af6b1cf5665f466ef1b3f08 (diff) |
Merge redundant toggle handling code (#693)
Diffstat (limited to 'ext/bg')
-rw-r--r-- | ext/bg/js/context-main.js | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/ext/bg/js/context-main.js b/ext/bg/js/context-main.js index 14013d3f..72abe554 100644 --- a/ext/bg/js/context-main.js +++ b/ext/bg/js/context-main.js @@ -61,13 +61,12 @@ async function setupOptions() { }; const options = await api.optionsGet(optionsContext); - const toggle = document.querySelector('#enable-search'); - toggle.checked = options.general.enable; - toggle.addEventListener('change', () => api.commandExec('toggle'), false); - - const toggle2 = document.querySelector('#enable-search2'); - toggle2.checked = options.general.enable; - toggle2.addEventListener('change', () => api.commandExec('toggle'), false); + const extensionEnabled = options.general.enable; + const onToggleChanged = () => api.commandExec('toggle'); + for (const toggle of document.querySelectorAll('#enable-search,#enable-search2')) { + toggle.checked = extensionEnabled; + toggle.addEventListener('change', onToggleChanged, false); + } setTimeout(() => { document.body.dataset.loaded = 'true'; |