Make ListenBrainz loop.
This commit is contained in:
parent
a03db59c65
commit
b3f855440f
|
@ -1,17 +1,34 @@
|
||||||
window.addEventListener('DOMContentLoaded', async () => {
|
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');
|
const result = await window.fetch('https://api.listenbrainz.org/1/user/BaukeXYZ/playing-now');
|
||||||
if (!result.ok) {
|
if (!result.ok) {
|
||||||
console.warn(result.status);
|
console.warn(result.status);
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await result.json();
|
const data = await result.json();
|
||||||
if (data.payload.listens.length === 0) {
|
if (data.payload.listens.length === 0) {
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const listen = data.payload.listens[0];
|
return data.payload.listens[0];
|
||||||
const listenHtml = `<div class="divider"></div><div class="listenbrainz">
|
}
|
||||||
|
|
||||||
|
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">
|
<a href="https://listenbrainz.org/user/BaukeXYZ/" target="_blank">
|
||||||
<img src="https://listenbrainz.org/static/img/logo_big.svg">
|
<img src="https://listenbrainz.org/static/img/logo_big.svg">
|
||||||
${listen.track_metadata.artist_name} - ${listen.track_metadata.track_name}
|
${listen.track_metadata.artist_name} - ${listen.track_metadata.track_name}
|
||||||
|
@ -19,4 +36,4 @@ window.addEventListener('DOMContentLoaded', async () => {
|
||||||
</div>`;
|
</div>`;
|
||||||
|
|
||||||
document.querySelector('.page-main').insertAdjacentHTML('beforeend', listenHtml);
|
document.querySelector('.page-main').insertAdjacentHTML('beforeend', listenHtml);
|
||||||
});
|
}
|
||||||
|
|
|
@ -1994,7 +1994,7 @@
|
||||||
dependencies:
|
dependencies:
|
||||||
"@types/yargs-parser" "*"
|
"@types/yargs-parser" "*"
|
||||||
|
|
||||||
"@typescript-eslint/eslint-plugin@*":
|
"@typescript-eslint/eslint-plugin@^5.4.0":
|
||||||
version "5.4.0"
|
version "5.4.0"
|
||||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.4.0.tgz#05e711a2e7b68342661fde61bccbd1531c19521a"
|
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.4.0.tgz#05e711a2e7b68342661fde61bccbd1531c19521a"
|
||||||
integrity sha512-9/yPSBlwzsetCsGEn9j24D8vGQgJkOTr4oMLas/w886ZtzKIs1iyoqFrwsX2fqYEeUwsdBpC21gcjRGo57u0eg==
|
integrity sha512-9/yPSBlwzsetCsGEn9j24D8vGQgJkOTr4oMLas/w886ZtzKIs1iyoqFrwsX2fqYEeUwsdBpC21gcjRGo57u0eg==
|
||||||
|
@ -2020,7 +2020,7 @@
|
||||||
eslint-scope "^5.1.1"
|
eslint-scope "^5.1.1"
|
||||||
eslint-utils "^3.0.0"
|
eslint-utils "^3.0.0"
|
||||||
|
|
||||||
"@typescript-eslint/parser@*":
|
"@typescript-eslint/parser@^5.4.0":
|
||||||
version "5.4.0"
|
version "5.4.0"
|
||||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-5.4.0.tgz#3aa83ce349d66e39b84151f6d5464928044ca9e3"
|
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-5.4.0.tgz#3aa83ce349d66e39b84151f6d5464928044ca9e3"
|
||||||
integrity sha512-JoB41EmxiYpaEsRwpZEYAJ9XQURPFer8hpkIW9GiaspVLX8oqbqNM8P4EP8HOZg96yaALiLEVWllA2E8vwsIKw==
|
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"
|
resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-8.3.0.tgz#f7471b20b6fe8a9a9254cc684454202886a2dd7a"
|
||||||
integrity sha512-BgZuLUSeKzvlL/VUjx/Yb787VQ26RU3gGjA3iiFvdsp/2bMfVIWUVP7tjxtjS0e+HP409cPlPvNkQloz8C91ew==
|
integrity sha512-BgZuLUSeKzvlL/VUjx/Yb787VQ26RU3gGjA3iiFvdsp/2bMfVIWUVP7tjxtjS0e+HP409cPlPvNkQloz8C91ew==
|
||||||
|
|
||||||
eslint-config-xo-typescript@*:
|
eslint-config-xo-typescript@^0.47.1:
|
||||||
version "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"
|
resolved "https://registry.yarnpkg.com/eslint-config-xo-typescript/-/eslint-config-xo-typescript-0.47.1.tgz#87b5865d8a3428fa26cc8dc3146ef4f712dfed46"
|
||||||
integrity sha512-BkbzIltZCWp8QLekKJKG8zJ/ZGezD8Z9FaJ+hJ5PrAVUGkIPmxXLLEHCKS3ax7oOqZLYQiG+jyKfQDIEdTQgbg==
|
integrity sha512-BkbzIltZCWp8QLekKJKG8zJ/ZGezD8Z9FaJ+hJ5PrAVUGkIPmxXLLEHCKS3ax7oOqZLYQiG+jyKfQDIEdTQgbg==
|
||||||
|
|
Loading…
Reference in New Issue