From 8e519f17d144165b6de31bf3ebabdab5eb13bf0d Mon Sep 17 00:00:00 2001
From: Choom
Date: Fri, 20 Jan 2023 00:36:43 -0300
Subject: Config para el usuario
---
static/js/aquiencitas.js | 14 +--
static/js/shobon.js | 84 --------------
static/js/userconf.js | 164 +++++++++++++++++++++-----
static/js/weabot.js | 139 ++++++++++------------
static/js/weabotxt.js | 295 +++++++++++++++++++++++++----------------------
5 files changed, 363 insertions(+), 333 deletions(-)
(limited to 'static/js')
diff --git a/static/js/aquiencitas.js b/static/js/aquiencitas.js
index 93f5323..309df8f 100644
--- a/static/js/aquiencitas.js
+++ b/static/js/aquiencitas.js
@@ -141,12 +141,12 @@ function remove_quote_preview(e) {
if (pst) pst.scrollIntoView();
}*/
function quotePreview() {
- if (localStorage.getItem("shobon_on") == "false") {
- return;
+ if (localStorage.hasOwnProperty("weabot")) {
+ weabot = JSON.parse(localStorage.getItem("weabot"));
+ var showprev = weabot.qpreview;
+ var showlink = weabot.backlink;
+ if (showprev == false && showlink == false) { return; }
}
- var showprev = localStorage.getItem("shobon_preview");
- var showlink = localStorage.getItem("shobon_backlink");
- if (showprev == "false" && showlink == "false") return;
var i, q, replies, quotes;
@@ -168,12 +168,12 @@ function quotePreview() {
q = quotes[i];
if (q.textContent.length < 3 || !q.textContent.startsWith(">>")) continue;
- if (showprev != "false") {
+ if (showprev != false) {
q.addEventListener("mouseover", who_are_you_quoting, false);
q.addEventListener("mouseout", remove_quote_preview, false);
}
- if (showlink != "false") {
+ if (showlink != false) {
fill_links(q);
}
}
diff --git a/static/js/shobon.js b/static/js/shobon.js
index 9eccf86..3a790a7 100644
--- a/static/js/shobon.js
+++ b/static/js/shobon.js
@@ -25,28 +25,6 @@ function shobon() {
var newRepliesCounter = 0;
- var shobon_time = localStorage.getItem("shobon_time");
- if (shobon_time != "false") {
- if (boardName == "world")
- week = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"];
- else if (boardName == "2d")
- week = ["日", "月", "火", "水", "木", "金", "土"];
- else week = ["dom", "lun", "mar", "mie", "jue", "vie", "sab"];
- }
-
- if (where == "threads") {
- if (shobon_time != "false") {
- var dt = document.getElementsByClassName("date");
- for (var i = 0; i < dt.length; i++) {
- dt[i].addEventListener("mouseover", function(e) {
- this.title = "Hace " + timeAgo(this.dataset.unix);
- });
- dt[i].textContent = localTime(dt[i].dataset.unix);
- }
- }
- return;
- }
-
if (localStorage.getItem("shobon_usefilters") != "false") {
loadFilters();
}
@@ -77,16 +55,6 @@ function shobon() {
var message = reply.getElementsByClassName("msg")[0];
var id = 0;
- if (shobon_time != "false") {
- var date = reply.getElementsByClassName("date")[0];
- date.addEventListener("mouseover", function(e) {
- this.title = "Hace " + timeAgo(this.dataset.unix);
- });
- if (date.textContent.includes("ID:"))
- id = date.textContent.split(" ")[1];
- date.textContent = localTime(date.dataset.unix, id);
- }
-
if (localStorage.getItem("shobon_newposts") == "true") {
var replyId = reply.attributes["data-n"].value;
var isNewReply = parseInt(lastSeen) < parseInt(replyId);
@@ -185,37 +153,6 @@ function createTh(label, w) {
th.width = w;
return th;
}
-function timeAgo(timestamp) {
- var time = Math.round(Date.now() / 1000);
- var el = time - timestamp;
- if (el == 0) return "un instante";
- else if (el == 1) return "un segundo";
- else if (el < 60) return el + " segundos";
- else if (el < 120) return "un minuto";
- else if (el < 3600) return Math.round(el / 60) + " minutos";
- else if (el < 7200) return "una hora";
- else if (el < 86400) return Math.round(el / 3600) + " horas";
- else if (el < 172800) return "un día";
- else if (el < 2628000) return Math.round(el / 86400) + " días";
- else if (el < 5256000) return "un mes";
- else if (el < 31536000) return Math.round(el / 2628000) + " meses";
- else if (el > 31535999) 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;
-}
function loadFilters() {
var filters = JSON.parse(localStorage.getItem("shobon_filters"));
@@ -315,7 +252,6 @@ function shobonSettings(e) {
p.appendChild(createCheckbox("shobon_ids", "Colorear IDs", false));
p.appendChild(createCheckbox("shobon_embedimg", "Insertar imágenes miniatura", false));
p.appendChild(createCheckbox("shobon_newposts", "Destacar mensajes nuevos", false));
- p.appendChild(createCheckbox("shobon_time", "Convertir fechas a hora local", true));
p.appendChild(createCheckbox("shobon_backlink", "Mostrar quién ha citado un post", true));
p.appendChild(createCheckbox("shobon_preview", "Previsualizar citas", true));
p.appendChild(createCheckbox("shobon_usefilters", "Activar filtros", false));
@@ -443,26 +379,6 @@ function paintIds(reply) {
";padding:0 3px;border-radius:5px; font-size:0.9em;vertical-align:top;'>ID:" +
userId +
"";
- dateId.getElementsByClassName("uid")[0].addEventListener("click", markId, false);
- }
-}
-
-function markId(e) {
- var uid = this.textContent.slice(0, -1).replace(":", "_");
- var sel = document.getElementsByClassName("sel");
- var len = sel.length;
- for (i = 0; i < len; i++) {
- var prev = String(sel[0].className);
- sel[0].className = sel[0].className.toString().replace(/ sel/i, "");
- }
- if (currentSel == uid) {
- currentSel = null;
- return;
- }
- currentSel = uid;
- var tosel = document.getElementsByClassName(uid);
- for (j = 0; j < tosel.length; j++) {
- tosel[j].className = tosel[j].className + " sel";
}
}
diff --git a/static/js/userconf.js b/static/js/userconf.js
index 985090a..0118e88 100644
--- a/static/js/userconf.js
+++ b/static/js/userconf.js
@@ -7,25 +7,25 @@ function cargarEstilos() {
}
function listarEstilos(id, estilos, def) {
- var select = document.getElementById(id);
-
- for (var i=0; i < estilos.length; i++) {
- var opt = document.createElement('option');
- opt.value = estilos[i];
- opt.textContent = estilos[i];
- if (i == def) {
- opt.selected = true;
- }
- select.appendChild(opt);
- }
+ var select = document.getElementById(id);
+
+ for (var i=0; i < estilos.length; i++) {
+ var opt = document.createElement('option');
+ opt.value = estilos[i];
+ opt.textContent = estilos[i];
+ if (i == def) {
+ opt.selected = true;
+ }
+ select.appendChild(opt);
+ }
}
request.onreadystatechange = function() {
if (request.readyState == 4) {
var json = JSON.parse(request.responseText);
if (json.state == "success") {
- listarEstilos('stylebbs', json.bbs_styles, json.bbs_styles_default);
- listarEstilos('styleib', json.ib_styles, json.ib_styles_default);
+ listarEstilos('stylebbs', json.bbs_styles, json.bbs_styles_default);
+ listarEstilos('styleib', json.ib_styles, json.ib_styles_default);
}
}
};
@@ -37,11 +37,11 @@ function cambiarModo(e) {
if (this.dataset.view == '1') {
iframe.addEventListener('load', mostrarEstilo);
iframe.src = '/static/example/bbs2.html';
- this.value = 'Ver modo frontal';
+ this.value = 'Previsualizar board';
this.dataset.view = '2';
} else {
iframe.src = '/static/example/bbs1.html';
- this.value = 'Ver modo respuesta';
+ this.value = 'Previsualizar respuesta';
this.dataset.view = '1';
}
}
@@ -64,6 +64,10 @@ function mostrarEstilo(e) {
}
css.href = loc + estilo.toLowerCase() + ".css";
+
+ var key = 'weabot_style_' + tipo;
+ var estilo = document.getElementById(('style'+tipo)).value;
+ localStorage.setItem(key, estilo);
}
function cargariframe(tipo) {
@@ -73,7 +77,6 @@ function cargariframe(tipo) {
iframe.addEventListener('load', cargarDatos);
iframe.src = '/static/example/' + tipo + '1.html';
var div = document.getElementById("desc" + tipo);
- div.appendChild(document.createElement("br"));
div.appendChild(iframe);
}
@@ -89,26 +92,135 @@ function cargarDatos(e) {
this.removeEventListener('load', cargarDatos);
}
-function establecerEstilo(e) {
- var key = e.target.dataset.key;
-}
-
function init(tipo) {
cargariframe(tipo);
document.getElementById('style'+tipo).addEventListener('change', mostrarEstilo);
- document.getElementById('set'+tipo).addEventListener('click', function() {
- var key = 'weabot_style_' + tipo;
- var estilo = document.getElementById(('style'+tipo)).value;
- localStorage.setItem(key, estilo);
- });
+}
+
+function checkboxes() {
+ var chk = document.getElementsByClassName("weabot-obj");
+ for (var i=0; i < chk.length; i++) {
+ chk[i].addEventListener("change", saveInput);
+ }
+}
+
+function saveInput(e) {
+ var key = e.target.id;
+ weabot[key] = e.target.checked;
+ localStorage.setItem("weabot", JSON.stringify(weabot));
+}
+
+function setInputs() {
+ for (key in weabot) {
+ var chk = document.getElementById(key);
+ if (chk) {
+ document.getElementById(key).checked = weabot[key];
+ }
+ }
+}
+
+function cargarFiltros() {
+ var del = document.getElementsByClassName("f-remove");
+ for (var i=0; i < del.length; i++) {
+ del[i].addEventListener('click', quitarFiltro);
+ }
+
+ if (localStorage.hasOwnProperty("weabot-filtros")) {
+ var lista = document.getElementById("filterlist");
+ var filtros = JSON.parse(localStorage.getItem("weabot-filtros"));
+
+ for (var i=0; i < filtros.length; i++) {
+ nuevoFiltro(filtros[i].usar, filtros[i].patron, filtros[i].tipo);
+ }
+ } else {
+ nuevoFiltro();
+ }
+
+ document.getElementById('newfilter').addEventListener('click', function(){ nuevoFiltro(); });
+ document.getElementById('savefilters').addEventListener('click', guardarFiltros);
+}
+
+function nuevoFiltro(usar, patron, tipo) {
+ if (arguments.length == 0) {
+ var usar = true;
+ var patron = '';
+ var tipo = 0;
+ } else {
+ tipo = parseInt(tipo);
+ }
+
+ var lista = document.getElementById("filterlist");
+ var fila = document.createElement("tr");
+ var selected = ['', '', '', ''];
+ selected[tipo] = ' selected="selected"';
+ var html = '
| ' : '>');
+ html += ' | ';
+ html += ' | ';
+ html += ' | ';
+ fila.innerHTML = html;
+ fila.children[3].firstChild.addEventListener('click', quitarFiltro);
+ lista.appendChild(fila);
+}
+
+function quitarFiltro(e) {
+ var lista = document.getElementById("filterlist");
+ var delme = e.target.parentElement.parentElement;
+ if (lista.children.length == 1) {
+ nuevoFiltro();
+ }
+ delme.parentNode.removeChild(delme);
+}
+
+function guardarFiltros() {
+ var f;
+ var filtros = [];
+ var tr = document.getElementById("filterlist").getElementsByTagName("tr");
+
+ for (var i=0; i < tr.length; i++) {
+ var pat = tr[i].children[1].firstChild.value.trim();
+ if (pat != '') {
+ f = {
+ usar: tr[i].children[0].firstChild.checked,
+ patron: pat,
+ tipo: parseInt(tr[i].children[2].firstChild.value)
+ }
+ filtros.push(f);
+ }
+ }
+
+ if (filtros.length > 0) {
+ localStorage.setItem("weabot-filtros", JSON.stringify(filtros));
+ } else {
+ localStorage.removeItem("weabot-filtros");
+ }
}
document.addEventListener("DOMContentLoaded", function() {
- document.getElementById("escondeme").style.display = 'none';
+ if (localStorage.hasOwnProperty("weabot")) {
+ weabot = JSON.parse(localStorage.getItem("weabot"));
+ } else {
+ weabot = {
+ localtime: false,
+ qpreview: true,
+ backlink: true,
+ filters: false
+ };
+ localStorage.setItem("weabot", JSON.stringify(weabot));
+ }
+ setInputs();
cargarEstilos();
+ checkboxes();
+ cargarFiltros();
document.getElementById('switchview').addEventListener('click', cambiarModo);
+
init('bbs');
init('ib');
});
diff --git a/static/js/weabot.js b/static/js/weabot.js
index 693d138..afe65c8 100644
--- a/static/js/weabot.js
+++ b/static/js/weabot.js
@@ -1,30 +1,11 @@
var style_cookie = "weabot_style_ib";
if (localStorage.hasOwnProperty(style_cookie)) {
- setTheme(localStorage.getItem(style_cookie));
-}
-
-function setTheme(styletitle) {
var css = document.getElementById("css");
if (css) {
- css.href = "/static/css/" + styletitle.toLowerCase() + ".css";
- localStorage.setItem(style_cookie, styletitle);
+ css.href = "/static/css/" + localStorage.getItem(style_cookie).toLowerCase() + ".css";
}
}
-/* 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 postClick(num) {
var sel = window.getSelection().toString();
if (sel) sel = sel.replace(/^/gm, ">") + "\n";
@@ -204,16 +185,6 @@ function getPassword() {
return pass;
}
-function catSearch() {
- var filter = this.value.toLowerCase();
- var nodes = document.getElementsByTagName("p");
- for (var i = 0; i < nodes.length; i++) {
- if (nodes[i].innerText.toLowerCase().includes(filter))
- nodes[i].parentNode.removeAttribute("style");
- else nodes[i].parentNode.style.display = "none";
- }
-}
-
function togglePost(e) {
if (e.tagName == "DIV") {
var post = e.parentElement;
@@ -223,24 +194,32 @@ function togglePost(e) {
var pid = post.id.slice(1);
var typ = post.id.charAt(0);
- var itm = "hid-" + typ + "-" + document.body.dataset.brd;
+ var itm = "hid-" + typ + "-" + board;
var hidp = localStorage.getItem(itm);
var hid = Array();
- if (hidp) hid = hidp.split("!");
+ if (hidp) { hid = hidp.split("!"); }
if (post.classList.contains("hidden")) {
- if (hid.includes(pid)) hid.splice(hid.indexOf(pid), 1);
+ if (hid.includes(pid)) {
+ hid.splice(hid.indexOf(pid), 1);
+ }
} else {
- if (!hid.includes(pid)) hid.push(pid);
+ if (!hid.includes(pid)) {
+ hid.push(pid);
+ }
}
post.classList.toggle("hidden");
localStorage.setItem(itm, hid.join("!"));
}
+function checkHidden() {
+
+}
+
document.addEventListener("DOMContentLoaded", function(e) {
- var board = document.body.dataset.brd;
+ board = document.body.dataset.brd;
checkhighlight();
if (localStorage.hasOwnProperty("weabot")) {
@@ -249,15 +228,10 @@ document.addEventListener("DOMContentLoaded", function(e) {
weabot = { name: null, email: null, password: null };
}
- var head = document.getElementById("main_nav");
- var a = head.getElementsByTagName("a");
- for (var i = 0; i < a.length; i++) {
- if (a[i].getAttribute("href") == "/" + board + "/") {
- a[i].className = "cur_brd";
- break;
- }
- }
+ var blink = document.getElementById("b-" + board);
+ if (blink) { blink.className = "cur_brd"; }
+ var head = document.getElementById("main_nav");
if (document.body.clientWidth < 600) {
var navlink = head.getElementsByTagName("a");
@@ -296,17 +270,11 @@ document.addEventListener("DOMContentLoaded", function(e) {
var hid = hidp.split("!");
for (var j = 0; j < hid.length; j++) {
var post = document.getElementById(type+hid[j]);
- if (post) post.classList.add("hidden");
+ if (post) { post.classList.add("hidden"); }
}
}
}
- var styleSelect = document.getElementById("styles");
- if (styleSelect) {
- styleSelect.addEventListener("change", function(e) { setTheme(this.value); });
- styleSelect.value = localStorage.getItem(style_cookie);
- }
-
if (document.getElementById("postform")) {
setInputs("postform");
postform.file.addEventListener("change", filePreview);
@@ -317,7 +285,7 @@ document.addEventListener("DOMContentLoaded", function(e) {
var cat = document.getElementById("catalog");
if (cat) {
- if (j>0) {
+ if (j > 0) { // hidden threads number
document.getElementById("hid-label").removeAttribute("style");
document.getElementById("hid-num").innerText = j;
}
@@ -338,40 +306,49 @@ document.addEventListener("DOMContentLoaded", function(e) {
this.innerText = (this.innerText == "Pequeño") ? "Grande" : "Pequeño";
});
- document.getElementById("cat-srch").addEventListener("keyup", catSearch);
-
document.getElementById("hid-num").addEventListener("click", function(e) {
e.preventDefault();
cat.classList.toggle("showhid");
});
- } else {
- window.addEventListener("hashchange", checkhighlight);
- }
+ }
+
+ window.addEventListener("hashchange", checkhighlight);
});
-document.addEventListener("click", function(e) {
- var cn = e.target.className;
- if (cn == "num") {
- e.preventDefault();
- postClick(e.target.textContent);
- return;
- }
- if (cn == "expimg") {
- e.preventDefault();
- expandimg(e.target);
- return;
- }
- if (cn == "tt") {
- e.preventDefault();
- togglePost(e.target);
- return;
- }
-}, false);
-document.addEventListener("dblclick", function(e) {
- if (e.target.closest(".info")) {
- e.preventDefault();
- togglePost(e.target.closest(".info"));
- return;
- }
-}, false);
+
+window.addEventListener("load", function() {
+ document.addEventListener("click", function(e) {
+ var cn = e.target.className;
+ if (cn == "num") {
+ e.preventDefault();
+ postClick(e.target.textContent);
+ return;
+ }
+ if (cn == "expimg") {
+ e.preventDefault();
+ expandimg(e.target);
+ return;
+ }
+ if (cn == "tt") {
+ e.preventDefault();
+ togglePost(e.target);
+ return;
+ }
+ }, false);
+
+ document.addEventListener("dblclick", function(e) {
+ if (e.target.closest(".info")) {
+ e.preventDefault();
+ togglePost(e.target.closest(".info"));
+ return;
+ }
+ if (document.getElementById("catalog")) {
+ if (e.target.className == 'subj') {
+ e.preventDefault();
+ togglePost(e.target.className == 'subj');
+ return;
+ }
+ }
+ }, false);
+});
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