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 imgElement = trackInfo.querySelector('img');
|
||||||
const albumCoverUrl = imgElement ? imgElement.src : null;
|
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 currentTimeEl = document.querySelector('[data-testid="playback-position"]');
|
||||||
const durationEl = document.querySelector('[data-testid="playback-duration"]');
|
const durationEl = document.querySelector('[data-testid="playback-duration"]');
|
||||||
|
|
||||||
const currentTime = currentTimeEl ? currentTimeEl.innerText : "0:00";
|
const currentTime = currentTimeEl ? currentTimeEl.innerText : "0:00";
|
||||||
const duration = durationEl ? durationEl.innerText : "0:00";
|
const duration = durationEl ? durationEl.innerText : "0:00";
|
||||||
|
|
||||||
// Spojený formát např. "0:53/3:45"
|
|
||||||
const progressFull = `${currentTime}/${duration}`;
|
const progressFull = `${currentTime}/${duration}`;
|
||||||
|
|
||||||
if (songTitle) {
|
// Spolehlivější detekce reklamy:
|
||||||
// Opraveno z artistTitle na artistName
|
// Reklamy na Spotify trvají vždy přesně 30 vteřin (0:30) nebo nemají běžné odkazy na skladbu
|
||||||
const currentSignature = `${artistName}-${songTitle}-${currentTime}`;
|
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) {
|
if (currentSignature !== lastSentSignature) {
|
||||||
lastSentSignature = currentSignature;
|
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, {
|
fetch(TARGET_URL, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@@ -38,10 +43,11 @@ function extractAndSendSong() {
|
|||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
artist: artistName,
|
artist: finalArtist,
|
||||||
title: songTitle,
|
title: finalTitle,
|
||||||
coverImg: albumCoverUrl,
|
coverImg: albumCoverUrl,
|
||||||
progressTime: progressFull,
|
progressTime: progressFull,
|
||||||
|
ad: isAd ? "true" : "false",
|
||||||
timestamp: new Date().toISOString()
|
timestamp: new Date().toISOString()
|
||||||
})
|
})
|
||||||
}).catch(err => {
|
}).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);
|
setInterval(extractAndSendSong, 1000);
|
||||||
Reference in New Issue
Block a user