Переглянути джерело

fix: onInteraction and number key skip

Sv443 11 місяців тому
батько
коміт
5679533ef8
2 змінених файлів з 14 додано та 3 видалено
  1. 9 3
      src/features/input.ts
  2. 5 0
      src/utils/dom.ts

+ 9 - 3
src/features/input.ts

@@ -18,8 +18,14 @@ export async function initArrowKeySkip() {
 
     if(!["ArrowLeft", "ArrowRight"].includes(evt.code))
       return;
+
+    const allowedClasses = ["bytm-generic-btn", "yt-spec-button-shape-next"];
+
     // discard the event when a (text) input is currently active, like when editing a playlist
-    if(inputIgnoreTagNames.includes(document.activeElement?.tagName ?? "") || ["volume-slider"].includes(document.activeElement?.id ?? ""))
+    if(
+      (inputIgnoreTagNames.includes(document.activeElement?.tagName ?? "") || ["volume-slider"].includes(document.activeElement?.id ?? ""))
+      && !allowedClasses.some((cls) => document.activeElement?.classList.contains(cls))
+    )
       return info(`Captured valid key to skip forward or backward but the current active element is <${document.activeElement?.tagName.toLowerCase()}>, so the keypress is ignored`);
 
     evt.preventDefault();
@@ -124,8 +130,8 @@ export async function initNumKeysSkip() {
     // 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
     if(
       document.activeElement !== document.body // short-circuit if nothing is active
-      && !numKeysIgnoreIds.includes(document.activeElement?.id ?? "") // video element or player bar active
-      && !numKeysIgnoreTagNames.includes(document.activeElement?.tagName ?? "") // other element active
+      || numKeysIgnoreIds.includes(document.activeElement?.id ?? "") // video element or player bar active
+      || numKeysIgnoreTagNames.includes(document.activeElement?.tagName ?? "") // other element active
     )
       return info("Captured valid key to skip video to, but ignored it since an unexpected element is active:", document.activeElement);
 

+ 5 - 0
src/utils/dom.ts

@@ -158,6 +158,11 @@ export function onInteraction<TElem extends HTMLElement>(elem: TElem, listener:
       }
       else return;
     }
+    else if(e instanceof MouseEvent) {
+      e.preventDefault();
+      e.stopImmediatePropagation();
+    }
+
     // clean up the other listener that isn't automatically removed if `once` is set
     listenerOptions?.once && e.type === "keydown" && elem.removeEventListener("click", proxListener, listenerOptions);
     listenerOptions?.once && e.type === "click" && elem.removeEventListener("keydown", proxListener, listenerOptions);