1
Fork 0

Make ListenBrainz loop.

This commit is contained in:
Bauke 2021-11-27 14:50:35 +01:00
parent a03db59c65
commit b3f855440f
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
2 changed files with 25 additions and 8 deletions

View File

@ -1,17 +1,34 @@
window.addEventListener('DOMContentLoaded', async () => {
document.querySelector('.page-main').insertAdjacentHTML('beforeend', '<div class="divider"></div>');
const loop = async () => insertHtml(await getCurrentListen());
await loop();
setInterval(loop, 60 * 1000);
});
async function getCurrentListen() {
const result = await window.fetch('https://api.listenbrainz.org/1/user/BaukeXYZ/playing-now');
if (!result.ok) {
console.warn(result.status);
return;
return null;
}
const data = await result.json();
if (data.payload.listens.length === 0) {
return;
return null;
}
const listen = data.payload.listens[0];
const listenHtml = `<div class="divider"></div><div class="listenbrainz">
return data.payload.listens[0];
}
function insertHtml(listen) {
const existing = document.querySelector('.listenbrainz');
if (existing !== null) {
existing.remove();
}
const listenHtml = `<div class="listenbrainz">
<a href="https://listenbrainz.org/user/BaukeXYZ/" target="_blank">
<img src="https://listenbrainz.org/static/img/logo_big.svg">
${listen.track_metadata.artist_name} - ${listen.track_metadata.track_name}
@ -19,4 +36,4 @@ window.addEventListener('DOMContentLoaded', async () => {
</div>`;
document.querySelector('.page-main').insertAdjacentHTML('beforeend', listenHtml);
});
}

View File

@ -1994,7 +1994,7 @@
dependencies:
"@types/yargs-parser" "*"
"@typescript-eslint/eslint-plugin@*":
"@typescript-eslint/eslint-plugin@^5.4.0":
version "5.4.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.4.0.tgz#05e711a2e7b68342661fde61bccbd1531c19521a"
integrity sha512-9/yPSBlwzsetCsGEn9j24D8vGQgJkOTr4oMLas/w886ZtzKIs1iyoqFrwsX2fqYEeUwsdBpC21gcjRGo57u0eg==
@ -2020,7 +2020,7 @@
eslint-scope "^5.1.1"
eslint-utils "^3.0.0"
"@typescript-eslint/parser@*":
"@typescript-eslint/parser@^5.4.0":
version "5.4.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-5.4.0.tgz#3aa83ce349d66e39b84151f6d5464928044ca9e3"
integrity sha512-JoB41EmxiYpaEsRwpZEYAJ9XQURPFer8hpkIW9GiaspVLX8oqbqNM8P4EP8HOZg96yaALiLEVWllA2E8vwsIKw==
@ -4098,7 +4098,7 @@ eslint-config-prettier@^8.3.0:
resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-8.3.0.tgz#f7471b20b6fe8a9a9254cc684454202886a2dd7a"
integrity sha512-BgZuLUSeKzvlL/VUjx/Yb787VQ26RU3gGjA3iiFvdsp/2bMfVIWUVP7tjxtjS0e+HP409cPlPvNkQloz8C91ew==
eslint-config-xo-typescript@*:
eslint-config-xo-typescript@^0.47.1:
version "0.47.1"
resolved "https://registry.yarnpkg.com/eslint-config-xo-typescript/-/eslint-config-xo-typescript-0.47.1.tgz#87b5865d8a3428fa26cc8dc3146ef4f712dfed46"
integrity sha512-BkbzIltZCWp8QLekKJKG8zJ/ZGezD8Z9FaJ+hJ5PrAVUGkIPmxXLLEHCKS3ax7oOqZLYQiG+jyKfQDIEdTQgbg==