Helloworld/test.js
Edhueppe ed9194ff9e overhaul of image displaying at '/' (unfinished)
Co-authored-by: Avior <github@avior.me>
2023-02-21 17:31:31 +01:00

29 lines
781 B
JavaScript

let intervalIds = [];
function runIntervals() {
intervalIds.push(setInterval(function() {
let min = 0;
let max = 5;
let perso = Math.floor(Math.random() * (max - min + 1) + min);
let imgElement = document.getElementById(perso);
if (imgElement){
intervalIds.push(setInterval(function() {
fetch('http://localhost:3000/code')
then(function(response) {
return response.json();
})
.then(function(data) {
let perso = Math.floor(Math.random() * (max - min + 1) + min);
let imgElement = document.getElementById(perso);
imgElement.src = (data[1][0]);
});
}, 1000));
}
}, 5000));
}
function stopIntervals() {
intervalIds.forEach(clearInterval);
intervalIds = [];
}
runIntervals();