import $ from "jquery"; import path from "path-browserify"; import { showLightBox } from "./dom/lightbox"; import { initTopBar, TopBarButton } from "./dom/topbar"; import { getBooleanStorageVal, getStorageVal, setStorageVal } from "./storage"; import { initPostPreviews } from "./postutil"; import { closeQR, initQR } from "./dom/qr"; import { initWatcher } from "./watcher/watcher"; import { updateBrowseButton } from "./dom/uploaddata"; let $settingsButton: TopBarButton = null; const settings: Map> = new Map(); type ElementValue = string|number|string[]; class Setting { key: string; title: string; defaultVal: T; onSave: () => any; element: JQuery; /** * @param key The name of the setting * @param title text that gets shown in the Settings lightbox * @param defaultVal the setting's default value * @param onSave function that gets called when you save the settings */ constructor(key: string, title: string, defaultVal:T, onSave?:()=>any) { this.key = key; this.title = title; this.defaultVal = defaultVal; this.onSave = onSave ?? (()=>true); this.element = null; } getElementValue(): T { if(this.element === null) return this.defaultVal; return this.element.val() as T; } setElementValue(newVal: T) { if(this.element === null) return; this.element.val(newVal as ElementValue); } getStorageValue(): T { return getStorageVal(this.key, this.defaultVal as any) as T; } setStorageValue(newVal: T) { setStorageVal(this.key, newVal); this.onSave(); } createElement(selector = "", props = {}) { return $(selector).prop(props).prop({ id: this.key, name: this.key }); } } class TextSetting extends Setting { constructor(key: string, title: string, defaultVal = "", onSave?:()=>any) { super(key, title, defaultVal, onSave); this.element = this.createElement("