live fetch for now playing track
This commit is contained in:
parent
8a2026a419
commit
ac0eb1d8d4
3 changed files with 46 additions and 1 deletions
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
# coryd.dev
|
# coryd.dev
|
||||||
|
|
||||||
[](https://github.com/cdransf/coryd.dev/actions/workflows/vercel-scheduled-build.yaml) [](https://github.com/cdransf/social-utils/actions/workflows/scheduled.yaml)
|
[](https://github.com/cdransf/coryd.dev/actions/workflows/scheduled-build.yaml) [](https://github.com/cdransf/social-utils/actions/workflows/scheduled.yaml)
|
||||||
|
|
||||||
Hi! I'm Cory. 👋🏻
|
Hi! I'm Cory. 👋🏻
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,43 @@
|
||||||
document.documentElement.classList.add('dark')
|
document.documentElement.classList.add('dark')
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
;(function () {
|
||||||
|
const nowPlayingWrapper = document.getElementById("now-playing");
|
||||||
|
if (nowPlayingWrapper) {
|
||||||
|
try {
|
||||||
|
const localStorageKey = "CD_NOW_PLAYING";
|
||||||
|
const cachedTemplate = localStorage.getItem(localStorageKey);
|
||||||
|
|
||||||
|
if (window.localStorage && cachedTemplate) {
|
||||||
|
nowPlayingWrapper.innerHTML = "";
|
||||||
|
nowPlayingWrapper.insertAdjacentHTML("beforeEnd", cachedTemplate);
|
||||||
|
}
|
||||||
|
|
||||||
|
fetch("https://utils.coryd.dev/api/music?limit=1&period=7day")
|
||||||
|
.then((response) => response.json())
|
||||||
|
.then((data) => {
|
||||||
|
const track = data.recenttracks.track[0];
|
||||||
|
const artistName = track.artist["#text"];
|
||||||
|
const template = `<a href="${
|
||||||
|
track.url
|
||||||
|
}" class="no-underline dark:text-white text-gray-800 font-normal">${
|
||||||
|
track.name
|
||||||
|
}</a> by <a href="https://ddg.gg?q=!rym ${encodeURIComponent(
|
||||||
|
artistName
|
||||||
|
)}" class="no-underline dark:text-white text-gray-800 font-normal">${artistName}</a>`;
|
||||||
|
|
||||||
|
if (window.localStorage)
|
||||||
|
localStorage.setItem(localStorageKey, template);
|
||||||
|
|
||||||
|
nowPlayingWrapper.innerHTML = "";
|
||||||
|
nowPlayingWrapper.insertAdjacentHTML("beforeEnd", template);
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
nowPlayingWrapper.innerHTML = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})();
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -2,4 +2,12 @@
|
||||||
<a class="no-underline" href="/now"><h2 class="m-0 text-xl font-black leading-tight tracking-normal md:text-2xl text-primary-500 hover:text-primary-400 mb-4">Now</h2></a>
|
<a class="no-underline" href="/now"><h2 class="m-0 text-xl font-black leading-tight tracking-normal md:text-2xl text-primary-500 hover:text-primary-400 mb-4">Now</h2></a>
|
||||||
<p>I'm a software developer in Camarillo, California. I enjoy hanging out with my beautiful family and 4 rescue dogs, technology, automation, music, writing, reading and tv and movies.</p>
|
<p>I'm a software developer in Camarillo, California. I enjoy hanging out with my beautiful family and 4 rescue dogs, technology, automation, music, writing, reading and tv and movies.</p>
|
||||||
<p>{{ status.emoji }} {{ status.content }}</p>
|
<p>{{ status.emoji }} {{ status.content }}</p>
|
||||||
|
<p class="mb-0">
|
||||||
|
<span class="icon-inline">
|
||||||
|
{% heroicon "solid" "music-note" "Now playing" "width=20 height=20" %}
|
||||||
|
</span>
|
||||||
|
<span id="now-playing">
|
||||||
|
<span class="blur-md">Loading track</span>
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
Reference in a new issue