Spaces:
Running
Running
Update main.js
Browse files
main.js
CHANGED
@@ -166,6 +166,29 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
166 |
settingsModal.classList.add('hidden');
|
167 |
}
|
168 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
169 |
|
170 |
// --- INITIALIZATION ---
|
171 |
// Fetch data as soon as the app loads
|
|
|
166 |
settingsModal.classList.add('hidden');
|
167 |
}
|
168 |
});
|
169 |
+
// --- Settings Toggles Functionality ---
|
170 |
+
// Select all checkboxes that have a "data-setting" attribute
|
171 |
+
const settingToggles = settingsModal.querySelectorAll('input[data-setting]');
|
172 |
+
|
173 |
+
settingToggles.forEach(toggle => {
|
174 |
+
// On page load, set the checkbox's state from our userSettings object
|
175 |
+
const settingName = toggle.dataset.setting;
|
176 |
+
if (userSettings[settingName] !== undefined) {
|
177 |
+
toggle.checked = userSettings[settingName];
|
178 |
+
}
|
179 |
+
|
180 |
+
// Add a listener that fires whenever a toggle is changed
|
181 |
+
toggle.addEventListener('change', (event) => {
|
182 |
+
const changedSettingName = event.target.dataset.setting;
|
183 |
+
const newValue = event.target.checked;
|
184 |
+
|
185 |
+
// Update our settings object with the new value
|
186 |
+
userSettings[changedSettingName] = newValue;
|
187 |
+
|
188 |
+
// For debugging, log the entire updated settings object to the console
|
189 |
+
console.log('Settings updated:', userSettings);
|
190 |
+
});
|
191 |
+
});
|
192 |
|
193 |
// --- INITIALIZATION ---
|
194 |
// Fetch data as soon as the app loads
|