newsfeed
This commit is contained in:
parent
d64cc3fbf2
commit
a1464bb865
20 changed files with 636 additions and 193 deletions
35
static/js/settings.js
Normal file
35
static/js/settings.js
Normal file
|
@ -0,0 +1,35 @@
|
|||
const settingsKey = "treehouse.settings";
|
||||
const settings = JSON.parse(localStorage.getItem(settingsKey)) || {};
|
||||
|
||||
const defaultSettingValues = {
|
||||
showNewPostIndicator: true,
|
||||
};
|
||||
|
||||
function saveSettings() {
|
||||
localStorage.setItem(settingsKey, JSON.stringify(settings));
|
||||
}
|
||||
|
||||
export function getSettingValue(setting) {
|
||||
return settings[setting] ?? defaultSettingValues[setting];
|
||||
}
|
||||
|
||||
class SettingCheckbox extends HTMLInputElement {
|
||||
connectedCallback() {
|
||||
this.checked = getSettingValue(this.id);
|
||||
|
||||
this.addEventListener("change", () => {
|
||||
settings[this.id] = this.checked;
|
||||
saveSettings();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
customElements.define("th-setting-checkbox", SettingCheckbox, { extends: "input" });
|
||||
|
||||
class Settings extends HTMLElement {
|
||||
connectedCallback() {
|
||||
this.style.display = "block";
|
||||
}
|
||||
}
|
||||
|
||||
customElements.define("th-settings", Settings, { extends: "section" });
|
Loading…
Add table
Add a link
Reference in a new issue