From d7f65ad78854f97f439e1d79f3f25a9706d0f15f Mon Sep 17 00:00:00 2001 From: Maxim Devaev Date: Thu, 12 Aug 2021 10:21:35 +0300 Subject: refactoring --- web/share/js/kvm/atx.js | 4 ++-- web/share/js/kvm/hid.js | 4 ++-- web/share/js/tools.js | 3 +++ 3 files changed, 7 insertions(+), 4 deletions(-) (limited to 'web') diff --git a/web/share/js/kvm/atx.js b/web/share/js/kvm/atx.js index 380dfb51..fb1e0d28 100644 --- a/web/share/js/kvm/atx.js +++ b/web/share/js/kvm/atx.js @@ -36,9 +36,9 @@ export function Atx() { $("atx-power-led").title = "Power Led"; $("atx-hdd-led").title = "Disk Activity Led"; - $("atx-ask-switch").checked = parseInt(tools.storage.get("atx.ask", "1")); + $("atx-ask-switch").checked = tools.storage.getBool("atx.ask", true); tools.el.setOnClick($("atx-ask-switch"), function() { - tools.storage.set("atx.ask", ($("atx-ask-switch").checked ? 1 : 0)); + tools.storage.setBool("atx.ask", $("atx-ask-switch").checked); }, false); diff --git a/web/share/js/kvm/hid.js b/web/share/js/kvm/hid.js index 374148c4..6dfad27b 100644 --- a/web/share/js/kvm/hid.js +++ b/web/share/js/kvm/hid.js @@ -74,9 +74,9 @@ export function Hid(__getResolution) { window.addEventListener("pagehide", __releaseAll); window.addEventListener("blur", __releaseAll); - $("hid-pak-ask-switch").checked = parseInt(tools.storage.get("hid.pak.ask", "1")); + $("hid-pak-ask-switch").checked = tools.storage.getBool("hid.pak.ask", true); tools.el.setOnClick($("hid-pak-ask-switch"), function() { - tools.storage.set("hid.pak.ask", ($("hid-pak-ask-switch").checked ? 1 : 0)); + tools.storage.setBool("hid.pak.ask", $("hid-pak-ask-switch").checked); }, false); $("hid-pak-keymap-selector").addEventListener("change", function() { diff --git a/web/share/js/tools.js b/web/share/js/tools.js index 10013727..dc443517 100644 --- a/web/share/js/tools.js +++ b/web/share/js/tools.js @@ -277,6 +277,9 @@ export var tools = new function() { return (value !== null ? value : default_value); }, "set": (key, value) => window.localStorage.setItem(key, value), + + "getBool": (key, default_value) => !!parseInt(self.storage.get(key, (default_value ? "1" : "0"))), + "setBool": (key, value) => self.storage.set(key, (value ? "1" : "0")), }; }; -- cgit v1.2.3