From 18f60364b920e0ff33bc4b8e3135590effeaf173 Mon Sep 17 00:00:00 2001 From: Renard Date: Sun, 29 Mar 2020 18:47:51 -0300 Subject: Prettier para JS --- static/js/autorefresh.js | 263 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 209 insertions(+), 54 deletions(-) (limited to 'static/js/autorefresh.js') diff --git a/static/js/autorefresh.js b/static/js/autorefresh.js index 3f9dbd4..cec1e33 100644 --- a/static/js/autorefresh.js +++ b/static/js/autorefresh.js @@ -18,15 +18,21 @@ function checkNew(e) { } function loadJSON() { - if (chk.checked) - stopCounter("..."); - if (manual) - document.getElementById("counter").innerText = "..."; + if (chk.checked) stopCounter("..."); + if (manual) document.getElementById("counter").innerText = "..."; var data_file; if (serviceType == 2 || serviceType == 3) { board = document.getElementsByName("board")[0].value; parent = document.getElementsByName("parent")[0].value; - data_file = "/cgi/api/thread?dir=" + board + "&id=" + parent + "&offset=" + thread_length + "&time=" + lastTime; + data_file = + "/cgi/api/thread?dir=" + + board + + "&id=" + + parent + + "&offset=" + + thread_length + + "&time=" + + lastTime; } else { return false; } @@ -38,69 +44,220 @@ function updateThread(posts, total_replies, serverTime) { var thread_div = document.getElementsByClassName("thread")[0]; if (serviceType == 2) var last_elem = document.getElementById("size"); else var last_elem = document.getElementsByClassName("cut")[0]; - for (var i=0; i' + post.name + ' ' + post.tripcode + ''; - else s_name = '' + post.name + ''; + if (post.tripcode) + s_name = + '' + + post.name + + " " + + post.tripcode + + ""; + else + s_name = + '' + + post.name + + ""; } else { - if (post.tripcode) s_name = '' + post.name + ' ' + post.tripcode + ''; - else s_name = '' + post.name + ''; + if (post.tripcode) + s_name = + '' + + post.name + + " " + + post.tripcode + + ""; + else s_name = '' + post.name + ""; } if (serviceType == 2) { if (post.file) { - s_img = '
' + Math.round(post.file_size/1024) + 'KB ' + post.file.substring(post.file.lastIndexOf(".")+1, post.file.length).toUpperCase() + '
'; - } else s_img = ''; - if (post.IS_DELETED == 1) div.innerHTML = '

' + num + ' : Mensaje eliminado por el usuario.

'; - else if (post.IS_DELETED == 2) div.innerHTML = '

' + num + ' : Mensaje eliminado por miembro del staff.

'; - else - div.innerHTML = '

' + num + ' : ' + s_name + ' : ' + post.timestamp_formatted + ' rep del

' + s_img + '
' + post.message + '
'; + s_img = + '
' + + Math.round(post.file_size / 1024) + + "KB " + + post.file + .substring(post.file.lastIndexOf(".") + 1, post.file.length) + .toUpperCase() + + "
"; + } else s_img = ""; + if (post.IS_DELETED == 1) + div.innerHTML = + '

' + + num + + " : Mensaje eliminado por el usuario.

"; + else if (post.IS_DELETED == 2) + div.innerHTML = + '

' + + num + + " : Mensaje eliminado por miembro del staff.

"; + else + div.innerHTML = + '

' + + num + + " : " + + s_name + + ' : ' + + post.timestamp_formatted + + ' rep del

' + + s_img + + '
' + + post.message + + "
"; } else { if (post.file) { if (post.image_width != 0) { - s_img = '
' + post.file + '-(' + post.file_size+ ' B, ' + post.image_width + 'x' + post.image_height + ')
'; + s_img = + '
' + + post.file + + "-(" + + post.file_size + + " B, " + + post.image_width + + "x" + + post.image_height + + ")
"; } else { - s_img = '
' + post.file + '-(' + post.file_size+ ' B)
'; + s_img = + '
' + + post.file + + "-(" + + post.file_size + + " B)
"; } - s_img += '' + post.id + ''; - s_msg = '
' + post.message + '
'; + s_img += + '' +
+          post.id +
+          ''; + s_msg = + '
' + + post.message + + "
"; } else { - s_img = ''; - s_msg = '
' + post.message + '
'; + s_img = ""; + s_msg = "
" + post.message + "
"; } if (post.IS_DELETED == 0) { - div.innerHTML = '
' + (post.subject ? (' ' + post.subject + '') : '') + ' ' + s_name + ' ' + '' + post.timestamp_formatted + ' No.' + post.id + ' rep
' + s_img + s_msg + '
'; + div.innerHTML = + '
' + + (post.subject + ? ' ' + post.subject + "" + : "") + + " " + + s_name + + " " + + '' + + post.timestamp_formatted + + ' No.' + + post.id + + ' rep
' + + s_img + + s_msg + + "
"; } } thread_div.insertBefore(div, last_elem); - thread_div.setAttribute("data-length",num); - if (serviceType == 2) document.getElementsByTagName("h3")[0].getElementsByTagName("span")[0].innerText = "("+num+" respuestas)"; + thread_div.setAttribute("data-length", num); + if (serviceType == 2) + document + .getElementsByTagName("h3")[0] + .getElementsByTagName("span")[0].innerText = "(" + num + " respuestas)"; } if (posts.length > 0) { - if (!manual) - refreshMaxTime = 10; + if (!manual) refreshMaxTime = 10; if (!document.hasFocus()) - if (posts.length > 1) notif(thread_title, posts.length + ' nuevos mensajes'); - else notif(thread_title, 'Un nuevo mensaje'); + if (posts.length > 1) + notif(thread_title, posts.length + " nuevos mensajes"); + else notif(thread_title, "Un nuevo mensaje"); } else { - if (refreshMaxTime <= 60) - refreshMaxTime += 5; + if (refreshMaxTime <= 60) refreshMaxTime += 5; } thread_length = parseInt(total_replies) + 1; //document.getElementsByClassName("thread")[0].firstChild.children[0].innerHTML = "("+thread_length+")"; new_unread = thread_length - thread_first_length; - if (new_unread) - document.title = "(" + new_unread + ") " + thread_title; - else - document.title = thread_title; + if (new_unread) document.title = "(" + new_unread + ") " + thread_title; + else document.title = thread_title; } function notif(title, msg) { @@ -115,7 +272,7 @@ function counter() { loadJSON(); } else { refreshTime--; - document.getElementById("counter").innerHTML = (refreshTime + 1); + document.getElementById("counter").innerHTML = refreshTime + 1; } } @@ -123,7 +280,9 @@ function detectService() { if (document.body.classList.contains("threadpage")) { if (!document.getElementById("n")) return; thread_title = document.title; - thread_length = parseInt(document.getElementsByClassName("thread")[0].dataset.length); + thread_length = parseInt( + document.getElementsByClassName("thread")[0].dataset.length + ); thread_first_length = thread_length; replylist = document.getElementsByClassName("reply"); lastr = replylist[replylist.length - 1].textContent; @@ -158,7 +317,9 @@ function detectService() { } else if (document.body.className === "res") { serviceType = 3; thread_title = document.title; - thread_length = parseInt(document.getElementsByClassName("thread")[0].dataset.length); + thread_length = parseInt( + document.getElementsByClassName("thread")[0].dataset.length + ); thread_first_length = thread_length; replylist = document.getElementsByClassName("thread"); replylist += document.getElementsByClassName("reply"); @@ -208,15 +369,13 @@ function stopCounter(str) { function autoRefresh(e) { chk_snd = document.getElementById("autosound"); if (document.getElementById("autorefresh").checked) { - if (chk_snd) - chk_snd.disabled = false; + if (chk_snd) chk_snd.disabled = false; Notification.requestPermission(); lastTime = Math.floor(Date.now() / 1000); refreshTime = refreshMaxTime; startCounter(); } else { - if (chk_snd) - document.getElementById("autosound").disabled = true; + if (chk_snd) document.getElementById("autosound").disabled = true; stopCounter("OFF"); } } @@ -228,15 +387,14 @@ http_request.onreadystatechange = function() { if (serviceType == 2 || serviceType == 3) updateThread(jsonObj.posts, jsonObj.total_replies, jsonObj.time); lastTime = jsonObj.time; - if (chk.checked) - startCounter(); + if (chk.checked) startCounter(); } if (!chk.checked) { document.getElementById("counter").innerText = "OFF"; } manual = 0; } -} +}; document.addEventListener("DOMContentLoaded", function() { if (!detectService()) return; @@ -254,17 +412,14 @@ document.addEventListener("DOMContentLoaded", function() { window.addEventListener("unload", function() { if (!serviceType) return; - + chk = document.getElementById("autorefresh"); chk_snd = document.getElementById("autosound"); - if (chk.checked) - localStorage.setItem("autorefresh", true); - else - localStorage.removeItem("autorefresh"); + if (chk.checked) localStorage.setItem("autorefresh", true); + else localStorage.removeItem("autorefresh"); if (!chk_snd) return; if (!document.getElementById("autosound").checked) localStorage.setItem("mainpage_nosound", true); - else - localStorage.removeItem("mainpage_nosound"); -}); \ No newline at end of file + else localStorage.removeItem("mainpage_nosound"); +}); -- cgit v1.2.1-18-gbd029