What if you could live for a 1000 years?
This commit is contained in:
parent
1820c7b9ed
commit
48a4809f1f
109 changed files with 2254 additions and 1814 deletions
assets/makai.js/np
45
assets/makai.js/np/client.js
Normal file
45
assets/makai.js/np/client.js
Normal file
|
@ -0,0 +1,45 @@
|
|||
#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]);
|
||||
},
|
||||
};
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue