aboutsummaryrefslogtreecommitdiff
path: root/static/js/weabotxt.js
diff options
context:
space:
mode:
authorLibravatar Choom 2023-01-28 00:52:56 -0300
committerLibravatar Choom 2023-02-02 00:39:27 -0300
commit081ddc03aef7becc3b084a9079a2574fd3e3b49b (patch)
treea6ca793a0c21917d3774778c0a14f65a8c678113 /static/js/weabotxt.js
parentd0d6b8ebff31d2306a040dc9c53f9e5e7a0ec7a0 (diff)
downloadweabot-081ddc03aef7becc3b084a9079a2574fd3e3b49b.tar.gz
weabot-081ddc03aef7becc3b084a9079a2574fd3e3b49b.tar.xz
weabot-081ddc03aef7becc3b084a9079a2574fd3e3b49b.zip
userconf
Diffstat (limited to 'static/js/weabotxt.js')
-rw-r--r--static/js/weabotxt.js144
1 files changed, 105 insertions, 39 deletions
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();