瀏覽代碼

fix: make number and arrow keys usable in cfg menu

Sv443 10 月之前
父節點
當前提交
0714a080c4
共有 2 個文件被更改,包括 8 次插入9 次删除
  1. 0 3
      src/features/input.ts
  2. 8 6
      src/menu/menu_old.ts

+ 0 - 3
src/features/input.ts

@@ -1,7 +1,6 @@
 import { DataStore, clamp, compress, decompress } from "@sv443-network/userutils";
 import { DataStore, clamp, compress, decompress } from "@sv443-network/userutils";
 import { error, getVideoTime, info, log, warn, getVideoSelector, getDomain, compressionSupported, t, clearNode, resourceToHTMLString, getCurrentChannelId, currentMediaType } from "../utils/index.js";
 import { error, getVideoTime, info, log, warn, getVideoSelector, getDomain, compressionSupported, t, clearNode, resourceToHTMLString, getCurrentChannelId, currentMediaType } from "../utils/index.js";
 import type { Domain } from "../types.js";
 import type { Domain } from "../types.js";
-import { isCfgMenuOpen } from "../menu/menu_old.js";
 import { disableBeforeUnload } from "./behavior.js";
 import { disableBeforeUnload } from "./behavior.js";
 import { siteEvents } from "../siteEvents.js";
 import { siteEvents } from "../siteEvents.js";
 import { featInfo } from "./index.js";
 import { featInfo } from "./index.js";
@@ -129,8 +128,6 @@ export async function initNumKeysSkip() {
       return;
       return;
     if(!e.key.trim().match(/^[0-9]$/))
     if(!e.key.trim().match(/^[0-9]$/))
       return;
       return;
-    if(isCfgMenuOpen)
-      return;
     // discard the event when an unexpected element is currently active or in focus, like when editing a playlist or when the search bar is focused
     // discard the event when an unexpected element is currently active or in focus, like when editing a playlist or when the search bar is focused
     const ignoreElement = numKeysIgnoreTagNames.includes(document.activeElement?.tagName ?? "");
     const ignoreElement = numKeysIgnoreTagNames.includes(document.activeElement?.tagName ?? "");
     if((document.activeElement !== document.body && ignoreElement) || ignoreElement)
     if((document.activeElement !== document.body && ignoreElement) || ignoreElement)

+ 8 - 6
src/menu/menu_old.ts

@@ -2,7 +2,7 @@ import { debounce, isScrollable, type Stringifiable } from "@sv443-network/useru
 import { defaultData, getFeature, getFeatures, setFeatures } from "../config.js";
 import { defaultData, getFeature, getFeatures, setFeatures } from "../config.js";
 import { buildNumber, host, mode, scriptInfo } from "../constants.js";
 import { buildNumber, host, mode, scriptInfo } from "../constants.js";
 import { featInfo, disableBeforeUnload } from "../features/index.js";
 import { featInfo, disableBeforeUnload } from "../features/index.js";
-import { error, getResourceUrl, info, log, resourceToHTMLString, getLocale, hasKey, initTranslations, setLocale, t, arrayWithSeparators, tp, type TrKey, onInteraction, getDomain, copyToClipboard } from "../utils/index.js";
+import { error, getResourceUrl, info, log, resourceToHTMLString, getLocale, hasKey, initTranslations, setLocale, t, arrayWithSeparators, tp, type TrKey, onInteraction, getDomain, copyToClipboard, warn } from "../utils/index.js";
 import { siteEvents } from "../siteEvents.js";
 import { siteEvents } from "../siteEvents.js";
 import { getChangelogDialog, getExportDialog, getFeatHelpDialog, getImportDialog } from "../dialogs/index.js";
 import { getChangelogDialog, getExportDialog, getFeatHelpDialog, getImportDialog } from "../dialogs/index.js";
 import type { FeatureCategory, FeatureKey, FeatureConfig, HotkeyObj, FeatureInfo } from "../types.js";
 import type { FeatureCategory, FeatureKey, FeatureConfig, HotkeyObj, FeatureInfo } from "../types.js";
@@ -779,6 +779,7 @@ export function closeCfgMenu(evt?: MouseEvent | KeyboardEvent, enableScroll = tr
   if(!isCfgMenuOpen)
   if(!isCfgMenuOpen)
     return;
     return;
   isCfgMenuOpen = false;
   isCfgMenuOpen = false;
+
   evt?.bubbles && evt.stopPropagation();
   evt?.bubbles && evt.stopPropagation();
 
 
   if(enableScroll) {
   if(enableScroll) {
@@ -787,19 +788,20 @@ export function closeCfgMenu(evt?: MouseEvent | KeyboardEvent, enableScroll = tr
   }
   }
   const menuBg = document.querySelector<HTMLElement>("#bytm-cfg-menu-bg");
   const menuBg = document.querySelector<HTMLElement>("#bytm-cfg-menu-bg");
 
 
+  clearTimeout(hiddenCopiedTxtTimeout);
+
+  openDialogs.splice(openDialogs.indexOf("cfg-menu"), 1);
+  setCurrentDialogId(openDialogs?.[0] ?? null);
+
   siteEvents.emit("cfgMenuClosed");
   siteEvents.emit("cfgMenuClosed");
 
 
   if(!menuBg)
   if(!menuBg)
-    return;
+    return warn("Couldn't close config menu because background element couldn't be found. The config menu is considered closed but might still be open. In this case please reload the page. If the issue persists, please create an issue on GitHub.");
 
 
   menuBg.querySelectorAll<HTMLElement>(".bytm-ftconf-adv-copy-hint")?.forEach((el) => el.style.display = "none");
   menuBg.querySelectorAll<HTMLElement>(".bytm-ftconf-adv-copy-hint")?.forEach((el) => el.style.display = "none");
-  clearTimeout(hiddenCopiedTxtTimeout);
 
 
   menuBg.style.visibility = "hidden";
   menuBg.style.visibility = "hidden";
   menuBg.style.display = "none";
   menuBg.style.display = "none";
-
-  openDialogs.splice(openDialogs.indexOf("cfg-menu"), 1);
-  setCurrentDialogId(openDialogs?.[0] ?? null);
 }
 }
 
 
 /** Opens the config menu if it is closed */
 /** Opens the config menu if it is closed */