From 381a27b36d006ba7764020a089a212776260a567 Mon Sep 17 00:00:00 2001 From: fraxken Date: Fri, 1 Dec 2023 18:22:17 +0100 Subject: [PATCH] feat: add wiki shortcut --- public/js/components/settings.js | 11 +++++------ public/js/components/wiki.js | 8 ++++++++ views/index.html | 8 ++++++-- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/public/js/components/settings.js b/public/js/components/settings.js index 5bc6110f..a900010d 100644 --- a/public/js/components/settings.js +++ b/public/js/components/settings.js @@ -10,7 +10,8 @@ const kAllowedHotKeys = new Set([ const kDefaultHotKeys = { home: "H", network: "N", - settings: "S" + settings: "S", + wiki: "W" } export class Settings { @@ -108,16 +109,14 @@ export class Settings { updateHotKeys() { const hotkeys = {}; - const hotkeysInputs = [...this.dom.shortcutsSection.querySelectorAll(".hotkey")]; + const hotkeysInputs = this.dom.shortcutsSection.querySelectorAll(".hotkey"); for (const input of hotkeysInputs) { - const viewName = input.getAttribute("id"); - const hotkey = input.value; - hotkeys[viewName] = hotkey; + const hotkeyName = input.getAttribute("id"); + hotkeys[hotkeyName] = input.value; } this.updateNavigationHotKey(hotkeys); - localStorage.setItem("hotkeys", JSON.stringify(hotkeys)); } diff --git a/public/js/components/wiki.js b/public/js/components/wiki.js index 13aa45b0..675faa3f 100644 --- a/public/js/components/wiki.js +++ b/public/js/components/wiki.js @@ -29,6 +29,14 @@ export class Wiki { this.openButton.addEventListener("click", () => { this[this.isOpen ? "close" : "open"](); }); + + document.addEventListener("keydown", (event) => { + const hotkeys = JSON.parse(localStorage.getItem("hotkeys")); + + if (event.key.toUpperCase() === hotkeys.wiki) { + this[this.isOpen ? "close" : "open"](); + } + }); } get isOpen() { diff --git a/views/index.html b/views/index.html index a8a61248..e5d3bf9f 100644 --- a/views/index.html +++ b/views/index.html @@ -253,11 +253,15 @@

Shortcuts

- +
- + +
+
+ +