diff options
Diffstat (limited to 'static')
-rw-r--r-- | static/js/autorefresh.js | 4 | ||||
-rw-r--r-- | static/js/home.js | 192 |
2 files changed, 98 insertions, 98 deletions
diff --git a/static/js/autorefresh.js b/static/js/autorefresh.js index af61c8b..91ac05c 100644 --- a/static/js/autorefresh.js +++ b/static/js/autorefresh.js @@ -252,7 +252,7 @@ function counter() { loadJSON(); } else { refreshTime--; - document.getElementById("counter").innerHTML = refreshTime + 1; + document.getElementById("counter").textContent = refreshTime + 1; } } @@ -343,7 +343,7 @@ function startCounter() { function stopCounter(str) { clearInterval(refreshInterval); - document.getElementById("counter").innerHTML = str; + document.getElementById("counter").textContent = str; } function autoRefresh(e) { diff --git a/static/js/home.js b/static/js/home.js index 32ade31..e395638 100644 --- a/static/js/home.js +++ b/static/js/home.js @@ -1,35 +1,6 @@ -console.log("%c¡Es calidad BaI!", "font-size: 32px; font-weight: bold;"); - -function set_stylesheet(styletitle) { - opcs.style = styletitle; - parse(); - var links = document.getElementsByTagName("link"); - var found = false; - for (var i = 0; i < links.length; i++) { - var rel = links[i].getAttribute("rel"); - var title = links[i].getAttribute("title"); - if (rel.indexOf("style") != -1 && title) { - links[i].disabled = true; // IE needs this to work. IE needs to die. - if (styletitle == title) { - links[i].disabled = false; - found = true; - } - } - } -} - -function get_active_stylesheet() { - var links = document.getElementsByTagName("link"); - for (var i = 0; i < links.length; i++) { - var rel = links[i].getAttribute("rel"); - var title = links[i].getAttribute("title"); - if (rel.indexOf("style") != -1 && title && !links[i].disabled) return title; - } - return null; -} +console.log("%c¡Es calidad BaI!", "font-size:25px; font-weight:bold; text-decoration:underline; font-style:italic; text-decoration-line:underline overline;"); function check_news() { - console.log("check_news"); var last_t = opcs.last; var items = document.getElementsByClassName("ni"); var dates = document.getElementsByClassName("ni-d"); @@ -39,14 +10,25 @@ function check_news() { dates[i].innerHTML = '<img src="/new.gif" style="width:18px;height:7px;"><br />' + dates[i].innerHTML; + } else { + break; } opcs.last = (Date.now() / 1000) | 0; parse(); } +function zeropad(n, w) { + var n = String(n); + if (n.length >= w) { + return n; + } else { + return (String(0).repeat(w) + n).slice(n.length); + } +} + var lastTime = 0; var refreshInterval; -var refreshMaxTime = 30; +var refreshMaxTime = 10; var refreshTime; var unread = {}; var last_threads = 0; @@ -56,10 +38,8 @@ var http_request = new XMLHttpRequest(); function loadJSON() { stopCounter("..."); var data_file = - "/cgi/api/lastage?time=" + - lastTime + - "&limit=" + - document.getElementById("limit").value; + "/cgi/api/lastage?time=" + lastTime + + "&limit=" + document.getElementById("limit").value; http_request.open("GET", data_file, true); http_request.send(); } @@ -72,11 +52,19 @@ function setRead(threadId) { } function updatePostList(threads, serverTime) { - if (refreshMaxTime <= 120) refreshMaxTime += 5; + if (refreshMaxTime >= 120 && refreshMaxTime <= 270) { + refreshMaxTime += 30; + } else if (refreshMaxTime >= 60 && refreshMaxTime < 120) { + refreshMaxTime += 10; + } else if (refreshMaxTime < 60) { + refreshMaxTime += 5; + } + var arrayLength = threads.length; if (!arrayLength) return; - html = ""; + divbbs = ""; + divib = ""; last_threads = threads; last_serverTime = serverTime; @@ -87,63 +75,76 @@ function updatePostList(threads, serverTime) { 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); + news.push(thread.board_name + ": " + thread.content); new_unread = true; } - if (unread[thread.id]) html += '<span class="new">'; - html += - '<a href="' + - thread.url + - '" class="thread" data-brd="' + - thread.board_fulln + - '" data-unix="' + - thread.timestamp + - '" data-last="' + - thread.bumped + - '" data-img="' + - thread.thumb + - '"><span class="brd">[' + - thread.board_name + - ']</span> <span class="cont">' + - thread.content + - '</span> <span class="rep">(' + - thread.length + - ")</span></a>"; + + html = + '<a href="' + thread.url + '" class="thread">' + + '<span class="brd">[' + thread.board_abr + ':' + zeropad(thread.length, 3) + ']</span> ' + + thread.content + '</a>' + if (unread[thread.id]) { - html += "</span>"; + html = '<span class="new">' + html + "</span>"; newposts++; } + + if (thread.board_type == 1) { + divbbs += html; + } else { + divib += html; + } } - if (newposts) newTitle = "(" + newposts + ") " + newTitle; + + 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") + "Hay nuevos mensajes en:\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; + window.addEventListener('focus', markRead); + + document.getElementById("postlistbbs").innerHTML = divbbs; + document.getElementById("postlistib").innerHTML = divib; +} + +function markRead() { + document.title = bainame; + window.removeEventListener('focus', markRead); } function notif(title, msg) { - var n = new Notification(title, { body: msg }); - setTimeout(n.close.bind(n), 10000); + if (Notification.permission === "granted") { + var n = new Notification(title, { + body: msg, + icon: 'https://bienvenidoainternet.org/favicon.ico', + }); + setTimeout(n.close.bind(n), 5000); + } } function counter() { - if (refreshTime < 1) loadJSON(); - else { + if (refreshTime < 1) { + loadJSON(); + } else { refreshTime--; - document.getElementById("counter").innerHTML = "– " + (refreshTime + 1); + document.getElementById("counter").textContent = "(" + (refreshTime + 1) + ")"; } } @@ -155,18 +156,26 @@ function startCounter() { function stopCounter(str) { clearInterval(refreshInterval); - document.getElementById("counter").innerHTML = str; + document.getElementById("counter").textContent = str; } function autoRefresh(e) { if (chk.checked) { if (chk_snd) chk_snd.disabled = false; - Notification.requestPermission(); + + if (!("Notification" in window)) { + console.log("Alerta: Este navegador no soporta notificaciones."); + } else { + Notification.requestPermission(); + } + lastTime = Math.floor(Date.now() / 1000); refreshTime = refreshMaxTime; startCounter(); } else { - if (chk_snd) chk_snd.disabled = true; + if (chk_snd) { + chk_snd.disabled = true; + } stopCounter(""); } } @@ -177,7 +186,9 @@ http_request.onreadystatechange = function() { if (jsonObj.state == "success") { updatePostList(jsonObj.threads, jsonObj.time); lastTime = jsonObj.time; - if (chk.checked) startCounter(); + if (chk.checked) { + startCounter(); + } } } }; @@ -187,49 +198,38 @@ function parse() { } document.addEventListener("DOMContentLoaded", function() { - console.log("1"); - window.parent.document.title = document.getElementsByTagName( - "title" - )[0].textContent; + var bainame = "Bienvenido a Internet BBS/IB"; if (localStorage.hasOwnProperty("home")) opcs = JSON.parse(localStorage.getItem("home")); else { - opcs = { style: "IB", auto: false, sound: false, last: 0 }; + opcs = { auto: false, sound: false, last: 0 }; parse(); } - //set_stylesheet(opcs.style); - console.log("2"); - - //var css = document.getElementById("change_style").getElementsByTagName("a"); - //for (var j = 0; j < css.length; j++) { - // css[j].addEventListener("click", function(e) { - // e.preventDefault(); - // set_stylesheet(this.textContent); - // }); - //} - console.log("2a"); + + check_news(); + document.getElementById("autorefresh").addEventListener("click", function(e) { opcs.auto = !opcs.auto; autoRefresh(); parse(); }); - console.log("2b"); document.getElementById("autosound").addEventListener("click", function(e) { opcs.sound = !opcs.sound; parse(); }); - console.log("3"); - check_news(); - console.log("4"); chk = document.getElementById("autorefresh"); chk_snd = document.getElementById("autosound"); if (opcs.auto) { chk.checked = true; autoRefresh(); - } else chk.checked = false; - if (opcs.sound) chk_snd.checked = true; - else chk_snd.checked = false; - console.log("5"); + } else { + chk.checked = false; + } + if (opcs.sound) { + chk_snd.checked = true; + } else { + chk_snd.checked = false; + } }); |