Neighbourhood.omg.lol/wwwroot/js/script.js

32 lines
971 B
JavaScript
Raw Normal View History

2024-07-16 00:42:43 +00:00
window.injectCSharp = async function (helper) { window.CSHARP = helper }
async function delay(t) { return new Promise((resolve) => { setTimeout(resolve, t) }) }
async function removeElementById(id) { document.getElementById(id)?.remove() }
function scrollToId(id) {
const element = document.getElementById(id)
if (element instanceof HTMLElement)
element.scrollIntoView({behavior: "smooth",block: "start",inline: "nearest"})
}
function toggleDetails(id) {
const element = document.getElementById(id)
if (element instanceof HTMLDetailsElement) element.open = !element.open
}
function cacheBust(url) {
fetch(new Request(url), {
headers: new Headers({
"pragma": "no-cache",
"cache-control": "no-cache"
}),
mode: 'no-cors',
cache: 'no-cache',
})
.finally(() => {
let els = document.querySelectorAll(`[src="${url}"]`)
els.forEach(el => el.removeAttribute('src'))
els.forEach(el => el.src = url)
})
}