diff options
author | Choom | 2023-01-20 00:36:43 -0300 |
---|---|---|
committer | Choom | 2023-01-22 07:57:56 -0300 |
commit | 8e519f17d144165b6de31bf3ebabdab5eb13bf0d (patch) | |
tree | 10b3bd7affd037d198fc6ec54af6862cb0ce85b0 /static/js/weabotxt.js | |
parent | 649a2e5f4fa0b13a58068772ec72605dba6624d2 (diff) | |
download | weabot-8e519f17d144165b6de31bf3ebabdab5eb13bf0d.tar.gz weabot-8e519f17d144165b6de31bf3ebabdab5eb13bf0d.tar.xz weabot-8e519f17d144165b6de31bf3ebabdab5eb13bf0d.zip |
Config para el usuario
Diffstat (limited to 'static/js/weabotxt.js')
-rw-r--r-- | static/js/weabotxt.js | 295 |
1 files changed, 160 insertions, 135 deletions
diff --git a/static/js/weabotxt.js b/static/js/weabotxt.js index 27d3cda..273856d 100644 --- a/static/js/weabotxt.js +++ b/static/js/weabotxt.js @@ -1,12 +1,9 @@ var style_cookie = "weabot_style_bbs"; if (localStorage.hasOwnProperty(style_cookie)) { - setTheme(localStorage.getItem(style_cookie)); -} - -function setTheme(styletitle) { var css = document.getElementById("css"); - if (css) css.href = "/static/css/txt/" + styletitle.toLowerCase() + ".css"; - localStorage.setItem(style_cookie, styletitle); + if (css) { + css.href = "/static/css/txt/" + localStorage.getItem(style_cookie).toLowerCase() + ".css"; + } } function getPassword() { @@ -27,14 +24,14 @@ 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.fieldb !== "undefined") weabot.email = form.fieldb.value; + if (typeof form.fielda !== "undefined") { weabot.name = form.fielda.value; } + if (typeof form.fieldb !== "undefined") { weabot.email = form.fieldb.value; } localStorage.setItem("weabot", JSON.stringify(weabot)); } -function setInputs(id) { - with (document.getElementById(id)) { +function setInputs(form) { + with (form) { if (typeof fielda !== "undefined" && weabot.name) { fielda.value = weabot.name; } @@ -45,12 +42,9 @@ function setInputs(id) { password.value = getPassword(); } if (typeof preview !== "undefined") { - preview.dataset.formid = id; + preview.dataset.formid = form.id; preview.addEventListener("click", previewPost); } - if (typeof message !== "undefined" && document.body.clientWidth < 600) { - message.addEventListener("input", resizeTextbox); - } addEventListener("submit", saveInputs); } } @@ -74,17 +68,6 @@ function insert(text) { return false; } -function deletePost(e) { - var ids = e.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; - } -} - function postClick(num) { var sel = window.getSelection().toString(); if (sel) { @@ -94,17 +77,27 @@ function postClick(num) { insert(">>" + num + sel); } +function deletePost(e) { + var ids = e.parentElement.firstChild.getAttribute("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; + } +} + function previewPost(e) { var form = document.getElementById(e.target.dataset.formid); + if (form.message.value.trim() == '') { + return; + } // empty post, nevermind var thread = e.target.dataset.formid.split('postform')[1]; var board = form.board.value; var preview = document.getElementById('preview' + thread); if (e.target.className == '') { // show preview - if (form.message.value.trim() == '') { - return; - } // empty post, nevermind - e.target.className = 'active'; preview.textContent = 'Cargando...'; @@ -157,36 +150,47 @@ function get_xmlhttp() { return xmlhttp; } -function listSort(e) { - e.preventDefault(); - var s = this.textContent; - var table = document.getElementById("threads"); - var arr = Array.prototype.slice.call(table.getElementsByTagName("tr")); - arr.shift(); - if (s == "Normal") { - arr.sort(function(a, b) { - return (parseInt(a.childNodes[1].textContent) - parseInt(b.childNodes[1].textContent)); - }); - } 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(); - }); +function listPrepare() { + function listSort(e) { + e.preventDefault(); + var sort = e.target.textContent; + var table = document.getElementById("threads"); + var arr = Array.prototype.slice.call(table.getElementsByTagName("tr")); + arr.shift(); + if (sort == "Normal") { + arr.sort(function(a, b) { + return (parseInt(a.childNodes[1].textContent) - parseInt(b.childNodes[1].textContent)); + }); + } else if (sort == "Edad") { + arr.sort(function(a, b) { + return (b.children[1].firstChild.getAttribute("href").split("/")[5] + - a.children[1].firstChild.getAttribute("href").split("/")[5]); + }); + } else if (sort == "Largo") { + arr.sort(function(a, b) { + return (b.children[2].textContent - a.children[2].textContent); + }); + } else if (sort == "Rapidez") { + var now = Math.round(Date.now() / 1000); + arr.sort(function(a, b) { + return (b.children[2].textContent + / (now - b.children[1].firstChild.getAttribute("href").split("/")[5]) + - a.children[2].textContent / (now - a.children[1].firstChild.getAttribute("href").split("/")[5])); + }); + } else if (sort == "Aleatorio") { + arr.sort(function(a, b) { + return 0.5 - Math.random(); + }); + } + for (var j = 0; j < arr.length; j++) { + table.appendChild(arr[j]); + } + } + + var srt = document.getElementById("listmenu").children; + for (var i = 0; i < srt.length; i++) { + srt[i].addEventListener("click", listSort); } - for (var j = 0; j < arr.length; j++) table.appendChild(arr[j]); } function checkHidden() { @@ -195,7 +199,9 @@ function checkHidden() { var hid = hidp.split("!"); for (var i = 0; i < hid.length; i++) { var post = document.getElementById("p"+hid[i]); - if (post) post.classList.add("hidden"); + if (post) { + post.classList.add("hidden"); + } } } } @@ -206,7 +212,7 @@ function togglePost(e) { var hidp = localStorage.getItem("hid-p-"+board); var hid = Array(); - if (hidp) hid = hidp.split("!"); + if (hidp) { hid = hidp.split("!"); } if (post.classList.contains("hidden")) { post.classList.remove("hidden"); @@ -219,115 +225,134 @@ function togglePost(e) { localStorage.setItem("hid-p-"+board, hid.join("!")); } -function resizeTextbox(e) { - var limit = 256; - e.target.style.height = ''; - e.target.style.height = Math.min((e.target.scrollHeight+2), limit) + 'px'; +function smallsjis() { + var rx = /( \| /|\ |/ | ̄ ̄|| | ||\| | \|)/; + var msg = document.getElementsByClassName("msg"); + for (var i=0; i < msg.length; i++) { + if (msg[i].textContent.match(rx)) { + msg[i].classList.add("sjis-mob"); + } + } +} + +function setLocalTime() { + if (weabot.localtime != true) { + return; + } + week = ["dom", "lun", "mar", "mie", "jue", "vie", "sab"]; + var dt = document.getElementsByClassName("date"); + for (var i = 0; i < dt.length; i++) { + dt[i].textContent = localTime(dt[i].dataset.unix); + } +} + +function localTime(timestamp) { + var newdate = new Date(timestamp * 1000); + newdate = + ("0" + newdate.getDate()).slice(-2) + "/" + + ("0" + (newdate.getMonth() + 1)).slice(-2) + + "/" + newdate.getFullYear().toString().slice(-2) + + "(" + week[newdate.getDay()] + ")" + + ("0" + newdate.getHours()).slice(-2) + ":" + + ("0" + newdate.getMinutes()).slice(-2) + ":" + + ("0" + newdate.getSeconds()).slice(-2); + return newdate; +} + +function parsePosts() { + } document.addEventListener("DOMContentLoaded", function() { + board = document.body.dataset.brd; + if (localStorage.hasOwnProperty("weabot")) { weabot = JSON.parse(localStorage.getItem("weabot")); } else { - weabot = { name: null, email: null, password: null }; + weabot = { name: null, + email: null, + password: null, + localtime: false, + qpreview: true, + backlink: true, + filters: false + }; } - - board = document.body.dataset.brd; var head = document.getElementById("main_nav"); if (head) { - var b = head.getElementsByTagName("a"); - for (var i = 0; i < b.length; i++) { - if (b[i].getAttribute("href") == "/" + board + "/") { - b[i].className = "cur_brd"; - break; - } - } + document.getElementById("b-" + board).className = 'cur_brd'; } - if (document.body.clientWidth < 600) { + clientw = document.body.clientWidth; + if (clientw < 800) { if (head) { - var navlink = head.getElementsByTagName("a"); - + var navlink = head.children; + var sel = document.createElement("select"); sel.id = head.id + "_sel"; sel.addEventListener("change", function(e){ - window.location.href = this.value; + window.location.href = e.target.value; }); - - for (var i=1; i<navlink.length; i++) { - var c = document.createElement("option"); + + for (var i=1; i < navlink.length; i++) { + var c = document.createElement("option"); c.text = navlink[i].textContent; - c.value = navlink[i].href; - if (navlink[i].className == "cur_brd") { - c.selected = true; - } + c.value = navlink[i].getAttribute("href"); sel.options.add(c); } - - head.textContent = "" - var home = document.createElement("a"); - home.text = "Bienvenido a Internet"; - home.href = "/home.html"; + sel.value = "/"+board+"/"; + + var home = navlink[0]; + head.textContent = ""; head.appendChild(home); head.appendChild(document.createTextNode(" ★ ")); head.appendChild(sel); - head.className = "mob"; document.body.style.marginTop = "2em"; } - - var sjis = /( \| /|\ |/ | ̄ ̄|| | ||\| | \|)/; - var msg = document.getElementsByClassName("msg"); - for (var i=0; i < msg.length; i++) { - if (msg[i].textContent.match(sjis)) { - msg[i].classList.add("sjis-mob"); - } - } } + if (clientw < 600) { + smallsjis(); + } +}); +window.addEventListener("load", function() { var forms = document.getElementsByTagName("form"); for (var i = 0; i < forms.length; i++) { if (forms[i].id.startsWith("postform")) { - setInputs(forms[i].id); + setInputs(forms[i]); } } - - var styleSelect = document.getElementById("styles"); - if (styleSelect) { - styleSelect.addEventListener("change", function(e) { setTheme(this.value); }); - styleSelect.value = localStorage.getItem(style_cookie); - } - + + checkHidden(); + setLocalTime(); + //parsePosts(); + if (document.getElementById("threads")) { - var srt = document.getElementsByClassName("l_s"); - for (var i = 0; i < srt.length; i++) { - srt[i].addEventListener("click", listSort); - } + listPrepare(); } - checkHidden(); + document.addEventListener("click", function(e) { + var txt = e.target.textContent; + /*if (e.target.className == "num") { + e.preventDefault(); + postClick(txt); + return; + }*/ + if (txt == "del") { + e.preventDefault(); + deletePost(e.target); + return; + } + }, false); + + document.addEventListener("dblclick", function(e) { + if (e.target.closest("h4")) { + e.preventDefault(); + togglePost(e.target.closest("h4")); + window.getSelection().removeAllRanges(); + return; + } + }, false); }); - -document.addEventListener("click", function(e) { - var txt = e.target.textContent; - /*if (e.target.className == "num") { - e.preventDefault(); - postClick(txt); - return; - }*/ - if (txt == "del") { - e.preventDefault(); - deletePost(e.target); - return; - } -}, false); - -document.addEventListener("dblclick", function(e) { - if (e.target.closest("h4")) { - e.preventDefault(); - togglePost(e.target.closest("h4")); - window.getSelection().removeAllRanges(); - return; - } -}, false); |