From 2e567e638b90ee9ae3e5d4160f60dcff064dd29e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Hosa?= Date: Wed, 23 Sep 2026 15:29:28 +0000 Subject: [PATCH] Aktualizovat content.js --- content.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/content.js b/content.js index 8c212dc..5d643c8 100644 --- a/content.js +++ b/content.js @@ -13,24 +13,29 @@ function extractAndSendSong() { const imgElement = trackInfo.querySelector('img'); const albumCoverUrl = imgElement ? imgElement.src : null; - // Získání uplynulého času a celkové délky písničky ze Spotify + // Získání času const currentTimeEl = document.querySelector('[data-testid="playback-position"]'); const durationEl = document.querySelector('[data-testid="playback-duration"]'); const currentTime = currentTimeEl ? currentTimeEl.innerText : "0:00"; const duration = durationEl ? durationEl.innerText : "0:00"; - // Spojený formát např. "0:53/3:45" const progressFull = `${currentTime}/${duration}`; - if (songTitle) { - // Opraveno z artistTitle na artistName - const currentSignature = `${artistName}-${songTitle}-${currentTime}`; + // Spolehlivější detekce reklamy: + // Reklamy na Spotify trvají vždy přesně 30 vteřin (0:30) nebo nemají běžné odkazy na skladbu + const isAd = (duration === "0:30") || (links.length < 2) || (songTitle === null); + + const finalTitle = isAd ? "Reklama" : songTitle; + const finalArtist = isAd ? "Spotify" : artistName; + + if (finalTitle || isAd) { + const currentSignature = `${finalArtist}-${finalTitle}-${currentTime}-${isAd}`; if (currentSignature !== lastSentSignature) { lastSentSignature = currentSignature; - console.log("Odesílám data:", artistName, "-", songTitle, `[${progressFull}]`); + console.log("Odesílám data:", finalArtist, "-", finalTitle, `[${progressFull}]`, "Reklama:", isAd); fetch(TARGET_URL, { method: "POST", @@ -38,10 +43,11 @@ function extractAndSendSong() { "Content-Type": "application/json" }, body: JSON.stringify({ - artist: artistName, - title: songTitle, + artist: finalArtist, + title: finalTitle, coverImg: albumCoverUrl, progressTime: progressFull, + ad: isAd ? "true" : "false", timestamp: new Date().toISOString() }) }).catch(err => { @@ -52,5 +58,5 @@ function extractAndSendSong() { } } -// Kontrola každou vteřinu pro plynulou aktualizaci času v písničce +// Kontrola každou vteřinu setInterval(extractAndSendSong, 1000); \ No newline at end of file