Skip to content

Commit

Permalink
Merge pull request #20 from jeroentvb/dev
Browse files Browse the repository at this point in the history
fix: images not rendering in 'add to playlist' contextmenu
  • Loading branch information
jeroentvb authored Feb 28, 2024
2 parents 8f9f899 + 5dbc0c2 commit b4315d8
Show file tree
Hide file tree
Showing 7 changed files with 464 additions and 558 deletions.
998 changes: 454 additions & 544 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "playlist-icons",
"version": "1.0.0",
"version": "1.0.1",
"private": true,
"scripts": {
"build": "spicetify-creator",
Expand Down
6 changes: 3 additions & 3 deletions src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ async function main() {
const initPlaylistWatcher = () => {
renderPlaylistImages(playlistData);
observer = createMutationObserver(() => renderPlaylistImages(playlistData));
}
};

/**
* Init
*/
if (legacyMode) initPlaylistWatcher()
if (legacyMode) initPlaylistWatcher();
if (showBigIcons) playlistElement.classList.add('big-icons');

// Watch for context menu and add icons to it
Expand All @@ -47,7 +47,7 @@ async function main() {
localStorage.setItem(LEGACY_MODE_KEY, JSON.stringify(!legacyMode));
legacyMode = !legacyMode;
if (legacyMode) {
initPlaylistWatcher()
initPlaylistWatcher();
} else {
observer?.disconnect();
observer = undefined;
Expand Down
6 changes: 2 additions & 4 deletions src/utils/add-to-playlist-icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function watchAddToPlaylistMenu(playlistData: SpotifyApi.PlaylistObjectSi
liElement.classList.add('add-to-playlist-item');

createMutationObserver(() => {
const nestedPlaylists = liElement.querySelector<HTMLLIElement>('.main-contextMenu-menu[tabindex="-1"] > div');
const nestedPlaylists = liElement.querySelector<HTMLLIElement>('ul[tabindex="-1"] > div');
if (!nestedPlaylists) return;

renderPlaylistIcons(nestedPlaylists.children);
Expand All @@ -38,11 +38,9 @@ export function watchAddToPlaylistMenu(playlistData: SpotifyApi.PlaylistObjectSi
};

createMutationObserver(() => {
const addToPlaylistElement: HTMLDivElement | null = document.querySelector('#context-menu .main-contextMenu-menu[tabindex="-1"] > div');
const addToPlaylistElement: HTMLDivElement | null = document.querySelector('#context-menu ul[tabindex="-1"] > div');
if (!addToPlaylistElement) return;

renderPlaylistIcons(addToPlaylistElement.children);
});
}


5 changes: 1 addition & 4 deletions src/utils/get-all-playlists.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
const data = [];


export default async function getAllPlaylistData(url: string, items: SpotifyApi.PlaylistObjectSimplified[] = []): Promise<SpotifyApi.PlaylistObjectSimplified[]> {
export default async function getAllPlaylistData(url: string): Promise<SpotifyApi.PlaylistObjectSimplified[]> {
const res: SpotifyApi.ListOfCurrentUsersPlaylistsResponse = await Spicetify.CosmosAsync.get(url);

return [
Expand Down
2 changes: 1 addition & 1 deletion src/utils/render-playlist-images.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export async function renderPlaylistImages(items: SpotifyApi.PlaylistObjectSimpl
const playlistAnchors = await getPlaylistAnchors();

playlistAnchors.forEach((playlistAnchor) => {
const id = playlistAnchor.href.split('/').at(-1)!;
const id = playlistAnchor.href.split('/').at(-1) as string;
const type = playlistAnchor.href.split('/').at(-2);
const existingImg = imgMap.get(id);

Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
"skipLibCheck": true,
"lib": ["es2022", "dom"],
},
"include": [
"./src/**/*.*"
Expand Down

0 comments on commit b4315d8

Please sign in to comment.