2021-09-05 02:21:11 +03:00
|
|
|
function sleep(ms) {
|
2022-04-30 21:18:10 +03:00
|
|
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
2021-09-05 02:21:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
async function add_boot_entry(entry_object) {
|
|
|
|
for (const entry in entry_object) {
|
|
|
|
if (do_sleep) {
|
|
|
|
let sleep_time;
|
2022-04-30 21:18:10 +03:00
|
|
|
if (typeof entry_object[entry]["sleep_time"] !== "undefined") {
|
|
|
|
sleep_time = entry_object[entry]["sleep_time"];
|
2021-09-05 02:21:11 +03:00
|
|
|
} else {
|
2022-04-30 21:18:10 +03:00
|
|
|
sleep_time = Math.floor(Math.random() * 2000 + 500);
|
2021-09-05 02:21:11 +03:00
|
|
|
}
|
|
|
|
await sleep(sleep_time);
|
|
|
|
}
|
|
|
|
|
2022-04-30 21:18:10 +03:00
|
|
|
let new_entry = document.createElement("p");
|
|
|
|
new_entry.innerHTML = entry_object[entry]["text"];
|
|
|
|
new_entry.classList.add("bmsg");
|
2021-09-05 02:21:11 +03:00
|
|
|
|
|
|
|
let entry_class;
|
2022-04-30 21:18:10 +03:00
|
|
|
switch (entry_object[entry]["type"]) {
|
|
|
|
case "error":
|
|
|
|
entry_class = "error";
|
2021-09-05 02:21:11 +03:00
|
|
|
break;
|
|
|
|
|
2022-04-30 21:18:10 +03:00
|
|
|
case "warning":
|
|
|
|
entry_class = "warn";
|
2021-09-05 02:21:11 +03:00
|
|
|
break;
|
|
|
|
|
2022-04-30 21:18:10 +03:00
|
|
|
case "ok":
|
|
|
|
entry_class = "ok";
|
2021-09-05 02:21:11 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2022-04-30 21:18:10 +03:00
|
|
|
throw `Type '${entry_object[entry]["type"]}' not found.`;
|
2021-09-05 02:21:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
new_entry.setAttribute("bmsg_type", entry_class);
|
|
|
|
boot.appendChild(new_entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-30 21:18:10 +03:00
|
|
|
function hash(string) {
|
|
|
|
return string.split("").reduce(function (a, b) {
|
|
|
|
a = (a << 5) - a + b.charCodeAt(0);
|
|
|
|
return a & a;
|
|
|
|
}, 0);
|
2021-09-05 02:21:11 +03:00
|
|
|
}
|