Frontend: Refactor settings.js
Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
parent
018ddf8c47
commit
5e9f9e13bc
@ -1,16 +1,16 @@
|
|||||||
/* Feature Detectors */
|
/* Feature Detectors */
|
||||||
|
|
||||||
/* Valid values for ${type}: localstorage, sessionstorage */
|
/* Valid values for ${type}: localstorage, sessionstorage */
|
||||||
async function storageAvailable(type) {
|
async function storageAvailable(type) { // Currently not used
|
||||||
try {
|
try {
|
||||||
var storage = window[type],
|
let storage = window[type];
|
||||||
x = '__storage_test__';
|
let x = '__storage_test__';
|
||||||
storage.setItem(x, x);
|
storage.setItem(x, "test");
|
||||||
storage.getItem(x);
|
storage.getItem(x);
|
||||||
log(`lib.main.storageAvailable: ${type} is available`)
|
log(`lib.main.storageAvailable: ${type} is available`, "INFO")
|
||||||
return true;
|
return true;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log(`lib.main.storageAvailable: ${type} is not available`)
|
log(`lib.main.storageAvailable: ${type} is not available`, "ERR")
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,31 +1,15 @@
|
|||||||
// Init:
|
// Init:
|
||||||
const ql = ["ql0","ql1","ql2","ql3","ql4","ql5","ql6","ql7","ql8","ql9","ql10","ql11"]
|
const ql = ["ql0","ql1","ql2","ql3","ql4","ql5","ql6","ql7","ql8","ql9","ql10","ql11"]
|
||||||
checkStorageSupport();
|
storageAvailable("localStorage");
|
||||||
getQl();
|
getQl();
|
||||||
clearLoading();
|
hideLoading();
|
||||||
|
|
||||||
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.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getQl(){
|
async function getQl(){
|
||||||
var qlOpt = JSON.parse(localStorage.getItem("qlOpt"))
|
var qlOpt = await getQuickLinks()
|
||||||
if (qlOpt){
|
if (qlOpt){
|
||||||
var i = 0
|
var i = 0
|
||||||
while (i < 12) {
|
while (i < 12) {
|
||||||
if (qlOpt[i] != 'undefined') {
|
if (qlOpt[i] != 'undefined') {
|
||||||
console.log(`Setting box ql${i} to ${qlOpt[i]}`)
|
|
||||||
document.getElementById(`ql${i}`).value = qlOpt[i]
|
document.getElementById(`ql${i}`).value = qlOpt[i]
|
||||||
i +=1
|
i +=1
|
||||||
}
|
}
|
||||||
@ -43,9 +27,9 @@ async function setQl(){
|
|||||||
}
|
}
|
||||||
qlSet.sort()
|
qlSet.sort()
|
||||||
}
|
}
|
||||||
console.log(qlSet)
|
|
||||||
localStorage.setItem("qlOpt", JSON.stringify(qlSet))
|
localStorage.setItem("qlOpt", JSON.stringify(qlSet))
|
||||||
clearLoading();
|
log(`settings.setQl: User settings saved`, "INFO")
|
||||||
|
hideLoading();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function clearQl(){
|
async function clearQl(){
|
||||||
|
@ -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="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>
|
<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="setQl()" class="lookup-button">Apply</button>
|
||||||
<button onclick="clearQl()" class="lookup-button">Reset</button>
|
<button onclick="clearQl()" class="lookup-button">Defaults</button>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
Reference in New Issue
Block a user