Browse Source

fix: autoplay list requiring context menu event dispatch now

Sv443 10 months ago
parent
commit
507f3e0103
4 changed files with 33 additions and 28 deletions
  1. 3 3
      src/features/input.ts
  2. 2 1
      src/features/layout.ts
  3. 27 24
      src/features/songLists.ts
  4. 1 0
      src/observers.ts

+ 3 - 3
src/features/input.ts

@@ -1,5 +1,5 @@
 import { DataStore, clamp, compress, decompress } from "@sv443-network/userutils";
-import { error, getVideoTime, info, log, warn, getVideoSelector, getDomain, compressionSupported, t, clearNode, resourceToHTMLString, getCurrentChannelId } 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 { isCfgMenuOpen } from "../menu/menu_old.js";
 import { disableBeforeUnload } from "./behavior.js";
@@ -231,7 +231,7 @@ export async function initAutoLike() {
               message: t("auto_liked_channel", likeChan.name),
               icon: "icon-auto_like",
             });
-            log(`Auto-liked channel '${likeChan.name}' (ID: '${likeChan.id}')`);
+            log(`Auto-liked ${currentMediaType()} from channel '${likeChan.name}' (${likeChan.id})`);
           }
         }, (getFeature("autoLikeTimeout") ?? 5) * 1000);
       });
@@ -286,7 +286,7 @@ export async function initAutoLike() {
                       message: t("auto_liked_channel", likeChan.name),
                       icon: "icon-auto_like",
                     });
-                    log(`Auto-liked channel '${likeChan.name}' (ID: '${likeChan.id}')`);
+                    log(`Auto-liked ${currentMediaType()} from channel '${likeChan.name}' (${likeChan.id})`);
                   }
                 }
               });

+ 2 - 1
src/features/layout.ts

@@ -189,7 +189,8 @@ export async function removeUpgradeTab() {
       log("Removed large upgrade tab");
     },
   });
-  addSelectorListener("sideBarMini", "ytmusic-guide-renderer #sections ytmusic-guide-section-renderer[is-primary] #items ytmusic-guide-entry-renderer:nth-of-type(4)", {
+  // TODO:FIXME: see https://github.com/Sv443/BetterYTM/issues/91
+  addSelectorListener("sideBarMini", "#sections ytmusic-guide-section-renderer[is-primary] #items ytmusic-guide-entry-renderer:nth-of-type(4)", {
     listener: (tabElemSmall) => {
       tabElemSmall.remove();
       log("Removed small upgrade tab");

+ 27 - 24
src/features/songLists.ts

@@ -1,5 +1,5 @@
 import { autoPlural, pauseFor } from "@sv443-network/userutils";
-import { clearInner, error, getResourceUrl, log, onInteraction, openInTab, t } from "../utils/index.js";
+import { clearInner, error, getResourceUrl, log, onInteraction, openInTab, t, warn } from "../utils/index.js";
 import { SiteEventsMap, siteEvents } from "../siteEvents.js";
 import { emitInterface } from "../interface.js";
 import { fetchLyricsUrlTop, createLyricsBtn, sanitizeArtists, sanitizeSong, splitVideoTitle } from "./lyrics.js";
@@ -225,30 +225,33 @@ async function addQueueButtons(
             queuePopupCont.setAttribute("data-bytm-hidden", "true");
 
           dotsBtnElem.click();
+        }
+        else {
+          warn("Couldn't find three dots button in queue item, trying to open the context menu manually");
+          queueItem.dispatchEvent(new MouseEvent("contextmenu", { bubbles: true, cancelable: false }));
+        }
+
+        queuePopupCont = document.querySelector<HTMLElement>("ytmusic-app ytmusic-popup-container tp-yt-iron-dropdown");
+        queuePopupCont?.setAttribute("data-bytm-hidden", "true");
+
+        await pauseFor(15);
+
+        const removeFromQueueBtn = queuePopupCont?.querySelector<HTMLElement>("tp-yt-paper-listbox ytmusic-menu-service-item-renderer:nth-of-type(3)");
+        removeFromQueueBtn?.click();
+
+        // queue items aren't removed automatically outside of the current queue
+        if(removeFromQueueBtn && listType === "genericQueue") {
+          await pauseFor(200);
+          clearInner(queueItem);
+          queueItem.remove();
+        }
 
-          queuePopupCont = document.querySelector<HTMLElement>("ytmusic-app ytmusic-popup-container tp-yt-iron-dropdown");
-          queuePopupCont?.setAttribute("data-bytm-hidden", "true");
-
-          // TODO: think of something better than this
-          await pauseFor(25);
-
-          const removeFromQueueBtn = queuePopupCont?.querySelector<HTMLElement>("tp-yt-paper-listbox ytmusic-menu-service-item-renderer:nth-of-type(3)");
-          removeFromQueueBtn?.click();
-
-          // queue items aren't removed automatically outside of the current queue
-          if(removeFromQueueBtn && listType === "genericQueue") {
-            await pauseFor(200);
-            clearInner(queueItem);
-            queueItem.remove();
-          }
-
-          if(!removeFromQueueBtn) {
-            error("Couldn't find 'remove from queue' button in queue item three dots menu");
-            dotsBtnElem.click();
-            imgElem.src = await getResourceUrl("icon-error");
-            if(deleteBtnElem)
-              deleteBtnElem.ariaLabel = deleteBtnElem.title = (listType === "currentQueue" ? t("couldnt_remove_from_queue") : t("couldnt_delete_from_list"));
-          }
+        if(!removeFromQueueBtn) {
+          error("Couldn't find 'remove from queue' button in queue item three dots menu.\nPlease make sure all autoplay restrictions on your browser's side are disabled for this page.");
+          dotsBtnElem?.click();
+          imgElem.src = await getResourceUrl("icon-error");
+          if(deleteBtnElem)
+            deleteBtnElem.ariaLabel = deleteBtnElem.title = (listType === "currentQueue" ? t("couldnt_remove_from_queue") : t("couldnt_delete_from_list"));
         }
       }
       catch(err) {

+ 1 - 0
src/observers.ts

@@ -92,6 +92,7 @@ export function initObservers() {
     //    enabled immediately
     globservers.body = new SelectorObserver(document.body, {
       ...defaultObserverOptions,
+      defaultDebounceEdge: "falling",
       defaultDebounce: 150,
       subtree: false,
     });