Explorar o código

feat: hotkey to skip to last remembered video/song time

Sv443 hai 9 horas
pai
achega
abddb3769c

+ 9 - 9
assets/translations/README.md

@@ -16,15 +16,15 @@ To submit or edit a translation, please follow [this guide](../../contributing.m
 ### Translation progress:
 |   | Locale | Translated keys | Based on |
 | :----: | ------ | --------------- | :------: |
-|  | [`en-US`](./en-US.json) | `364` (default locale) |  |
-| ✅ | [`de-DE`](./de-DE.json) | `364/364` (100%) | ─ |
-|  | [`en-GB`](./en-GB.json) | `364/364` (100%) | `en-US` |
-| ‼️ | [`es-ES`](./es-ES.json) | `342/364` (94%) | ─ |
-| ‼️ | [`fr-FR`](./fr-FR.json) | `342/364` (94%) | ─ |
-| ‼️ | [`hi-IN`](./hi-IN.json) | `342/364` (94%) | ─ |
-| ‼️ | [`ja-JP`](./ja-JP.json) | `342/364` (94%) | ─ |
-| ‼️ | [`pt-BR`](./pt-BR.json) | `342/364` (94%) | ─ |
-| ‼️ | [`zh-CN`](./zh-CN.json) | `342/364` (94%) | ─ |
+|  | [`en-US`](./en-US.json) | `366` (default locale) |  |
+| ✅ | [`de-DE`](./de-DE.json) | `366/366` (100%) | ─ |
+|  | [`en-GB`](./en-GB.json) | `366/366` (100%) | `en-US` |
+| ‼️ | [`es-ES`](./es-ES.json) | `342/366` (93.4%) | ─ |
+| ‼️ | [`fr-FR`](./fr-FR.json) | `342/366` (93.4%) | ─ |
+| ‼️ | [`hi-IN`](./hi-IN.json) | `342/366` (93.4%) | ─ |
+| ‼️ | [`ja-JP`](./ja-JP.json) | `342/366` (93.4%) | ─ |
+| ‼️ | [`pt-BR`](./pt-BR.json) | `342/366` (93.4%) | ─ |
+| ‼️ | [`zh-CN`](./zh-CN.json) | `342/366` (93.4%) | ─ |
 
 <sub>
 ✅ - Fully translated

+ 2 - 0
assets/translations/de-DE.json

@@ -344,6 +344,8 @@
   "feature_desc_dislikeHotkey": "Der Hotkey, um das aktuell spielende Video/Lied zu disliken",
   "feature_desc_currentLyricsHotkeyEnabled": "Einen Hotkey hinzufügen, um den Songtext des aktuell spielenden Songs in einem neuen Tab zu öffnen",
   "feature_desc_currentLyricsHotkey": "Der Hotkey, um den Songtext des aktuellen Songs zu öffnen",
+  "feature_desc_skipToRemTimeHotkeyEnabled": "Einen Hotkey hinzufügen, um zu der letzten gespeicherten Zeit des aktuellen Videos/Lieds zu springen",
+  "feature_desc_skipToRemTimeHotkey": "Der Hotkey, um zu der letzten gespeicherten Zeit zu springen",
   "feature_desc_rebindNextAndPrevious": "Die Hotkeys neu belegen, die zum nächsten (J) oder vorherigen (K) Video/Lied springen",
   "feature_desc_nextHotkey": "Der Hotkey, um zum nächsten Video/Lied zu springen",
   "feature_desc_previousHotkey": "Der Hotkey, um zum vorherigen Video/Lied zu springen",

+ 2 - 0
assets/translations/en-US.json

@@ -344,6 +344,8 @@
   "feature_desc_dislikeHotkey": "The hotkey to dislike the current video/song",
   "feature_desc_currentLyricsHotkeyEnabled": "Add a hotkey to open the current song's lyrics in a new tab",
   "feature_desc_currentLyricsHotkey": "The hotkey to open the song's lyrics",
+  "feature_desc_skipToRemTimeHotkeyEnabled": "Add a hotkey to skip to the last remembered time of the current video/song",
+  "feature_desc_skipToRemTimeHotkey": "The hotkey to skip to the last remembered time",
   "feature_desc_rebindNextAndPrevious": "Rebind the hotkeys to skip to the next (J) or previous (K) video/song",
   "feature_desc_nextHotkey": "The hotkey to skip to the next video/song",
   "feature_desc_previousHotkey": "The hotkey to skip to the previous video/song",

+ 1 - 0
src/config.ts

@@ -145,6 +145,7 @@ export const migrations: DataMigrationsDict = {
         "arrowKeyVolumeStep", "likeDislikeHotkeys",
         "likeHotkey", "dislikeHotkey",
         "currentLyricsHotkeyEnabled", "currentLyricsHotkey",
+        "skipToRemTimeHotkeyEnabled", "skipToRemTimeHotkey",
         "rebindNextAndPrevious", "nextHotkey",
         "previousHotkey", "rebindPlayPause",
         "playPauseHotkey",

+ 25 - 1
src/features/hotkeys.ts

@@ -2,7 +2,7 @@ import { getUnsafeWindow } from "@sv443-network/userutils";
 import { getFeature } from "../config.js";
 import { inputIgnoreTagNames } from "./input.js";
 import { siteEvents } from "../siteEvents.js";
-import { enableDiscardBeforeUnload } from "./behavior.js";
+import { enableDiscardBeforeUnload, remTimeTryRestoreTime } from "./behavior.js";
 import { getLikeDislikeBtns, getVideoTime } from "../utils/dom.js";
 import { getDomain } from "../utils/misc.js";
 import { error, info, log, warn } from "../utils/logging.js";
@@ -15,6 +15,7 @@ export async function initHotkeys() {
   promises.push(initLyricsHotkey());
   promises.push(initSiteSwitch());
   promises.push(initProxyHotkeys());
+  promises.push(initSkipToRemTimeHotkey());
 
   return await Promise.allSettled(promises);
 }
@@ -130,8 +131,28 @@ async function initLyricsHotkey() {
   }, { capture: true });
 }
 
