29 lines
781 B
JavaScript
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(); |