mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-12 11:01:45 +00:00
fix: improve menu detector
This commit is contained in:
@ -1,20 +1,39 @@
|
||||
export const isMusicOrVideoTrack = () => {
|
||||
let menuUrl = document.querySelector<HTMLAnchorElement>(
|
||||
'tp-yt-paper-listbox [tabindex="0"] #navigation-endpoint',
|
||||
)?.href;
|
||||
|
||||
if (!menuUrl?.includes('watch?')) {
|
||||
menuUrl = undefined;
|
||||
// check for podcast
|
||||
for (const it of document.querySelectorAll(
|
||||
'tp-yt-paper-listbox [tabindex="-1"] #navigation-endpoint',
|
||||
)) {
|
||||
if (it.getAttribute('href')?.includes('podcast/')) {
|
||||
menuUrl = it.getAttribute('href')!;
|
||||
break;
|
||||
}
|
||||
for (const menuSelector of document.querySelectorAll<
|
||||
HTMLAnchorElement & {
|
||||
data: {
|
||||
watchEndpoint: {
|
||||
videoId: string;
|
||||
};
|
||||
addToPlaylistEndpoint: {
|
||||
videoId: string;
|
||||
};
|
||||
clickTrackingParams: string;
|
||||
};
|
||||
}
|
||||
>('tp-yt-paper-listbox #navigation-endpoint')) {
|
||||
if (
|
||||
menuSelector?.data?.addToPlaylistEndpoint?.videoId ||
|
||||
menuSelector?.data?.watchEndpoint?.videoId
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return !!menuUrl;
|
||||
return false;
|
||||
};
|
||||
|
||||
export const isPlayerMenu = (menu?: HTMLElement | null) => {
|
||||
return (
|
||||
menu?.parentElement as
|
||||
| (HTMLElement & {
|
||||
ytEventForwardingBehavior: {
|
||||
forwarder_: {
|
||||
eventSink: HTMLElement;
|
||||
};
|
||||
};
|
||||
})
|
||||
| null
|
||||
)?.ytEventForwardingBehavior?.forwarder_?.eventSink?.matches(
|
||||
'ytmusic-menu-renderer.ytmusic-player-bar',
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user