feat(*): refactor dynamic vs. static structure and distinctions; make additional elements dynamic

This commit is contained in:
Cory Dransfeldt 2025-06-11 20:27:41 -07:00
parent ca57082f01
commit c021ea54ae
No known key found for this signature in database
140 changed files with 1001 additions and 985 deletions

View file

@ -1,41 +0,0 @@
class NowPlaying extends HTMLElement {
static tagName = "now-playing";
static register(tagName = this.tagName, registry = globalThis.customElements) {
registry.define(tagName, this);
}
async connectedCallback() {
this.contentElement = this.querySelector(".content");
if (!this.contentElement) return;
const cache = localStorage.getItem("now-playing-cache");
if (cache) this.updateHTML(JSON.parse(cache));
await this.fetchAndUpdate();
}
async fetchAndUpdate() {
try {
const data = await this.fetchData();
const newHTML = data?.content;
if (newHTML && newHTML !== this.contentElement.innerHTML) {
this.updateHTML(newHTML);
localStorage.setItem("now-playing-cache", JSON.stringify(newHTML));
}
} catch {}
}
updateHTML(value) {
this.contentElement.innerHTML = value;
}
async fetchData() {
return fetch(`/api/playing.php?nocache=${Date.now()}`)
.then(response => response.json())
.catch(() => ({}));
}
}
NowPlaying.register();

View file

@ -7,7 +7,6 @@ const staticAssets = [
'/assets/fonts/dmi.woff2',
'/assets/fonts/ml.woff2',
'/assets/scripts/index.js',
'/assets/scripts/components/now-playing.js',
'/assets/scripts/components/select-pagination.js',
];