2023-01-13 22:59:03 +01:00
|
|
|
function get(id) {
|
|
|
|
return document.getElementById(id);
|
|
|
|
}
|
2023-01-15 14:12:55 +01:00
|
|
|
|
2023-01-15 16:36:09 +01:00
|
|
|
function set(id, text) {
|
|
|
|
get(id).innerText = text;
|
|
|
|
}
|
|
|
|
|
2023-01-14 20:47:27 +01:00
|
|
|
function get_class(class_name, parent) {
|
|
|
|
if (!parent) parent = document;
|
|
|
|
return parent.getElementsByClassName(class_name);
|
|
|
|
}
|
2023-01-15 14:12:55 +01:00
|
|
|
|
2023-01-14 20:47:27 +01:00
|
|
|
function for_all(class_name, func, parent) {
|
|
|
|
let a = get_class(class_name, parent);
|
2023-01-13 22:59:03 +01:00
|
|
|
for (let i = 0; i < a.length; i++) {
|
|
|
|
func(a[i]);
|
|
|
|
}
|
|
|
|
}
|
2023-01-15 14:12:55 +01:00
|
|
|
|
2023-01-13 22:59:03 +01:00
|
|
|
function load_img(img) {
|
|
|
|
img.classList.remove("unloaded");
|
|
|
|
}
|
2023-01-15 14:12:55 +01:00
|
|
|
|
2023-01-14 12:21:09 +01:00
|
|
|
function get_background() {
|
|
|
|
let bg = get("background");
|
2023-01-15 14:12:55 +01:00
|
|
|
return bg.children[1-1+bg.classList.contains("dark")];
|
2023-01-14 14:13:46 +01:00
|
|
|
}
|
2023-01-15 14:12:55 +01:00
|
|
|
|
2023-01-14 14:13:46 +01:00
|
|
|
function safe_text(text) {
|
|
|
|
text = text.replaceAll("<", "<");
|
|
|
|
text = text.replaceAll(">", ">");
|
|
|
|
text = text.replaceAll("&", "&");
|
|
|
|
return text;
|
|
|
|
}
|
2023-01-15 14:12:55 +01:00
|
|
|
|
2023-01-14 14:13:46 +01:00
|
|
|
function mk_entry(app) {
|
2023-01-15 16:53:23 +01:00
|
|
|
let new_tab = get_bool("open_new_tab") ? ` target="_blank"` : "";
|
2023-01-14 14:13:46 +01:00
|
|
|
return `
|
2023-01-15 16:53:23 +01:00
|
|
|
<a class="box" href="${safe_text(app["href"])}"${new_tab}>
|
2023-01-14 14:13:46 +01:00
|
|
|
<img src="${safe_text(app["icon"])}">
|
|
|
|
<div>
|
|
|
|
<div class="name">${safe_text(app["name"])}</div>
|
|
|
|
<div class="desc">${safe_text(app["desc"])}</div>
|
|
|
|
</div>
|
|
|
|
</a>`;
|
2023-01-15 14:12:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function config(key, value) {
|
2023-01-15 16:06:34 +01:00
|
|
|
let def = CONFIG["ui"][key];
|
2023-01-15 14:12:55 +01:00
|
|
|
let val = localStorage.getItem(key);
|
|
|
|
if (def == value && !val) return;
|
|
|
|
if (value !== undefined) {
|
|
|
|
localStorage.setItem(key, value);
|
|
|
|
return;
|
|
|
|
}
|
2023-01-15 16:06:34 +01:00
|
|
|
if (!val) val = CONFIG["ui"][key].toString();
|
2023-01-15 14:12:55 +01:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_bool(key) {
|
|
|
|
return config(key) == "true";
|
2023-01-15 16:36:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function load_config(conf) {
|
|
|
|
CONFIG = JSON.parse(conf);
|
|
|
|
let ui = CONFIG.ui;
|
|
|
|
set("app-name", ui.name);
|
|
|
|
set("app-desc", ui.desc);
|
|
|
|
get("app-icon").src = ui.icon;
|
|
|
|
if (ui.hosted_by) set("app-hostedby", ui.hosted_by);
|
|
|
|
else get("app-hostedby").parentNode.style.display = "none";
|
|
|
|
load_apps();
|
2023-01-14 12:21:09 +01:00
|
|
|
}
|