var smf_lastNews = Date.now() / 1000; var smf_getNews = function () { var url = window.location.origin + "/forum/?action=.js;limit=1"; var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { var posts = []; try { posts = eval("("+xmlhttp.responseText+")"); } catch (e) {}; if (posts[0].timestamp > smf_lastNews) { localStorage.setItem("newPost", true); if (document.getElementById("boardindex_table")) { document.location.reload(); return; } } if (localStorage.getItem("newPost") == "true") { localStorage.setItem("newPost", false); smf_lastNews = posts[0].timestamp; document.title += " (neuer Beitrag)"; if (localStorage.getItem("notification.permission") != "false") { if (Notification.permission == "granted") { function decodeHtml(html) { var txt = document.createElement("textarea"); txt.innerHTML = html; return txt.value; } var notification = new Notification("MLD Forum", { icon: document.getElementById('favicon').href, body: "Neuer Post zum Thema:\n" + decodeHtml(posts[0].subject), }); notification.onclick = function () { document.location.href = posts[0].link; }; } else if (Notification.permission != "denied") { Notification.requestPermission(function(result) { smf_getNews(); }); } } } } } xmlhttp.open("GET", url, true); xmlhttp.send(); } window.setInterval(smf_getNews, 1000*60); if (localStorage.getItem("newPost") == "true") { window.setTimeout(smf_getNews, 1000); } else { // Testing //smf_lastNews = 0; window.setTimeout(smf_getNews, 1000*5); }