reinvent the wheel

This commit is contained in:
YOUR_NAME 2023-02-04 23:53:09 -06:00
parent b791da9187
commit f8f4cd8320
1 changed files with 44 additions and 0 deletions

44
wheel2.js Normal file
View File

@ -0,0 +1,44 @@
// 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]());
}
}, wheel2.updateTime);
});
updateables.map((elt) => {
const fxn = elt.getAttribute("data-wheel-update");
setInterval(() => {
window[fxn]();
}, wheel2.updateTime);
})
}
});
window.addEventListener('load', wheel2.init);