diff --git a/owe.js b/owe.js index f59a505..db53f7c 100644 --- a/owe.js +++ b/owe.js @@ -2,13 +2,15 @@ var previousTextLength; var config_data; var unread_words = 0; -function loadSentences(alertIfNew = false) { +function loadSentences(alertIfNew = false, increaseUnread = true) { fetch("./data/sentences.txt", {headers: {"Cache-Control": "no-cache, no-store"}}) .then((response) => { return response.text().then((text) => { document.querySelector(".sentences").innerHTML = text; if (text.length > previousTextLength) { - document.getElementsByTagName("title")[0].innerText = (config_data.title ? config_data.title : "One Word Each") + " (" + ++unread_words + ")"; + if (increaseUnread) { + document.getElementsByTagName("title")[0].innerText = "(" + ++unread_words + ") " + (config_data.title ? config_data.title : "One Word Each") ; + } if (alertIfNew) { var newtxt = text.substring(previousTextLength, text.length); //var parser = new DOMParser(); @@ -41,6 +43,7 @@ function loadConfig() { fetch("./data/config.json").then((response) => { return response.text().then((text) => { config_data = JSON.parse(text); + setInterval(loadSentences, 5000, ((typeof config_data.notifications !== "undefined") ? config_data.notifications : true)); }); }).catch(() => { config_data = Object(); // leave empty @@ -62,7 +65,8 @@ function sendWord() { Http.open('POST', '.'); Http.onreadystatechange=(e)=>{ document.getElementById("wordinput").value = ""; - loadSentences(); + loadSentences(false, false); + resetUnread(); } Http.send(data); } @@ -96,7 +100,6 @@ window.onfocus = resetUnread; //setTimeout(loadSentences, 500); loadConfig(); loadSentences(); -setInterval(loadSentences, 5000, true); var input = document.getElementById("wordinput"); input.focus();