#include xhr.js const MakaiNowPlaying = function(userName) { const noCoverUrl = 'https://lastfm.freetls.fastly.net/i/u/174s/2a96cbd8b46e442fc41c2b86b821562f.png'; const fetchTarget = `https://now.flash.moe/get.php?u=${userName}`; let lastResult; const format = info => { const coverUrl = info.images?.large ?? ''; const result = { first: lastResult === undefined, changed: false, name: info.name, now_playing: !!info.nowplaying, url: info.url, cover: coverUrl === noCoverUrl ? '' : coverUrl, artist: { name: info.artist?.name ?? '', url: info.url.split('/_/')[0] }, }; if(lastResult === undefined || result.url !== lastResult.url || result.now_playing !== lastResult.now_playing) result.changed = true; lastResult = result; return result; }; return { fetch: async () => { const result = await $x.get(fetchTarget); if(result.status !== 200) throw `http ${result.status}`; let info = result.json(); if(info.length < 1) throw 'no data'; return format(info[0]); }, }; };