Sv443 11 місяців тому
батько
коміт
f1e50eaa96
5 змінених файлів з 11 додано та 7 видалено
  1. 3 0
      src/constants.ts
  2. 4 4
      src/features/behavior.ts
  3. 1 1
      src/features/input.ts
  4. 1 1
      src/features/layout.ts
  5. 2 1
      src/siteEvents.ts

+ 3 - 0
src/constants.ts

@@ -42,6 +42,9 @@ export const sessionStorageAllowed =
     }
   })();
 
+/** The search params of the current URL */
+export const currentParams = new URL(location.href).searchParams;
+
 /**
  * How much info should be logged to the devtools console  
  * 0 = Debug (show everything) or 1 = Info (show only important stuff)

+ 4 - 4
src/features/behavior.ts

@@ -1,8 +1,9 @@
 import { clamp, interceptWindowEvent, pauseFor } from "@sv443-network/userutils";
 import { domLoaded, error, getDomain, getVideoTime, getWatchId, info, log, getVideoSelector, waitVideoElementReady } from "../utils";
+import { getFeatures } from "../config";
+import { addSelectorListener } from "../observers";
+import { currentParams } from "../constants";
 import { LogLevel } from "../types";
-import { getFeatures } from "src/config";
-import { addSelectorListener } from "src/observers";
 
 //#region beforeunload popup
 
@@ -106,8 +107,7 @@ export async function initRememberSongTime() {
 /** Tries to restore the time of the currently playing song */
 async function restoreSongTime() {
   if(location.pathname.startsWith("/watch")) {
-    const { searchParams } = new URL(location.href);
-    const watchID = searchParams.get("v");
+    const watchID = currentParams.get("v");
     if(!watchID)
       return;
 

+ 1 - 1
src/features/input.ts

@@ -113,7 +113,7 @@ async function switchSite(newDomain: Domain) {
   }
 }
 
-//#region num key skip to
+//#region num keys skip
 
 const numKeysIgnoreTagNames = [...inputIgnoreTagNames, "TP-YT-PAPER-TAB"];
 const numKeysIgnoreIds = ["progress-bar", "song-media-window"];

+ 1 - 1
src/features/layout.ts

@@ -431,7 +431,7 @@ export async function initAboveQueueBtns() {
               const url = new URL(location.href);
               url.searchParams.delete("list");
               url.searchParams.set("t", String(await getVideoTime(0)));
-              location.href = String(url);
+              location.assign(url);
             }
             catch(err) {
               error("Couldn't clear queue due to an error:", err);

+ 2 - 1
src/siteEvents.ts

@@ -3,6 +3,7 @@ import { error, info } from "./utils";
 import { FeatureConfig } from "./types";
 import { emitInterface } from "./interface";
 import { addSelectorListener } from "./observers";
+import { currentParams } from "./constants";
 
 export interface SiteEventsMap {
   // misc:
@@ -153,7 +154,7 @@ export async function initSiteEvents() {
 
     const checkWatchId = () => {
       if(location.pathname.startsWith("/watch")) {
-        const newWatchId = new URL(location.href).searchParams.get("v");
+        const newWatchId = currentParams.get("v");
         if(newWatchId && newWatchId !== lastWatchId) {
           info(`Detected watch ID change - old ID: "${lastWatchId}" - new ID: "${newWatchId}"`);
           emitSiteEvent("watchIdChanged", newWatchId, lastWatchId);