Frontend: Refactor settings.js

Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
Fred Boniface 2023-01-23 20:25:05 +00:00
parent 018ddf8c47
commit 5e9f9e13bc
3 changed files with 12 additions and 28 deletions

View File

@ -1,16 +1,16 @@
/* Feature Detectors */
/* Valid values for ${type}: localstorage, sessionstorage */
async function storageAvailable(type) {
async function storageAvailable(type) { // Currently not used
try {
var storage = window[type],
x = '__storage_test__';
storage.setItem(x, x);
let storage = window[type];
let x = '__storage_test__';
storage.setItem(x, "test");
storage.getItem(x);
log(`lib.main.storageAvailable: ${type} is available`)
log(`lib.main.storageAvailable: ${type} is available`, "INFO")
return true;
} catch (err) {
log(`lib.main.storageAvailable: ${type} is not available`)
log(`lib.main.storageAvailable: ${type} is not available`, "ERR")
return false;
}
}

View File

@ -1,31 +1,15 @@
// Init:
const ql = ["ql0","ql1","ql2","ql3","ql4","ql5","ql6","ql7","ql8","ql9","ql10","ql11"]
checkStorageSupport();
storageAvailable("localStorage");
getQl();
clearLoading();
async function checkStorageSupport(){
if (window.localStorage){
localStorage.setItem("support-check","8441");
if (localStorage.getItem("support-check")=="8441"){
console.log("Local Storage supported.")
localStorage.removeItem("support-check")
} else if (localStorage.getItem("support-check" != "8441")){
console.log("Error fetching test value.")
}
} else {
console.log("Local Storage is not supported")
window.alert("Settings cannot be saved on your device, try updating your browser.")
}
}
hideLoading();
async function getQl(){
var qlOpt = JSON.parse(localStorage.getItem("qlOpt"))
var qlOpt = await getQuickLinks()
if (qlOpt){
var i = 0
while (i < 12) {
if (qlOpt[i] != 'undefined') {
console.log(`Setting box ql${i} to ${qlOpt[i]}`)
document.getElementById(`ql${i}`).value = qlOpt[i]
i +=1
}
@ -43,9 +27,9 @@ async function setQl(){
}
qlSet.sort()
}
console.log(qlSet)
localStorage.setItem("qlOpt", JSON.stringify(qlSet))
clearLoading();
log(`settings.setQl: User settings saved`, "INFO")
hideLoading();
}
async function clearQl(){

View File

@ -50,7 +50,7 @@
<input type="text" maxlength="3" id="ql10" name="ql10" autocomplete="off" class="small-lookup-box">
<input type="text" maxlength="3" id="ql11" name="ql11" autocomplete="off" class="small-lookup-box"><br>
<button onclick="setQl()" class="lookup-button">Apply</button>
<button onclick="clearQl()" class="lookup-button">Reset</button>
<button onclick="clearQl()" class="lookup-button">Defaults</button>
</body>
</html>