1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
|
var style_cookie = "weabot_style_bbs";
if (localStorage.hasOwnProperty(style_cookie)) {
var css = document.getElementById("css");
if (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);
}
}
}
function getPassword() {
if (weabot.password) return weabot.password;
var pass = "";
var char = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789?!-_.:;";
for (var i=0; i<=8; i++) {
pass += char[Math.floor(Math.random() * char.length)];
}
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.fieldb !== "undefined") { weabot.email = form.fieldb.value; }
localStorage.setItem("weabot", JSON.stringify(weabot));
}
function setInputs(form) {
with (form) {
if (typeof fielda !== "undefined" && weabot.name) {
fielda.value = weabot.name;
}
if (typeof fielda !== "undefined" && weabot.email) {
fieldb.value = weabot.email;
}
if (!password.value) {
password.value = getPassword();
}
if (typeof preview !== "undefined") {
preview.dataset.formid = form.id;
preview.addEventListener("click", previewPost);
}
addEventListener("submit", saveInputs);
}
}
// Textboard data
function insert(text) {
var textarea = document.forms.postform.message;
if (textarea) {
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 postClick(num) {
var sel = window.getSelection().toString();
if (sel) {
sel = sel.replace(/^/gm, ">") + "\n";
sel = "\n" + sel;
}
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
e.target.className = 'active';
preview.textContent = 'Cargando...';
if (thread == '0') { // new thread
document.getElementById('tr_preview').removeAttribute('style');
} else {
preview.removeAttribute('style');
}
} else { // hide it
if (thread == '0') { // new thread
document.getElementById('tr_preview').style.display = 'none';
} else {
preview.style.display = 'none';
}
e.target.removeAttribute('class');
preview.textContent = null;
return;
}
var post = 'message=' + encodeURIComponent(form.message.value) + '&board=' + board + '&parentid=' + thread;
var xmlhttp = get_xmlhttp();
xmlhttp.open('POST', '/cgi/preview');
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) {
preview.innerHTML = xmlhttp.responseText;
}
};
if (xmlhttp.setRequestHeader) {
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
}
xmlhttp.send(post);
}
function get_xmlhttp() {
var xmlhttp;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e1) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e1) {
xmlhttp = null;
}
}
if (!xmlhttp && typeof XMLHttpRequest != "undefined") {
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}
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);
}
}
function checkHidden() {
var hidp = localStorage.getItem("hid-p-"+board);
if (hidp) {
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");
}
}
}
}
function togglePost(e) {
var post = e.parentElement;
var pid = post.id.slice(1);
var hidp = localStorage.getItem("hid-p-"+board);
var hid = Array();
if (hidp) { hid = hidp.split("!"); }
if (post.classList.contains("hidden")) {
post.classList.remove("hidden");
if (hid.includes(pid)) hid.splice(hid.indexOf(pid), 1);
} else {
post.classList.add("hidden");
if (!hid.includes(pid)) hid.push(pid);
}
localStorage.setItem("hid-p-"+board, hid.join("!"));
}
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() {
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() {
board = document.body.dataset.brd;
if (localStorage.hasOwnProperty("weabot")) {
weabot = JSON.parse(localStorage.getItem("weabot"));
} else {
weabot = { name: null,
email: null,
password: null,
localtime: false,
qpreview: true,
backlink: true,
filters: false
};
}
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;
});
for (var i=1; i < navlink.length; i++) {
var c = document.createElement("option");
c.text = navlink[i].textContent;
c.value = navlink[i].getAttribute("href");
sel.options.add(c);
}
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";
}
}
});
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]);
}
}
if (weabot.localtime) {
week = ["dom", "lun", "mar", "mie", "jue", "vie", "sab"];
}
checkHidden();
loadFilters();
parsePosts();
if (document.getElementById("threads")) {
listPrepare();
}
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);
});
|