summaryrefslogtreecommitdiff
path: root/assets
diff options
context:
space:
mode:
authorEltrac <hi@guhub.cn>2025-09-10 19:32:10 +0800
committerEltrac <hi@guhub.cn>2025-09-10 19:32:10 +0800
commitcac65038abbd13e2891f0084499ee82d9c67fb72 (patch)
tree997a0c20a4a6ee4ec155876eb53ae7cf1ccb4941 /assets
parent418bb07285241d41d9007d7ff0fb7f9fa35fcb03 (diff)
style: less redundant code and clearer logic
Diffstat (limited to 'assets')
-rw-r--r--assets/js/settings.js17
1 files changed, 8 insertions, 9 deletions
diff --git a/assets/js/settings.js b/assets/js/settings.js
index f785a705..a640ca24 100644
--- a/assets/js/settings.js
+++ b/assets/js/settings.js
@@ -60,7 +60,6 @@
// initialize checkbox options
function initCheckboxes() {
- const checkboxes = document.querySelectorAll('#checkbox-options input[type="checkbox"]');
const checkboxOptions = [
{
id: 'dontAllowTracking',
@@ -84,6 +83,14 @@
element.checked = localStorage.getItem(checkboxOption.storage) ||
checkboxOption.default === 'true';
+ // add event listener to checkbox
+ element.addEventListener('change', () => {
+ if (element.checked)
+ localStorage.setItem(checkboxOption.storage, 1);
+ else
+ localStorage.removeItem(checkboxOption.storage);
+ });
+
// create label
const label = document.createElement('label');
label.htmlFor = element.id;
@@ -95,14 +102,6 @@
wrapper.appendChild(element);
wrapper.appendChild(label);
- // add event listener to checkbox
- element.addEventListener('change', () => {
- if (element.checked)
- localStorage.setItem(checkboxOption.storage, 1);
- else
- localStorage.removeItem(checkboxOption.storage);
- });
-
// append checkbox and label to container
const container = document.getElementById('checkbox-options');
container.appendChild(wrapper);