feat(downloader): Add context menu button for playlists and albums (#3768)

Co-authored-by: JellyBrick <shlee1503@naver.com>
This commit is contained in:
Suffocate
2025-09-06 01:12:24 +01:00
committed by GitHub
parent f8654dfdb9
commit 555817e2f5
2 changed files with 23 additions and 2 deletions

View File

@ -6,7 +6,10 @@ import defaultConfig from '@/config/defaults';
import { getSongMenu } from '@/providers/dom-elements'; import { getSongMenu } from '@/providers/dom-elements';
import { getSongInfo } from '@/providers/song-info-front'; import { getSongInfo } from '@/providers/song-info-front';
import { t } from '@/i18n'; import { t } from '@/i18n';
import { isMusicOrVideoTrack } from '@/plugins/utils/renderer/check'; import {
isAlbumOrPlaylist,
isMusicOrVideoTrack,
} from '@/plugins/utils/renderer/check';
import { DownloadButton } from './templates/download'; import { DownloadButton } from './templates/download';
@ -25,7 +28,7 @@ const menuObserver = new MutationObserver(() => {
if ( if (
!menu || !menu ||
menu.contains(buttonContainer) || menu.contains(buttonContainer) ||
!isMusicOrVideoTrack() || !(isMusicOrVideoTrack() || isAlbumOrPlaylist()) ||
!buttonContainer !buttonContainer
) { ) {
return; return;

View File

@ -22,6 +22,24 @@ export const isMusicOrVideoTrack = () => {
return false; return false;
}; };
export const isAlbumOrPlaylist = () => {
for (const menuSelector of document.querySelectorAll<
HTMLAnchorElement & {
data: {
addToPlaylistEndpoint: {
playlistId: string;
};
clickTrackingParams: string;
};
}
>('tp-yt-paper-listbox #navigation-endpoint')) {
if (menuSelector?.data?.addToPlaylistEndpoint?.playlistId) {
return true;
}
}
return false;
};
export const isPlayerMenu = (menu?: HTMLElement | null) => { export const isPlayerMenu = (menu?: HTMLElement | null) => {
return ( return (
menu?.parentElement as menu?.parentElement as