+//#region skip to remembered
+
+async function initSkipToRemTimeHotkey() {
+  document.addEventListener("keydown", async (e) => {
+    if(!getFeature("skipToRemTimeHotkeyEnabled"))
+      return;
+    if(inputIgnoreTagNames.includes(document.activeElement?.tagName ?? ""))
+      return;
+
+    if(hotkeyMatches(e, getFeature("skipToRemTimeHotkey"))) {
+      e.preventDefault();
+      e.stopImmediatePropagation();
+
+      await remTimeTryRestoreTime(true);
+    }
+  });
+}
+
 //#region proxy hotkeys
 
+//TODO:FIXME: proxy hotkeys are triggered when input is active
+
 type HotkeyProxyGroup = {
   /** The feature key that contains the hotkey object */
   hkFeatKey: FeatKeysOfType<HotkeyObj>;
@@ -196,6 +217,9 @@ async function initProxyHotkeys() {
   } as const;
 
   document.addEventListener("keydown", (e) => {
+    if(inputIgnoreTagNames.includes(document.activeElement?.tagName ?? ""))
+      return;
+
     for(const [featKey, proxyGroup] of Object.entries(proxyHotkeys)) {
       if(getFeature(featKey as "_") !== true)
         continue;

+ 21 - 0
src/features/index.ts

@@ -756,6 +756,27 @@ export const featInfo = {
     enable: noop,
     textAdornment: adornments.ytmOnly,
   },
+  skipToRemTimeHotkeyEnabled: {
+    type: "toggle",
+    category: "hotkeys",
+    supportedSites: ["ytm", "yt"],
+    default: true,
+    reloadRequired: false,
+    enable: noop,
+  },
+  skipToRemTimeHotkey: {
+    type: "hotkey",
+    category: "hotkeys",
+    supportedSites: ["ytm", "yt"],
+    default: {
+      code: "KeyR",
+      shift: false,
+      ctrl: false,
+      alt: true,
+    },
+    reloadRequired: false,
+    enable: noop,
+  },
   rebindNextAndPrevious: {
     type: "toggle",
     category: "hotkeys",

+ 4 - 0
src/types.ts

@@ -649,6 +649,10 @@ export interface FeatureConfig {
   currentLyricsHotkeyEnabled: boolean;
   /** The hotkey that needs to be pressed to open the current song's lyrics in a new tab */
   currentLyricsHotkey: HotkeyObj;
+  /** Add a hotkey to skip to the last remembered time of the current video/song */
+  skipToRemTimeHotkeyEnabled: boolean;
+  /** The hotkey that needs to be pressed to skip to the last remembered time of the current video/song */
+  skipToRemTimeHotkey: HotkeyObj;
   /** Whether to rebind the next [J] and previous [K] keys */
   rebindNextAndPrevious: boolean;
   /** The hotkey that needs to be pressed to skip to the next video/song */