u.twoha.cc/static/util.js

32 lines
801 B
JavaScript

export function span(text) {
const s = document.createElement('span');
s.textContent = text;
return s;
}
export function popup(text) {
const d = document.createElement('div');
d.className = 'popup';
const s = span(text);
d.appendChild(s);
d.onanimationend = () => {
d.remove();
};
document.body.appendChild(d);
}
export function shuffle(array) {
for (let i = array.length - 1; i > 0; i--) {
let j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
}
export function addSheet(href) {
return new Promise((res, rej) => {
let link = document.createElement('link');
link.rel = 'stylesheet';
link.href = href;
link.onload = () => res(link);
link.onerror = () => rej();
document.head.appendChild(link);
});
}