fix scrobblerrr
This commit is contained in:
parent
21ad28c980
commit
8a6d08d276
1 changed files with 11 additions and 5 deletions
|
|
@ -4,7 +4,7 @@
|
||||||
<div class="lastfm">
|
<div class="lastfm">
|
||||||
<img class="cover" src="https://lastfm.freetls.fastly.net/i/u/300x300/c6f59c1e5e7240a4c0d427abd71f3dbb.jpg">
|
<img class="cover" src="https://lastfm.freetls.fastly.net/i/u/300x300/c6f59c1e5e7240a4c0d427abd71f3dbb.jpg">
|
||||||
<div class="info">
|
<div class="info">
|
||||||
<h3 class="title">loading...</h3>
|
<h3 class="title"><a target="_blank">loading...</a></h3>
|
||||||
on <span class="album"><strong>loading...</strong></span><br>
|
on <span class="album"><strong>loading...</strong></span><br>
|
||||||
by <span class="artist"><strong>loading...</strong></span><br>
|
by <span class="artist"><strong>loading...</strong></span><br>
|
||||||
at <time class="time"><strong>loading...</strong></time>
|
at <time class="time"><strong>loading...</strong></time>
|
||||||
|
|
@ -15,28 +15,34 @@
|
||||||
const json = await fetch("https://lastfm.nkko.workers.dev/?method=user.getRecentTracks&user=reidlab")
|
const json = await fetch("https://lastfm.nkko.workers.dev/?method=user.getRecentTracks&user=reidlab")
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.catch(err => console.error("last.fm fail:", err));
|
.catch(err => console.error("last.fm fail:", err));
|
||||||
|
console.log(json);
|
||||||
type LastFmResource<T> = { "#text": T }
|
type LastFmResource<T> = { "#text": T }
|
||||||
const track = json.recenttracks.track[0] as {
|
const track = json.recenttracks.track[0] as {
|
||||||
|
"@attr"?: { nowplaying: boolean },
|
||||||
album: LastFmResource<string>,
|
album: LastFmResource<string>,
|
||||||
artist: LastFmResource<string>,
|
artist: LastFmResource<string>,
|
||||||
date: LastFmResource<string>,
|
date?: LastFmResource<string>,
|
||||||
image: LastFmResource<string>[],
|
image: LastFmResource<string>[],
|
||||||
name: string,
|
name: string,
|
||||||
url: string,
|
url: string,
|
||||||
};
|
};
|
||||||
|
|
||||||
const title = document.querySelector(".title") as HTMLHeadingElement;
|
// i think it's okay to have this be an anchor element
|
||||||
|
// the aria role is link if href is present, otherwise generic (https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/a#technical_summary)
|
||||||
|
// also briefly stated in the html spec (https://html.spec.whatwg.org/#the-a-element)
|
||||||
|
const title = document.querySelector(".title a") as HTMLAnchorElement;
|
||||||
const album = document.querySelector(".album strong") as HTMLElement;
|
const album = document.querySelector(".album strong") as HTMLElement;
|
||||||
const artist = document.querySelector(".artist strong") as HTMLElement;
|
const artist = document.querySelector(".artist strong") as HTMLElement;
|
||||||
const time = document.querySelector(".time strong") as HTMLTimeElement;
|
const time = document.querySelector(".time strong") as HTMLTimeElement;
|
||||||
const cover = document.querySelector(".cover") as HTMLImageElement;
|
const cover = document.querySelector(".cover") as HTMLImageElement;
|
||||||
title.innerText = track.name;
|
title.innerText = track.name;
|
||||||
|
title.href = track.url;
|
||||||
album.innerText = track.album["#text"];
|
album.innerText = track.album["#text"];
|
||||||
artist.innerText = track.artist["#text"];
|
artist.innerText = track.artist["#text"];
|
||||||
time.innerText = new Date(track.date["#text"]).toLocaleString(undefined, {
|
time.innerText = (track.date && new Date(track.date["#text"]).toLocaleString(undefined, {
|
||||||
dateStyle: "medium",
|
dateStyle: "medium",
|
||||||
timeStyle: "short"
|
timeStyle: "short"
|
||||||
});
|
})) || (track["@attr"]?.nowplaying && "NOW!!!") || "epic error getting play time..";
|
||||||
|
|
||||||
// i chose a random thing from my library missing an album cover for this
|
// i chose a random thing from my library missing an album cover for this
|
||||||
// but apparently this goes for any missing track? cuz everyone else is doing it
|
// but apparently this goes for any missing track? cuz everyone else is doing it
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue