console.log("%c¡Es calidad BaI!", "font-size: 50px; font-weight: bold;"); function set_stylesheet(styletitle) { opcs.style = styletitle; parse(); var links=document.getElementsByTagName("link"); var found=false; for(var i=0;i last_t) { items[i].className += ' urgent'; dates[i].innerHTML = '
' + dates[i].innerHTML; } opcs.last = Date.now() / 1000 | 0; parse(); } var lastTime = 0; var refreshInterval; var refreshMaxTime = 30; var refreshTime; var unread = {}; var last_threads = 0; var last_serverTime = 0; var http_request = new XMLHttpRequest(); function loadJSON() { stopCounter("..."); var data_file = "/cgi/api/lastage?time=" + lastTime + "&limit=" + document.getElementById("limit").value; http_request.open("GET", data_file, true); http_request.send(); } function setRead(threadId) { if (threadId in unread) { unread[threadId] = false; updatePostList(last_threads, last_serverTime); } } function updatePostList(threads, serverTime) { if (refreshMaxTime <= 120) refreshMaxTime += 5; var arrayLength = threads.length; if (!arrayLength) return; html = ""; last_threads = threads; last_serverTime = serverTime; var newposts = 0; var newTitle = "Bienvenido a Internet BBS/IB"; var new_unread = false; var news = []; for (var i = 0; i < arrayLength; i++) { thread = threads[i]; if (thread.bumped >= lastTime) { unread[thread.id] = true; news.push('- ' + thread.board_fulln + ': ' + thread.content); new_unread = true; } if (unread[thread.id]) html += ''; html += '[' + thread.board_name + '] ' + thread.content + ' (' + thread.length + ')'; if (unread[thread.id]) { html += ''; newposts++; } } if (newposts) newTitle = '(' + newposts + ') ' + newTitle; if (new_unread) { document.getElementById("newposts").style = "color:red"; notif('Bienvenido a Internet BBS/IB', 'Hay nuevos mensajes:\n' + news.join('\n')); refreshMaxTime = 10; if (document.getElementById('autosound').checked) { document.getElementById("machina").volume = 0.6; document.getElementById("machina").play(); } } window.parent.document.title = newTitle; document.title = newTitle; document.getElementById("postlist").innerHTML = html; } function notif(title, msg) { var n = new Notification(title, { body: msg }); setTimeout(n.close.bind(n), 10000); } function counter() { if (refreshTime < 1) loadJSON(); else { refreshTime--; document.getElementById("counter").innerHTML = "– " + (refreshTime + 1); } } function startCounter() { refreshTime = refreshMaxTime; counter(); refreshInterval = setInterval(counter, 1000); } function stopCounter(str) { clearInterval(refreshInterval); document.getElementById("counter").innerHTML = str; } function autoRefresh(e) { if (chk.checked) { if (chk_snd) chk_snd.disabled = false; Notification.requestPermission(); lastTime = Math.floor(Date.now() / 1000); refreshTime = refreshMaxTime; startCounter(); } else { if (chk_snd) chk_snd.disabled = true; stopCounter(""); } } http_request.onreadystatechange = function() { if (http_request.readyState == 4) { var jsonObj = JSON.parse(http_request.responseText); if (jsonObj.state == "success") { updatePostList(jsonObj.threads, jsonObj.time); lastTime = jsonObj.time; if (chk.checked) startCounter(); } } } function parse() { localStorage.setItem("home", JSON.stringify(opcs)); } document.addEventListener("DOMContentLoaded", function() { window.parent.document.title = document.getElementsByTagName("title")[0].textContent; if (localStorage.hasOwnProperty("home")) opcs=JSON.parse(localStorage.getItem("home")); else { opcs={"style":"IB","auto":false,"sound":false,"last":0}; parse(); } set_stylesheet(opcs.style); var css = document.getElementById("change_style").getElementsByTagName("a"); for(var j=0;j