From 95dfe14528663923ca2a88ec928f1d8d9df2402b Mon Sep 17 00:00:00 2001 From: bai Date: Fri, 29 Mar 2019 02:14:43 +0000 Subject: Init --- static/js/weabotxt.js | 299 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 299 insertions(+) create mode 100644 static/js/weabotxt.js (limited to 'static/js/weabotxt.js') diff --git a/static/js/weabotxt.js b/static/js/weabotxt.js new file mode 100644 index 0000000..37668d8 --- /dev/null +++ b/static/js/weabotxt.js @@ -0,0 +1,299 @@ +var style_cookie = "weabot_style_txt"; +if(style_cookie && localStorage.hasOwnProperty(style_cookie)) { set_stylesheet(localStorage.getItem(style_cookie)); } + +var hiddenposts = Array(); + +function set_stylesheet(styletitle) { + var css=document.getElementById("css"); + if(css) css.href = "/static/css/txt/"+styletitle.toLowerCase()+".css"; + localStorage.setItem(style_cookie,styletitle); +} + +function changeDate() { + var dts = document.getElementsByClassName("date"); + if (dts[0].dataset.unix) { + week = ["dom", "lun", "mar", "mie", "jue", "vie", "sab"]; + if (board == "world") week = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"]; + for(var d=0;d31535999) return "más de un año"; +} + +function localTime(timestamp, id) { + id = id || 0; + var lcl = new Date(timestamp*1000); + lcl = ("0"+lcl.getDate()).slice(-2) + "/" + ("0" + (lcl.getMonth()+1)).slice(-2) + "/" + lcl.getFullYear().toString().slice(-2) + "(" + week[lcl.getDay()] + ")" + ("0"+lcl.getHours()).slice(-2) + ":" + ("0"+lcl.getMinutes()).slice(-2) + ":" + ("0"+lcl.getSeconds()).slice(-2) + if (id) lcl = lcl + " " + id; + return lcl; +} + +/* IE/Opera fix, because they need to go learn a book on how to use indexOf with arrays */ +if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function(elt /*, from*/) { + var len = this.length; + var from = Number(arguments[1]) || 0; + from = (from < 0) ? Math.ceil(from) : Math.floor(from); + if (from < 0) from += len; + for (; from < len; from++) { if (from in this && this[from] === elt) return from; } + return -1; + }; +} + +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); + } + weabot.password = pass; + localStorage.setItem("weabot", JSON.stringify(weabot)); + 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; + localStorage.setItem("weabot", JSON.stringify(weabot)); +} + +function setInputs(id) { + if (document.getElementById(id)) { + with(document.getElementById(id)) { + 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(); + if(typeof preview !== 'undefined') { preview.id = id; preview.addEventListener("click", previewPost); } + addEventListener("submit", saveInputs); + } + } +} + +function setPassword(id) { + if (document.getElementById(id).password) + with (document.getElementById(id)) + if(!password.value) password.value = getPassword("weabot_password"); +} + +// Textboard data +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(); + } + return false; +} + +function deletePost(e) { + var ids = this.parentElement.firstChild.href.split("/"); + var post = ids.pop(); + var realid = ids.pop(); + if(confirm("¿Seguro que deseas borrar el mensaje "+post+"?")) { + var script="/cgi/delete"; + document.location=script+"?board="+board+"&password="+weabot.password+"&delete="+realid; + } + e.preventDefault(); +} + +function postClick(e) { + e.preventDefault(); + var sel = window.getSelection().toString(); + if (sel) { sel=sel.replace(/^/gm, ">")+"\n"; sel="\n"+sel; } + insert(">>" + this.textContent + sel); +} + +function previewPost(e) { + var formid = e.target.id; + var thread = "0"; + if(formid.startsWith("postform")) thread = formid.substr(8); + + var form=document.getElementById(formid); + var preview=document.getElementById("preview"+thread); + var main=document.getElementById("options"); + + if(!form||!preview||!form.message.value) return; + if(main) main.style.display=""; + + preview.removeAttribute("style"); + preview.innerHTML="Cargando..."; + + var text="message="+encodeURIComponent(form.message.value)+"&board="+board; + if (thread) text+="&parentid="+thread; + + var xmlhttp=get_xmlhttp(); + xmlhttp.open("POST", "/cgi/preview"); + xmlhttp.onreadystatechange=function() { if(xmlhttp.readyState==4) preview.innerHTML=xmlhttp.responseText; } + if(is_ie()||xmlhttp.setRequestHeader) xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); + xmlhttp.send(text); +} + +function listSort() { + var s = opcs.sort; + var cont = document.getElementById("content"); + var elem = document.getElementsByClassName("row"); + var arr = Array.prototype.slice.call(elem); arr.shift(); + if (s=="Normal") { arr.sort(function (a,b) { return (parseInt(a.childNodes[1].innerText) - parseInt(b.childNodes[1].innerText)) }); } + else if(s=="Edad"){ arr.sort(function (a,b) { return (b.children[1].firstChild.href.split("/")[5] - a.children[1].firstChild.href.split("/")[5]) }); } + else if(s=="Largo"){ arr.sort(function (a,b) { return (b.children[2].textContent - a.children[2].textContent) }); } + else if(s=="Rapidez"){ var now=Math.round(Date.now()/1000); arr.sort(function (a,b) { return ((b.children[2].textContent/(now-b.children[1].firstChild.href.split("/")[5])) - (a.children[2].textContent/(now-a.children[1].firstChild.href.split("/")[5]))) }); } + else if(s=="Aleatorio"){ arr.sort(function(a,b) { return 0.5-Math.random()}); } + for (var j=0;j