mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-10 10:11:46 +00:00
feat(downloader): Add context menu button for playlists and albums (#3768)
Co-authored-by: JellyBrick <shlee1503@naver.com>
This commit is contained in:
@ -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;
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user