Aktualizovat content.js
This commit is contained in:
24
content.js
24
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);
|
||||
Reference in New Issue
Block a user