Nahrát soubory do „/“

This commit is contained in:
2026-09-19 22:00:28 +00:00
parent 3dcec7d43f
commit 876a537354
2 changed files with 65 additions and 0 deletions

45
content.js Normal file
View File

@@ -0,0 +1,45 @@
const TARGET_URL = "http://localhost:8080/endpoint";
let lastSentSong = "";
function extractAndSendSong() {
// Najdeme widget "Now Playing" v levém dolním rohu Spotify
const trackInfo = document.querySelector('[data-testid="now-playing-widget"]');
if (trackInfo) {
const links = trackInfo.querySelectorAll('a');
const songTitle = links[0] ? links[0].innerText : null;
const artistName = links[1] ? links[1].innerText : "Unknown Artist";
if (songTitle) {
const currentTrackString = `${artistName} - ${songTitle}`;
// Odesíláme pouze pokud se písnička změnila, abychom zbytečně nezatěžovali server
if (currentTrackString !== lastSentSong) {
lastSentSong = currentTrackString;
console.log("Odesílám skladbu:", currentTrackString);
fetch(TARGET_URL, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
artist: artistName,
title: songTitle,
timestamp: new Date().toISOString()
})
}).catch(err => {
console.error("Chyba při odesílání:", err);
});
}
}
}
}
// Sledujeme změny na stránce, protože Spotify funguje jako Single Page Application
const observer = new MutationObserver(() => {
extractAndSendSong();
});
observer.observe(document.body, { childList: true, subtree: true });