muse/static/main.js

66 lines
1.5 KiB
JavaScript

function songNode(info) {
let wrap = document.createElement("div");
let a = document.createElement("a");
let cover = document.createElement("img");
let title = document.createElement("div");
let date = document.createElement("div");
title.innerText = "" + info["artist"] + " - " + (info["track"] == undefined ? info["album"] : info["track"]);
options = {
year: "numeric",
month:"numeric",
day:"numeric"
};
if (info["date"] !== undefined) {
date.innerText = new Date(info["date"].replace(/-/g, "/"))
.toLocaleString(window.navigator.language, options);
}
if (info["cover"] !== undefined) {
cover.setAttribute("src", info["cover"]);
} else {
cover.setAttribute("src", "static/noalbum.jpg");
}
title.setAttribute("class", "title");
cover.setAttribute("class", "cover");
date.setAttribute("class", "date");
wrap.setAttribute("class", "elem");
wrap.appendChild(cover);
wrap.appendChild(title);
wrap.appendChild(date);
if (info["linkto"]) {
a.setAttribute("href", info["linkto"]);
}
a.appendChild(wrap);
return a;
}
function addimages(list) {
let cont = document.querySelector("main");
let ret = false;
if (typeof list === "object" && list !== null) {
for (let i = 0; i < list.length; i++) {
cont.appendChild(songNode(list[i]));
}
ret = !list.length;
}
return ret;
}
window.onload = () => {
window.app = new ProgView("list", addimages);
window.app.down();
}
window.onbeforeunload = () => {
if (!window.app.stored) {
window.app.clear();
}
};