feat(*): refactor dynamic vs. static structure and distinctions; make additional elements dynamic
This commit is contained in:
parent
ca57082f01
commit
c021ea54ae
140 changed files with 1001 additions and 985 deletions
|
@ -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();
|
|
@ -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',
|
||||
];
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue