init: init
This commit is contained in:
commit
75bf105e98
6 changed files with 179 additions and 0 deletions
10
modules/copy.js
Normal file
10
modules/copy.js
Normal 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
24
modules/http.js
Normal 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")));
|
||||
}
|
||||
})
|
||||
})()
|
Loading…
Add table
Add a link
Reference in a new issue