diff options
Diffstat (limited to 'static/js/mobile.js')
-rw-r--r-- | static/js/mobile.js | 370 |
1 files changed, 274 insertions, 96 deletions
diff --git a/static/js/mobile.js b/static/js/mobile.js index b4dd8cf..22606b9 100644 --- a/static/js/mobile.js +++ b/static/js/mobile.js @@ -10,65 +10,78 @@ function sendPost(e) { if (sendpost.readyState == 4) { button.disabled = false; var response = JSON.parse(sendpost.responseText); - if (response.state == "success") { postform.message.value = ""; checkNew(e); } - else alert(response.message); + if (response.state == "success") { + postform.message.value = ""; + checkNew(e); + } else alert(response.message); } - } + }; } function postClick(e) { e.preventDefault(); var sel = window.getSelection().toString(); - if (sel) { sel=sel.replace(/^/gm, ">")+"\n"; sel="\n"+sel; } + if (sel) { + sel = sel.replace(/^/gm, ">") + "\n"; + sel = "\n" + sel; + } insert(">>" + parseInt(this.innerHTML, 10) + sel); } function insert(text) { - var textarea=document.forms.postform.message; - if(textarea) { - if(textarea.createTextRange && textarea.caretPos) { // IE - var caretPos=textarea.caretPos; - caretPos.text=caretPos.text.charAt(caretPos.text.length-1)==" "?text+" ":text; - } else if(textarea.setSelectionRange) { // Firefox - var start=textarea.selectionStart; - var end=textarea.selectionEnd; - textarea.value=textarea.value.substr(0,start)+text+textarea.value.substr(end); - textarea.setSelectionRange(start+text.length,start+text.length); - } else { - textarea.value+=text+" "; - } - textarea.focus(); - } + var textarea = document.forms.postform.message; + if (textarea) { + if (textarea.createTextRange && textarea.caretPos) { + // IE + var caretPos = textarea.caretPos; + caretPos.text = + caretPos.text.charAt(caretPos.text.length - 1) == " " + ? text + " " + : text; + } else if (textarea.setSelectionRange) { + // Firefox + var start = textarea.selectionStart; + var end = textarea.selectionEnd; + textarea.value = + textarea.value.substr(0, start) + text + textarea.value.substr(end); + textarea.setSelectionRange(start + text.length, start + text.length); + } else { + textarea.value += text + " "; + } + textarea.focus(); + } return false; } function getPassword() { if (weabot.password) return weabot.password; - var char="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; - var pass=""; - for (var i=0;i<8;i++) { - var rnd = Math.floor(Math.random()*char.length); - pass += char.substring(rnd, rnd+1); - } + var char = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + var pass = ""; + for (var i = 0; i < 8; i++) { + var rnd = Math.floor(Math.random() * char.length); + pass += char.substring(rnd, rnd + 1); + } console.log(weabot.password); - weabot.password = pass; + weabot.password = pass; localStorage.setItem("weabot", JSON.stringify(weabot)); - return(pass); + return pass; } function saveInputs(e) { var e = e || window.event; var form = e.target || e.srcElement; - if(typeof(form.fielda) !== "undefined") weabot.name = form.fielda.value; - if(typeof(form.fielda) !== "undefined") weabot.email = form.fieldb.value; + if (typeof form.fielda !== "undefined") weabot.name = form.fielda.value; + if (typeof form.fielda !== "undefined") weabot.email = form.fieldb.value; localStorage.setItem("weabot", JSON.stringify(weabot)); } function setInputs() { - with(document.getElementById("postform")) { - if(typeof(fielda) !== 'undefined' && !fielda.value && weabot.name) fielda.value = weabot.name; - if(typeof(fielda) !== 'undefined' && !fieldb.value && weabot.email) fieldb.value = weabot.email; - if(!password.value) password.value = getPassword(); + with (document.getElementById("postform")) { + if (typeof fielda !== "undefined" && !fielda.value && weabot.name) + fielda.value = weabot.name; + if (typeof fielda !== "undefined" && !fieldb.value && weabot.email) + fieldb.value = weabot.email; + if (!password.value) password.value = getPassword(); addEventListener("submit", saveInputs); } } @@ -84,12 +97,12 @@ function showMenu(e) { var num = parseInt(post.getElementsByClassName("num")[0].innerText, 10); } else { var id = post.getElementsByClassName("num")[0].innerText; - var num = ((post.className === "first") ? 1 : 0); + var num = post.className === "first" ? 1 : 0; } var menu = document.createElement("div"); menu.id = "mnu-list"; - menu.style.top = (e.pageY + 5) + "px"; - menu.style.left = (e.pageX + 5) + "px"; + menu.style.top = e.pageY + 5 + "px"; + menu.style.left = e.pageX + 5 + "px"; document.body.appendChild(menu); menu = document.getElementById("mnu-list"); var rep = document.createElement("a"); @@ -97,15 +110,24 @@ function showMenu(e) { rep.innerText = "Denunciar post"; rep.addEventListener("click", function(e) { var reason = prompt("Razón de denuncia:"); - if (reason === "") while(reason === "") reason = prompt("Error: Ingresa una razón."); + if (reason === "") + while (reason === "") reason = prompt("Error: Ingresa una razón."); if (reason) { var rep_req = new XMLHttpRequest(); - var report = "/cgi/report/" + brd + "/" + id + ((num) ? "/" + num : "") + "?reason=" + reason; + var report = + "/cgi/report/" + + brd + + "/" + + id + + (num ? "/" + num : "") + + "?reason=" + + reason; rep_req.open("GET", report, true); rep_req.send(); rep_req.onreadystatechange = function() { - if (rep_req.readyState == 4 && rep_req.status == 200) alert("Denuncia enviada."); - } + if (rep_req.readyState == 4 && rep_req.status == 200) + alert("Denuncia enviada."); + }; } }); menu.appendChild(rep); @@ -113,9 +135,17 @@ function showMenu(e) { del.href = "#"; del.innerText = "Eliminar post"; del.addEventListener("click", function(e) { - if(confirm("¿Seguro que deseas borrar el mensaje "+((num) ? num : id)+"?")) { + if ( + confirm("¿Seguro que deseas borrar el mensaje " + (num ? num : id) + "?") + ) { var del_req = new XMLHttpRequest(); - var del_form = "/cgi/api/delete?dir=" + brd + "&id=" + id + "&password=" + postform.password.value; + var del_form = + "/cgi/api/delete?dir=" + + brd + + "&id=" + + id + + "&password=" + + postform.password.value; del_req.open("GET", del_form, true); del_req.send(); del_req.onreadystatechange = function() { @@ -131,7 +161,7 @@ function showMenu(e) { } } else if (response.state == "failed") alert(response.message); } - } + }; } }); menu.appendChild(del); @@ -141,9 +171,22 @@ function showMenu(e) { dfile.href = "#"; dfile.innerText = "Eliminar archivo"; dfile.addEventListener("click", function(e) { - if(confirm("¿Seguro que deseas borrar el archivo del mensaje "+((num) ? num : id)+"?")) { + if ( + confirm( + "¿Seguro que deseas borrar el archivo del mensaje " + + (num ? num : id) + + "?" + ) + ) { var fdel_req = new XMLHttpRequest(); - var fdel_form = "/cgi/api/delete?dir=" + brd + "&id=" + id + "&password=" + postform.password.value + "&imageonly=true"; + var fdel_form = + "/cgi/api/delete?dir=" + + brd + + "&id=" + + id + + "&password=" + + postform.password.value + + "&imageonly=true"; fdel_req.open("GET", fdel_form, true); fdel_req.send(); fdel_req.onreadystatechange = function() { @@ -154,7 +197,7 @@ function showMenu(e) { post.removeChild(file); } else if (response.state == "failed") alert(response.message); } - } + }; } }); menu.appendChild(dfile); @@ -176,9 +219,16 @@ function closeMenu(e) { function searchSubjects() { var filter = document.getElementById("search").value.toLowerCase(); - var nodes = document.getElementsByClassName("list")[0].getElementsByTagName("a"); + var nodes = document + .getElementsByClassName("list")[0] + .getElementsByTagName("a"); for (i = 0; i < nodes.length; i++) { - if (nodes[i].innerHTML.toLowerCase().split(/<\/?br[^>]*>\s*/im)[0].includes(filter)) + if ( + nodes[i].innerHTML + .toLowerCase() + .split(/<\/?br[^>]*>\s*/im)[0] + .includes(filter) + ) nodes[i].removeAttribute("style"); else nodes[i].style.display = "none"; } @@ -188,7 +238,12 @@ function searchCatalog() { var filter = document.getElementById("catsearch").value.toLowerCase(); var nodes = document.getElementsByClassName("cat"); for (i = 0; i < nodes.length; i++) { - if (nodes[i].innerText.toLowerCase().substring(nodes[i].innerText.indexOf("R)")+2).includes(filter)) + if ( + nodes[i].innerText + .toLowerCase() + .substring(nodes[i].innerText.indexOf("R)") + 2) + .includes(filter) + ) nodes[i].removeAttribute("style"); else nodes[i].style.display = "none"; } @@ -221,7 +276,15 @@ function loadJSON() { } var data_file; if (serviceType) - data_file = "/cgi/api/thread?dir=" + postform.board.value + "&id=" + postform.parent.value + "&offset=" + thread_length + "&time=" + lastTime; + data_file = + "/cgi/api/thread?dir=" + + postform.board.value + + "&id=" + + postform.parent.value + + "&offset=" + + thread_length + + "&time=" + + lastTime; else return false; http_request.open("GET", data_file, true); http_request.send(); @@ -234,50 +297,114 @@ function updateThread(posts, total_replies, serverTime) { for (var i = 0; i < posts.length; i++) { post = posts[i]; brd = postform.board.value; - var div = document.createElement('div'); + var div = document.createElement("div"); div.className = "pst"; div.id = "p" + post.id; if (post.IS_DELETED == 0) { s_name = post.name; - if (post.tripcode) s_name += ' ' + post.tripcode; + if (post.tripcode) s_name += " " + post.tripcode; s_time = post.timestamp_formatted.replace(/\(.{1,3}\)/g, " "); if (post.file) - s_img = '<a href="/' + brd + '/src/' + post.file + '" target="_blank" class="thm"><img src="/' + brd + '/mobile/' + post.thumb + '" /><br />' + Math.round(post.file_size/1024) + 'KB ' + post.file.substring(post.file.lastIndexOf(".")+1, post.file.length).toUpperCase() + '</a>'; - else s_img = ''; + s_img = + '<a href="/' + + brd + + "/src/" + + post.file + + '" target="_blank" class="thm"><img src="/' + + brd + + "/mobile/" + + post.thumb + + '" /><br />' + + Math.round(post.file_size / 1024) + + "KB " + + post.file + .substring(post.file.lastIndexOf(".") + 1, post.file.length) + .toUpperCase() + + "</a>"; + else s_img = ""; } if (serviceType == 1) { var pad = "0000" + (thread_length + i + 1); - pad = pad.substr(pad.length-4); + pad = pad.substr(pad.length - 4); if (post.IS_DELETED == 0) - div.innerHTML = '<h3><a href="#" class="num">' + pad + '</a> ' + s_name + '</h3>' + s_img + '<div class="msg">' + post.message + '</div><h4>' + s_time + '<a href="#" class="mnu">|||</a></h4>'; + div.innerHTML = + '<h3><a href="#" class="num">' + + pad + + "</a> " + + s_name + + "</h3>" + + s_img + + '<div class="msg">' + + post.message + + "</div><h4>" + + s_time + + '<a href="#" class="mnu">|||</a></h4>'; else if (post.IS_DELETED == 1) - div.innerHTML = '<h3 class="del"><a href="#" class="num">' + pad + '</a> : Eliminado por el usuario.</h3>'; + div.innerHTML = + '<h3 class="del"><a href="#" class="num">' + + pad + + "</a> : Eliminado por el usuario.</h3>"; else - div.innerHTML = '<h3 class="del"><a href="#" class="num">' + pad + '</a> : Eliminado por miembro del staff.</h3>'; + div.innerHTML = + '<h3 class="del"><a href="#" class="num">' + + pad + + "</a> : Eliminado por miembro del staff.</h3>"; } else { if (post.IS_DELETED == 0) { - div.innerHTML = '<h3>' + s_name + ' ' + s_time + ' <a href="#" class="num" name="' + post.id + '">' + post.id + '</a><a href="#" class="mnu">|||</a></h3>' + s_img + '<div class="msg">' + post.message + '</div>'; - } else if (post.IS_DELETED == 1) { div.innerHTML = '<h3 class="del"><a name="' + post.id + '"></a>No.' + post.id + ' eliminado por el usuario.</h3>'; } - else { div.innerHTML = '<h3 class="del"><a name="' + post.id + '"></a>No.' + post.id + ' eliminado por miembro del staff.</h3>'; } + div.innerHTML = + "<h3>" + + s_name + + " " + + s_time + + ' <a href="#" class="num" name="' + + post.id + + '">' + + post.id + + '</a><a href="#" class="mnu">|||</a></h3>' + + s_img + + '<div class="msg">' + + post.message + + "</div>"; + } else if (post.IS_DELETED == 1) { + div.innerHTML = + '<h3 class="del"><a name="' + + post.id + + '"></a>No.' + + post.id + + " eliminado por el usuario.</h3>"; + } else { + div.innerHTML = + '<h3 class="del"><a name="' + + post.id + + '"></a>No.' + + post.id + + " eliminado por miembro del staff.</h3>"; + } } div.getElementsByClassName("mnu")[0].addEventListener("click", showMenu); div.getElementsByClassName("num")[0].addEventListener("click", postClick); thread_div.insertBefore(div, last_elem); - document.getElementsByTagName("h1")[0].getElementsByTagName("span")[0].innerText = "(" + (thread_length + i + 1) + ")" + document + .getElementsByTagName("h1")[0] + .getElementsByTagName("span")[0].innerText = + "(" + (thread_length + i + 1) + ")"; } if (posts.length > 0) { 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'); - } else { if (refreshMaxTime <= 60) refreshMaxTime += 5; } + if (posts.length > 1) + notif(thread_title, posts.length + " nuevos mensajes"); + else notif(thread_title, "Un nuevo mensaje"); + } else { + if (refreshMaxTime <= 60) refreshMaxTime += 5; + } thread_length = parseInt(total_replies) + 1; new_unread = thread_length - thread_first_length; - if (new_unread) document.title = '(' + new_unread + ') ' + thread_title; + if (new_unread) document.title = "(" + new_unread + ") " + thread_title; else document.title = thread_title; } @@ -290,28 +417,50 @@ function counter() { if (refreshTime < 1) loadJSON(); else { refreshTime--; - document.getElementById("counter").innerHTML = (refreshTime + 1); + document.getElementById("counter").innerHTML = refreshTime + 1; } } function detectService() { if (document.getElementById("thread")) { - thread_title = document.getElementsByTagName("h1")[0].innerHTML.split(" \<span\>")[0] + " - " + document.title; - thread_length = parseInt(document.getElementsByTagName("h1")[0].getElementsByTagName("span")[0].innerText.slice(1, -1), 10); + thread_title = + document.getElementsByTagName("h1")[0].innerHTML.split(" <span>")[0] + + " - " + + document.title; + thread_length = parseInt( + document + .getElementsByTagName("h1")[0] + .getElementsByTagName("span")[0] + .innerText.slice(1, -1), + 10 + ); thread_first_length = thread_length; if (document.body.className === "txt") { serviceType = 1; replylist = document.getElementsByClassName("pst"); - thread_lastreply = parseInt(replylist[replylist.length - 1].getElementsByClassName("num")[0].innerText); + thread_lastreply = parseInt( + replylist[replylist.length - 1].getElementsByClassName("num")[0] + .innerText + ); if (thread_length == thread_lastreply) { serviceType = 1; - document.getElementById("n2").setAttribute("style", "border-top:1px solid #c6c7c8;border-left:1px solid #c6c7c8;display:inline-block;text-align:center;width:50%;"); + document + .getElementById("n2") + .setAttribute( + "style", + "border-top:1px solid #c6c7c8;border-left:1px solid #c6c7c8;display:inline-block;text-align:center;width:50%;" + ); return true; } else return false; } else if (document.body.className === "img") { serviceType = 2; document.getElementById("n").innerText = "Ver nuevos posts"; - document.getElementById("n2").setAttribute("style", "border-top:1px solid #333;border-left:1px solid #333;display:inline-block;text-align:center;width:50%;"); + document + .getElementById("n2") + .setAttribute( + "style", + "border-top:1px solid #333;border-left:1px solid #333;display:inline-block;text-align:center;width:50%;" + ); replylist = document.getElementsByClassName("first"); replylist += document.getElementsByClassName("pst"); return true; @@ -358,51 +507,78 @@ http_request.onreadystatechange = function() { } manual = 0; } -} +}; function sortList(type) { - for(var i=0;i<srts.length;i++) srts[i].removeAttribute("class"); + for (var i = 0; i < srts.length; i++) srts[i].removeAttribute("class"); srts[type].className = "sel"; var cont = document.getElementById("to_sort"); var elem = cont.getElementsByTagName("a"); var arr = Array.prototype.slice.call(elem); - if (type==0) arr.sort(function (a,b) { return (a.dataset.num-b.dataset.num) }); - else if (type==1) arr.sort(function (a,b) { return (b.dataset.id-a.dataset.id) }); - else if (type==2) arr.sort(function (a,b) { return (a.dataset.id-b.dataset.id) }); - else if (type==3) arr.sort(function (a,b) { return (b.dataset.res-a.dataset.res) }); - else if (type==4) arr.sort(function (a,b) { return (a.dataset.res-b.dataset.res) }); - for (var j=0;j<arr.length;j++) cont.appendChild(arr[j]); + if (type == 0) + arr.sort(function(a, b) { + return a.dataset.num - b.dataset.num; + }); + else if (type == 1) + arr.sort(function(a, b) { + return b.dataset.id - a.dataset.id; + }); + else if (type == 2) + arr.sort(function(a, b) { + return a.dataset.id - b.dataset.id; + }); + else if (type == 3) + arr.sort(function(a, b) { + return b.dataset.res - a.dataset.res; + }); + else if (type == 4) + arr.sort(function(a, b) { + return a.dataset.res - b.dataset.res; + }); + for (var j = 0; j < arr.length; j++) cont.appendChild(arr[j]); } document.addEventListener("DOMContentLoaded", function(e) { - if (localStorage.hasOwnProperty("weabot")) weabot = JSON.parse(localStorage.getItem("weabot")); - else weabot = {"name":null,"email":null,"password":null}; + if (localStorage.hasOwnProperty("weabot")) + weabot = JSON.parse(localStorage.getItem("weabot")); + else weabot = { name: null, email: null, password: null }; var ids = document.getElementsByClassName("num"); - for(var i=0;i<ids.length;i++) ids[i].addEventListener("click", postClick); - + for (var i = 0; i < ids.length; i++) + ids[i].addEventListener("click", postClick); + var form = document.getElementById("postform"); if (form) { setInputs(); if (document.getElementById("post").value == "Responder") form.addEventListener("submit", sendPost); } - - if (document.getElementById("search")) document.getElementById("search").addEventListener("keyup", searchSubjects); - if (document.getElementById("catsearch")) document.getElementById("catsearch").addEventListener("keyup", searchCatalog); + + if (document.getElementById("search")) + document.getElementById("search").addEventListener("keyup", searchSubjects); + if (document.getElementById("catsearch")) + document + .getElementById("catsearch") + .addEventListener("keyup", searchCatalog); if (document.getElementById("to_sort")) { srts = document.getElementsByClassName("ord")[0].getElementsByTagName("a"); - for(var i=0;i<srts.length;i++) srts[i].addEventListener("click", function(e) { e.preventDefault(); sortList(this.dataset.sort); }); + for (var i = 0; i < srts.length; i++) + srts[i].addEventListener("click", function(e) { + e.preventDefault(); + sortList(this.dataset.sort); + }); } if (document.getElementById("thread")) { - var mnu = document.createElement('a'); + var mnu = document.createElement("a"); mnu.href = "#"; mnu.className = "mnu"; mnu.innerHTML = "|||"; - if (document.body.className === "txt") var ft = document.getElementsByTagName("h4"); - else if (document.body.className === "img") var ft = document.getElementsByTagName("h3"); - for(var i=0;i<ft.length;i++) { + if (document.body.className === "txt") + var ft = document.getElementsByTagName("h4"); + else if (document.body.className === "img") + var ft = document.getElementsByTagName("h3"); + for (var i = 0; i < ft.length; i++) { if (!ft[i].classList.contains("del")) { var cln = mnu.cloneNode(true); cln.addEventListener("click", showMenu); @@ -429,9 +605,11 @@ document.addEventListener("DOMContentLoaded", function(e) { cnt.textContent = "OFF"; document.getElementById("n2").appendChild(lbl); document.getElementById("auto").appendChild(btn); - document.getElementById("auto").appendChild(document.createTextNode(" Auto ")); + document + .getElementById("auto") + .appendChild(document.createTextNode(" Auto ")); document.getElementById("auto").appendChild(cnt); - + chk = document.getElementById("autorefresh"); if (localStorage.getItem("autorefreshmobile")) { chk.checked = true; @@ -439,9 +617,9 @@ document.addEventListener("DOMContentLoaded", function(e) { } }); -window.addEventListener("unload", function() { +window.addEventListener("unload", function() { chk = document.getElementById("autorefresh"); if (!serviceType) return; if (chk.checked) localStorage.setItem("autorefreshmobile", true); else localStorage.removeItem("autorefreshmobile"); -});
\ No newline at end of file +}); |