Ver código fonte

fix: loading class only applied if no cache entry

Sv443 1 ano atrás
pai
commit
8e661fec9e
2 arquivos alterados com 13 adições e 12 exclusões
  1. 0 1
      src/features/layout.css
  2. 13 11
      src/features/layout.ts

+ 0 - 1
src/features/layout.css

@@ -59,7 +59,6 @@
 }
 
 /* #MARKER queue buttons */
-/* TODO: */
 
 .side-panel.modular ytmusic-player-queue-item .song-info.ytmusic-player-queue-item {
   position: relative;

+ 13 - 11
src/features/layout.ts

@@ -147,7 +147,7 @@ async function addQueueButtons(queueItem: HTMLElement) {
     lyricsBtnElem.style.pointerEvents = "initial";
 
     lyricsBtnElem.addEventListener("click", async () => {
-      let lyricsUrl;
+      let lyricsUrl: string | undefined;
       const artistsSan = sanitizeArtists(artist);
       const songSan = sanitizeSong(song);
       const cachedLyricsUrl = getLyricsCacheEntry(artistsSan, songSan);
@@ -155,23 +155,25 @@ async function addQueueButtons(queueItem: HTMLElement) {
       if(cachedLyricsUrl)
         lyricsUrl = cachedLyricsUrl;
       else if(!songInfo.hasAttribute("data-bytm-loading")) {
-        if(!cachedLyricsUrl)
+        const imgEl = lyricsBtnElem.querySelector("img") as HTMLImageElement;
+        if(!cachedLyricsUrl) {
           songInfo.setAttribute("data-bytm-loading", "");
 
-        const imgEl = lyricsBtnElem.querySelector("img") as HTMLImageElement;
-        imgEl.classList.add("bytm-spinner");
-        imgEl.src = getAssetUrl("loading.svg");
+          imgEl.classList.add("bytm-spinner");
+          imgEl.src = getAssetUrl("loading.svg");
+        }
 
         lyricsUrl = cachedLyricsUrl ?? await getGeniusUrl(artistsSan, songSan);
 
-        if(!cachedLyricsUrl)
+        if(!cachedLyricsUrl) {
           songInfo.removeAttribute("data-bytm-loading");
 
-        // so the new image doesn't "blink"
-        setTimeout(() => {
-          imgEl.src = getAssetUrl("external/genius.png");
-          imgEl.classList.remove("bytm-spinner");
-        }, 100);
+          // so the new image doesn't "blink"
+          setTimeout(() => {
+            imgEl.src = getAssetUrl("external/genius.png");
+            imgEl.classList.remove("bytm-spinner");
+          }, 100);
+        }
 
         if(!lyricsUrl) {
           if(confirm("Couldn't find a lyrics page for this song.\nDo you want to open genius.com to manually search for it?"))