diff options
author | 0neGal <mail@0negal.com> | 2022-02-21 19:31:33 +0100 |
---|---|---|
committer | 0neGal <mail@0negal.com> | 2022-02-21 19:35:56 +0100 |
commit | 132fea11e3599c9c2c9df8a69fd4d093033788ba (patch) | |
tree | c4a47181d3a65461c3d4448542639dd7dc953d36 /src/app/settings.js | |
parent | 43122069a282f4594653ede9402ba330b7f39e84 (diff) | |
download | Viper-132fea11e3599c9c2c9df8a69fd4d093033788ba.tar.gz Viper-132fea11e3599c9c2c9df8a69fd4d093033788ba.zip |
some functionality is now present
Albeit only frontend functionality, it doesn't actually save your
settings, it simply loads them, and Settings.get(), allows you to
convert them to a format that can be used to save settings.
Diffstat (limited to 'src/app/settings.js')
-rw-r--r-- | src/app/settings.js | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/src/app/settings.js b/src/app/settings.js index c9e43ae..e558d61 100644 --- a/src/app/settings.js +++ b/src/app/settings.js @@ -1,6 +1,7 @@ var Settings = { toggle: (state) => { if (state) { + Settings.load(); options.scrollTo(0, 0); overlay.classList.add("shown") options.classList.add("shown") @@ -14,6 +15,7 @@ var Settings = { } } + Settings.load(); options.scrollTo(0, 0); overlay.classList.toggle("shown") options.classList.toggle("shown") @@ -39,8 +41,60 @@ var Settings = { } Settings.reloadSwitches(); + }, + get: () => { + let opts = {}; + let options = document.querySelectorAll(".option"); + + for (let i = 0; i < options.length; i++) { + let optName = options[i].getAttribute("name"); + if (options[i].querySelector(".actions input")) { + let input = options[i].querySelector(".actions input").value; + if (options[i].getAttribute("type")) { + opts[optName] = input.split(" "); + } else { + opts[optName] = input; + } + } else if (options[i].querySelector(".actions .switch")) { + if (options[i].querySelector(".actions .switch.on")) { + opts[optName] = true; + } else { + opts[optName] = false; + } + } + } + + return opts; + }, + load: () => { + let options = document.querySelectorAll(".option"); + + for (let i = 0; i < options.length; i++) { + let optName = options[i].getAttribute("name"); + if (settings[optName] != undefined) { + switch(typeof settings[optName]) { + case "string": + options[i].querySelector(".actions input").value = settings[optName]; + break + case "object": + options[i].querySelector(".actions input").value = settings[optName].join(" "); + break + case "boolean": + let switchDiv = options[i].querySelector(".actions .switch"); + if (settings[optName]) { + switchDiv.classList.add("on"); + switchDiv.classList.remove("off"); + } else { + switchDiv.classList.add("off"); + switchDiv.classList.remove("on"); + } + break + + } + } + } } } Settings.reloadSwitches(); - +Settings.load(); |