47 lines
1.6 KiB
JavaScript
47 lines
1.6 KiB
JavaScript
// WHEEL2 HOW 2 USE
|
|
// =====================
|
|
// written by carly smallbird. GPL-3 license
|
|
// this should play fine with jquery. i'm not a snob
|
|
//
|
|
// data-wheel-timer = put this on the body with a number in miliseconds in it if you
|
|
// want to change the default timer
|
|
// data-wheel-get = name of callback function to periodically get data from
|
|
// data-wheel-update = name of callback function to periodically put data to
|
|
// data-wheel-transformer = function to call after getting data to transform it.
|
|
// requires above data-wheel-get
|
|
|
|
((wheel2) => {
|
|
wheel2.updateTime =
|
|
5000 ||
|
|
document.getElementsByTagName("body").getAttribute("data-wheel-timer") ?
|
|
parseInt(document.getElementsByTagName("body").getAttribute("data-wheel-timer")) :
|
|
null;
|
|
|
|
wheel2.init = () => {
|
|
const gettables = document.querySelectorAll("[data-wheel-get]");
|
|
const updateables = document.querySelectorAll("[data-wheel-update]");
|
|
gettables.map((elt) => {
|
|
const fxn = elt.getAttribute("data-wheel-get");
|
|
const transformer = elt.getAttribute("data-wheel-transformer");
|
|
setInterval(() => {
|
|
const getData = new Promise(() => {
|
|
window[fxn]();
|
|
});
|
|
if (transformer) {
|
|
getData.then(window[transformer]());
|
|
} else {
|
|
getData.then((data) => { elt.innerHTML = data; });
|
|
}
|
|
}, wheel2.updateTime);
|
|
});
|
|
updateables.map((elt) => {
|
|
const fxn = elt.getAttribute("data-wheel-update");
|
|
setInterval(() => {
|
|
window[fxn]();
|
|
}, wheel2.updateTime);
|
|
})
|
|
}
|
|
});
|
|
|
|
window.addEventListener('load', wheel2.init);
|