diff --git a/.env b/.env index c0c68b1..2ddb765 100644 --- a/.env +++ b/.env @@ -1 +1,2 @@ -PORT=3000 \ No newline at end of file +PORT=3000 +LFM_API_KEY=8f9b0255cc55a19f82d37c22600aff1a \ No newline at end of file diff --git a/assets/elements.css b/assets/elements.css index 3b73489..446820a 100644 --- a/assets/elements.css +++ b/assets/elements.css @@ -51,6 +51,7 @@ div { img { vertical-align: middle; + background-color: #fff8; } a { @@ -94,4 +95,14 @@ button, input[type=submit] { button:active, input[type=submit]:active { background-color: transparent; color: var(--color-accent); +} + +marquee { + vertical-align: top; +} + +.clearfix:after { + content: ""; + display: table; + clear: both; } \ No newline at end of file diff --git a/index.js b/index.js index c483ec1..81e9f1b 100644 --- a/index.js +++ b/index.js @@ -95,13 +95,38 @@ app.get('/servers', async (req, res) => { }); }); +var units = { + year: 24 * 60 * 60 * 1000 * 365, + month: 24 * 60 * 60 * 1000 * 365 / 12, + day: 24 * 60 * 60 * 1000, + hour: 60 * 60 * 1000, + minute: 60 * 1000, + second: 1000 +} + +var rtf = new Intl.RelativeTimeFormat('en', { numeric: 'auto' }) + +var getRelativeTime = (d1, d2 = new Date()) => { + var elapsed = d1 - d2 + + // "Math.abs" accounts for both "past" & "future" scenarios + for (var u in units) + if (Math.abs(elapsed) > units[u] || u == 'second') + return rtf.format(Math.round(elapsed / units[u]), u) +} + app.get('/about', async (req, res) => { const linksJson = await fetch("https://cdn.abtmtr.link/site_content/v13/links.json") .catch(() => res.status(500).send()) .then((res) => res.json()); + const currentlyListeningJson = await fetch(`https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=MeowcaTheoRange&api_key=${process.env.LFM_API_KEY}&format=json&limit=2&extended=1`) + .catch(() => res.status(500).send()) + .then((res) => res.json()); res.render('about', { - links: linksJson + links: linksJson, + cl: currentlyListeningJson.recenttracks.track[0], + getRelativeTime }); }); diff --git a/views/pages/about.ejs b/views/pages/about.ejs index a3804e4..701331d 100644 --- a/views/pages/about.ejs +++ b/views/pages/about.ejs @@ -17,7 +17,7 @@ Non-binary, they/them

-

+

website, email @@ -30,6 +30,18 @@ USA

+ <% if (cl["@attr"] != null && cl["@attr"].nowplaying) { %> +

MeowcaTheoRange is currently listening to

+ <% } else { %> +

MeowcaTheoRange last listened to (<%= getRelativeTime(cl.date.uts * 1000) %>)

+ <% } %> +

" height="72" width="72">

+

+ <%= cl.name %>
+ <%= cl.album["#text"] %>
+ <%= cl.artist.name %>
+ See on Last.fm +

MeowcaTheoRange's links

where else is MeowcaTheoRange?