2023-02-12 19:11:50 +00:00
|
|
|
function createElement(name, attrs, ...children) {
|
|
|
|
const el = document.createElement(name);
|
|
|
|
|
|
|
|
for (const attr in attrs) {
|
|
|
|
if(attr.startsWith("on")) {
|
|
|
|
el[attr] = attrs[attr];
|
|
|
|
} else {
|
|
|
|
el.setAttribute(attr, attrs[attr])
|
|
|
|
}
|
2023-01-29 05:35:06 +00:00
|
|
|
}
|
2023-02-12 19:11:50 +00:00
|
|
|
|
|
|
|
for (const child of children) {
|
|
|
|
if (child == null) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
el.appendChild(child)
|
2023-01-26 22:29:16 +00:00
|
|
|
}
|
2023-02-12 19:11:50 +00:00
|
|
|
|
|
|
|
return el
|
2023-01-26 22:29:16 +00:00
|
|
|
}
|
|
|
|
|
2023-02-12 19:11:50 +00:00
|
|
|
export function createElementNS(name, attrs, ...children) {
|
|
|
|
var svgns = "http://www.w3.org/2000/svg";
|
|
|
|
var el = document.createElementNS(svgns, name);
|
|
|
|
|
|
|
|
for (const attr in attrs) {
|
|
|
|
if(attr.startsWith("on")) {
|
|
|
|
el[attr] = attrs[attr];
|
|
|
|
} else {
|
|
|
|
el.setAttribute(attr, attrs[attr])
|
|
|
|
}
|
2023-01-26 22:29:16 +00:00
|
|
|
}
|
2023-02-12 19:11:50 +00:00
|
|
|
|
|
|
|
for (const child of children) {
|
|
|
|
if (child == null) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
el.appendChild(child)
|
|
|
|
}
|
|
|
|
|
|
|
|
return el
|
|
|
|
}
|
|
|
|
|
|
|
|
export function p(attrs, ...children) {
|
|
|
|
return createElement("p", attrs, ...children)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function span(attrs, ...children) {
|
|
|
|
return createElement("span", attrs, ...children)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function div(attrs, ...children) {
|
|
|
|
return createElement("div", attrs, ...children)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function a(attrs, ...children) {
|
|
|
|
return createElement("a", attrs, ...children)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function i(attrs, ...children) {
|
|
|
|
return createElement("i", attrs, ...children)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function form(attrs, ...children) {
|
|
|
|
return createElement("form", attrs, ...children)
|
2023-01-28 07:51:34 +00:00
|
|
|
}
|
|
|
|
|
2023-02-14 03:41:09 +00:00
|
|
|
export function img(alt, attrs, ...children) {
|
2023-02-12 21:44:45 +00:00
|
|
|
attrs['onerror'] = (event) => event.target.remove()
|
2023-02-14 03:41:09 +00:00
|
|
|
attrs['alt'] = alt
|
2023-02-12 19:11:50 +00:00
|
|
|
return createElement("img", attrs, ...children)
|
2023-02-01 03:21:19 +00:00
|
|
|
}
|
|
|
|
|
2023-02-12 19:11:50 +00:00
|
|
|
export function input(attrs, ...children) {
|
|
|
|
return createElement("input", attrs, ...children)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function button(attrs, ...children) {
|
|
|
|
return createElement("button", attrs, ...children)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function path(attrs, ...children) {
|
|
|
|
return createElementNS("path", attrs, ...children)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function svg(attrs, ...children) {
|
|
|
|
return createElementNS("svg", attrs, ...children)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function body(attrs, ...children) {
|
|
|
|
return createElement("body", attrs, ...children)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function textarea(attrs, ...children) {
|
|
|
|
return createElement("textarea", attrs, ...children)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function parse(html) {
|
|
|
|
return document.createRange().createContextualFragment(html);
|
|
|
|
}
|
|
|
|
|
2023-02-14 03:41:09 +00:00
|
|
|
export function pfpl(id) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-02-12 19:11:50 +00:00
|
|
|
export function pfp(id) {
|
2023-02-14 03:41:09 +00:00
|
|
|
return img('pfp', {src: `/image/avatar?user_id=${id}`})
|
2023-02-12 19:11:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function banner(id) {
|
2023-02-14 03:41:09 +00:00
|
|
|
return img('banner', {src: `/image/banner?user_id=${id}`})
|
2023-01-31 03:55:14 +00:00
|
|
|
}
|
|
|
|
|
2023-01-28 07:51:34 +00:00
|
|
|
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
|
|
|
|
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
|
|
|
|
|
|
const letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
|
|
|
|
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
|
|
|
|
|
2023-02-12 19:11:50 +00:00
|
|
|
export function parseMonth(month) {
|
2023-01-28 07:51:34 +00:00
|
|
|
if (month > -1 && month < 26) {
|
|
|
|
return months[month]
|
|
|
|
} else {
|
|
|
|
let first = letters[month%26].toUpperCase()
|
|
|
|
let middle = letters[month*13%26]
|
|
|
|
let last = letters[month*50%26]
|
|
|
|
return first + middle + last
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-12 19:11:50 +00:00
|
|
|
export function parseDate(date) {
|
2023-01-28 07:51:34 +00:00
|
|
|
return parseMonth(date.getUTCMonth()) + ' ' + date.getUTCDate() + ', ' + date.getUTCFullYear() + ' ' + date.toLocaleTimeString();
|
2023-02-12 19:11:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function crawl(key, object) {
|
|
|
|
let data = []
|
|
|
|
for (const k in object) {
|
|
|
|
if (typeof object[k] === 'object') {
|
|
|
|
data.push(...crawl(key, object[k]))
|
|
|
|
} else if (k == key) {
|
|
|
|
data.push(object[k])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return data
|
2023-01-26 22:29:16 +00:00
|
|
|
}
|