init: init

This commit is contained in:
Strix 2023-12-24 00:32:43 +01:00
commit 75bf105e98
No known key found for this signature in database
GPG key ID: 5F35B3B8537287A7
6 changed files with 179 additions and 0 deletions

10
modules/copy.js Normal file
View file

@ -0,0 +1,10 @@
// [x-copy-query="<query selector>"]
// [x-inner-text] - will use innerText
document.querySelectorAll("[x-copy-query]")
.forEach(e => {
if (e.hasAttribute("x-inner-text")) {
e.innerText = document.querySelector(e.getAttribute("x-copy-query")).innerHTML
} else {
e.innerHTML = document.querySelector(e.getAttribute("x-copy-query")).innerHTML
}
})

24
modules/http.js Normal file
View file

@ -0,0 +1,24 @@
// [x-get="<url>"]
// [x-inner-text] - will use inner text instead of html
(() => {
let storage = window.x0?.registerStorage("http") || {};
storage.intervals = [];
window.x0?.registerModuleRemoveHook("http", ({ intervals }) => intervals.forEach(p => clearInterval(p)));
document.querySelectorAll("[x-get]")
.forEach(async e => {
e.innerHTML += "*";
let update = async () => {
let result = await (await fetch(e.getAttribute("x-get"))).text();
if (e.hasAttribute("x-inner-text")) {
e.innerText = result;
} else {
e.innerHTML = result;
}
}
await update()
if (e.hasAttribute("x-get-refresh")) {
storage.intervals.push(setInterval(update, e.getAttribute("x-get-refresh")));
}
})
})()