So I'm fairly new to JavaScript and web development in general. I'm trying to write a script which reloads the a webpage if:
a. the file "forum.html" has updated
and
b. The textbox named "chat" is not empty.
as easy as this sounds I've managed to somehow go over my own head a little. The script seems to do what its designed to do. At first. But then somehow sets itself in a fury of reloading hell, and leaves the webpage unusable after trying (I'm assuming) to reload the page infinitely many times.
I'll leave thew script here:
function timer() {
}
//rest time
setTimeout(timer, 10000);
function ifThen() {
while (0 == 0) {
setTimeout(timer, 1000);
if (form.chat.value == "") {
break;
}
}
}
function mything() {
fetch('forum.html')
.then(response => response.text())
.then((data) => {
setTimeout(timer, 7500);
fetch('forum.html')
.then(response => response.text())
.then((data2) => {
if (data !== data2) {
setTimeout(ifThen, 100);
location.reload();
}
delete(data2);
})
delete(data);
})
}
setInterval(mything, 100);