summaryrefslogtreecommitdiff
path: root/scrobbles.js
diff options
context:
space:
mode:
authorMagdalena Szweda <hi@roughlynamed.net>2026-10-04 10:45:22 +0200
committerMagdalena Szweda <hi@roughlynamed.net>2026-10-06 14:09:45 +0200
commit44f4bb35b0057eca28ea7d7d93d765b9608d607d (patch)
tree41fffdec2e895d22e609f371ac9d171cba3f17c5 /scrobbles.js
parent9a0b9ef98d47951b00b84da7ed62820c0d00de89 (diff)
lotta fucking stuff
Diffstat (limited to 'scrobbles.js')
-rw-r--r--scrobbles.js26
1 files changed, 13 insertions, 13 deletions
diff --git a/scrobbles.js b/scrobbles.js
index a05cd82..5b2d6fa 100644
--- a/scrobbles.js
+++ b/scrobbles.js
@@ -19,9 +19,9 @@
* along with sophies.rocks. If not, see <https://www.gnu.org/licenses/>.
*/
-const LIBREFM_USER = 'sophii.xyz';
-const LIBREFM_API_KEY = '00000000000000000000000000000000';
-const LIBREFM_CACHE_KEY = 'scrobbles-cache';
+const LIBREFM_USER = "sophii.xyz";
+const LIBREFM_API_KEY = "00000000000000000000000000000000";
+const LIBREFM_CACHE_KEY = "scrobbles-cache";
const LIBREFM_CACHE_TTL_MS = 60_000;
async function loadScrobbles(limit = 7) {
@@ -33,7 +33,7 @@ async function loadScrobbles(limit = 7) {
const url = `https://libre.fm/2.0/?method=user.getrecenttracks&user=${LIBREFM_USER}&api_key=${LIBREFM_API_KEY}&format=json&limit=${limit}`;
const res = await fetch(url);
- if (!res.ok) throw new Error('Could not fetch scrobbles');
+ if (!res.ok) throw new Error("Could not fetch scrobbles");
const data = await res.json();
const tracks = data.recenttracks?.track ?? [];
@@ -42,26 +42,26 @@ async function loadScrobbles(limit = 7) {
}
async function renderScrobbles() {
- const list = document.querySelector('#recent-scrobbles ul');
+ const list = document.querySelector("#recent-scrobbles ul");
try {
const tracks = await loadScrobbles();
if (tracks.length === 0) {
- list.innerHTML = '<li>No scrobbles yet.</li>';
+ list.innerHTML = "<li>No scrobbles yet.</li>";
return;
}
- list.innerHTML = '';
- tracks.forEach(track => {
- const li = document.createElement('li');
- const artist = track.artist?.['#text'] ?? '';
- const nowPlaying = track['@attr']?.nowplaying === 'true';
+ list.innerHTML = "";
+ tracks.forEach((track) => {
+ const li = document.createElement("li");
+ const artist = track.artist?.["#text"] ?? "";
+ const nowPlaying = track["@attr"]?.nowplaying === "true";
li.innerHTML = `
<a href="${track.url}">${track.name}</a>
- <div>${artist}${nowPlaying ? ' - listening now' : ''}</div>
+ <div>${artist}${nowPlaying ? " - listening now" : ""}</div>
`;
list.appendChild(li);
});
} catch (err) {
- console.error('Failed to load libre.fm scrobbles:', err);
+ console.error("Failed to load libre.fm scrobbles:", err);
list.innerHTML = "<li>Couldn't load scrobbles right now.</li>";
}
}