ソースを参照

ref: random stuff

Sven 1 年間 前
コミット
24bd22b075
4 ファイル変更14 行追加15 行削除
  1. 1 1
      src/features/index.ts
  2. 10 9
      src/features/layout.ts
  3. 1 1
      src/types.ts
  4. 2 4
      src/utils.ts

+ 1 - 1
src/features/index.ts

@@ -94,7 +94,7 @@ export const featInfo = {
     default: true,
   },
   closeToastsTimeout: {
-    desc: "After how long to close permanent notifications - 0 to only close them manually (default behavior)",
+    desc: "After how many seconds to close permanent notifications - 0 to only close them manually (default behavior)",
     type: "number",
     category: "layout",
     min: 0,

+ 10 - 9
src/features/layout.ts

@@ -624,7 +624,7 @@ export function initAutoCloseToasts() {
     onSelector("tp-yt-paper-toast#toast", {
       all: true,
       continuous: true,
-      listener: (toastElems) => {
+      listener: async (toastElems) => {
         for(const toastElem of toastElems) {
           if(!toastElem.hasAttribute("allow-click-through"))
             continue;
@@ -633,14 +633,15 @@ export function initAutoCloseToasts() {
             continue;
           toastElem.classList.add("bytm-closing");
 
-          setTimeout(() => {
-            toastElem.classList.remove("paper-toast-open");
-            // wait for the transition to finish
-            setTimeout(() => {
-              toastElem.style.display = "none";
-              log(`Automatically closed toast '${toastElem.querySelector<HTMLDivElement>("#text-container yt-formatted-string")?.innerText}' after ${closeTimeout + animTimeout}ms`);
-            }, animTimeout);
-          }, closeTimeout);
+          await pauseFor(closeTimeout);
+
+          toastElem.classList.remove("paper-toast-open");
+          log(`Automatically closed toast '${toastElem.querySelector<HTMLDivElement>("#text-container yt-formatted-string")?.innerText}' after ${features.closeToastsTimeout * 1000}ms`);
+
+          // wait for the transition to finish
+          await pauseFor(animTimeout);
+
+          toastElem.style.display = "none";
         }
       },
     });

+ 1 - 1
src/types.ts

@@ -42,7 +42,7 @@ export interface FeatureConfig {
   watermarkEnabled: boolean;
   /** Add buttons while hovering over a song in a queue to quickly remove it or open its lyrics */
   queueButtons: boolean;
-  /** After how many seconds to close toasts */
+  /** After how many milliseconds to close permanent toasts */
   closeToastsTimeout: number;
 
   //#SECTION lyrics

+ 2 - 4
src/utils.ts

@@ -213,11 +213,9 @@ function ytForceShowVideoTime() {
  * @throws Throws if script runs on an unexpected website
  */
 export function getDomain(): Domain {
-  const { hostname } = new URL(location.href);
-
-  if(hostname.includes("music.youtube"))
+  if(location.hostname.match(/^music\.youtube/))
     return "ytm";
-  else if(hostname.includes("youtube"))
+  else if(location.hostname.match(/youtube\./))
     return "yt";
   else
     throw new Error("BetterYTM is running on an unexpected website. Please don't tamper with the @match directives in the userscript header.");