From 876a537354c2c88798c3ff28bdcab733eecddcb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Hosa?= Date: Sat, 19 Sep 2026 22:00:28 +0000 Subject: [PATCH] =?UTF-8?q?Nahr=C3=A1t=20soubory=20do=20=E2=80=9E/?= =?UTF-8?q?=E2=80=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- content.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ manifest.json | 20 ++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 content.js create mode 100644 manifest.json diff --git a/content.js b/content.js new file mode 100644 index 0000000..5475b3f --- /dev/null +++ b/content.js @@ -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 }); \ No newline at end of file diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..3a32f0b --- /dev/null +++ b/manifest.json @@ -0,0 +1,20 @@ +{ + "manifest_version": 3, + "name": "Spotify IP Sender", + "version": "1.0", + "permissions": [ + "activeTab", + "storage" + ], + "host_permissions": [ + "https://open.spotify.com/*", + "http://*/*", + "https://*/*" + ], + "content_scripts": [ + { + "matches": ["https://open.spotify.com/*"], + "js": ["content.js"] + } + ] +} \ No newline at end of file