From 081ddc03aef7becc3b084a9079a2574fd3e3b49b Mon Sep 17 00:00:00 2001 From: Choom Date: Sat, 28 Jan 2023 00:52:56 -0300 Subject: userconf --- static/js/weabotxt.js | 144 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 105 insertions(+), 39 deletions(-) (limited to 'static/js/weabotxt.js') diff --git a/static/js/weabotxt.js b/static/js/weabotxt.js index 273856d..06819ff 100644 --- a/static/js/weabotxt.js +++ b/static/js/weabotxt.js @@ -2,7 +2,12 @@ var style_cookie = "weabot_style_bbs"; if (localStorage.hasOwnProperty(style_cookie)) { var css = document.getElementById("css"); if (css) { - css.href = "/static/css/txt/" + localStorage.getItem(style_cookie).toLowerCase() + ".css"; + var style = localStorage.getItem(style_cookie).trim().toLowerCase(); + if (style != "") { + css.href = "/static/css/txt/" + localStorage.getItem(style_cookie).toLowerCase() + ".css"; + } else { + localStorage.removeItem(style_cookie); + } } } @@ -225,42 +230,101 @@ function togglePost(e) { localStorage.setItem("hid-p-"+board, hid.join("!")); } -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; + 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() { - + if (!weabot.localtime && !weabot.filters && clientw > 600) { + return; + } + + console.log('parsePosts() begin'); + var sjisrx = /(  \|  /|\  |/  | ̄ ̄||  |  ||\|  |  \|)/; + + var p = document.getElementsByClassName("reply"); + for (var i = 0; i < p.length; i++) { + if (p[i].classList.contains('deleted')) { + continue; + } + if (weabot.localtime) { + var date = p[i].getElementsByClassName("date")[0]; + date.textContent = localTime(date.dataset.unix); + } + if (weabot.filters) { + var hit = false; + for (var f in active) { + if (active[f].type == 0) { //mensaje + var rx = new RegExp(active[f].pattern); + if (p[i].getElementsByClassName('msg')[0].textContent.match(rx)) { + hit = true; + break; + } + } else if (active[f].type == 1) { //ID + if (p[i].getElementsByClassName('hash')[0].textContent + == ('ID:'+active[f].pattern)) { + hit = true; + break; + } + } else if (active[f].type == 2) { //tripcode + var trip = p[i].getElementsByClassName('trip')[0]; + if (trip) { + if (trip.textContent.split(' ')[0] == ('◆'+active[f].pattern)) { + hit = true; + break; + } + } + } else if (active[f].type == 3) { //nombre + if (p[i].getElementsByClassName('name')[0].textContent.startsWith(active[f].pattern)) { + hit = true; + break; + } + } + } + if (hit) { + p[i].classList.add('hidden'); + } + } + if (clientw <= 600) { + var msg = p[i].getElementsByClassName('msg')[0]; + if (msg.textContent.match(sjisrx)) { + msg.classList.add("sjis-mob"); + } + } + } +} + +function loadFilters() { + if (!weabot.filters) { return; } + + if (localStorage.hasOwnProperty("weabot-filtros")) { + var filtros = JSON.parse(localStorage.getItem("weabot-filtros")); + active = []; + for (var f in filtros) { + if (filtros[f].usar) { + active.push({ + type: filtros[f].tipo, + pattern: filtros[f].patron + }); + } + } + if (active.length == 0) { + weabot.filters = false; + } + } else { + weabot.filters = false; + } } document.addEventListener("DOMContentLoaded", function() { @@ -279,20 +343,21 @@ document.addEventListener("DOMContentLoaded", function() { }; } - var head = document.getElementById("main_nav"); - if (head) { - document.getElementById("b-" + board).className = 'cur_brd'; + var b_link = document.getElementById("b-" + board); + if (b_link) { + b_link.className = 'cur_brd'; } clientw = document.body.clientWidth; if (clientw < 800) { + var head = document.getElementById('main_nav'); if (head) { var navlink = head.children; var sel = document.createElement("select"); sel.id = head.id + "_sel"; sel.addEventListener("change", function(e){ - window.location.href = e.target.value; + window.location.href = e.target.value; }); for (var i=1; i < navlink.length; i++) { @@ -312,9 +377,6 @@ document.addEventListener("DOMContentLoaded", function() { document.body.style.marginTop = "2em"; } } - if (clientw < 600) { - smallsjis(); - } }); window.addEventListener("load", function() { @@ -325,9 +387,13 @@ window.addEventListener("load", function() { } } + if (weabot.localtime) { + week = ["dom", "lun", "mar", "mie", "jue", "vie", "sab"]; + } + checkHidden(); - setLocalTime(); - //parsePosts(); + loadFilters(); + parsePosts(); if (document.getElementById("threads")) { listPrepare(); -- cgit v1.2.1-18-gbd029