Initialization of Logs/4Chan_Bans_Log-Reverse_Chrono-415.json
[Backup_bans.verniy.xyz.git] / Scripts / TableFunctions.js
blob29d695fa6e257b426f6cdf0dcb892ab335311a8e
1 //Enter to search table.
2 function enterForSearch(){
3 document.getElementById("refinement").addEventListener("keydown", function(e){
4 if(e.keyCode == 13){
5 document.getElementById("set").click();
6 }
7 });
8 document.getElementById("commentrefine").addEventListener("keydown", function(e){
9 if(e.keyCode == 13){
10 document.getElementById("set").click();
12 });
13 document.getElementById("rulerefine").addEventListener("keydown", function(e){
14 if(e.keyCode == 13){
15 document.getElementById("set").click();
17 });
20 window.onload = function(){
21 loadFunction();
22 enterForSearch();
24 window.onhashchange = function() {
25 board_changed = true;
26 loadFunction();
29 //Construction of tables.
30 var global_data = Array();
31 var board_data = Array();
32 var working_data = Array();
33 var archive_URL_Text = "[Archive Link]"
34 var window_width;
35 const WINDOW_CONSTANT = 1845;
37 var table = document.getElementById("bansTable");
38 var count = document.getElementById("count");
39 var counter = 0;
41 var max_counter;
42 var first_page_max;
43 var minus_counter = 0;
44 var current_page;
45 var actual_page;
46 var max_page;
48 var board_refine = "";
49 var comment_refine = "";
50 var rule_refine = "";
52 var init = false;
53 var table_built = Array();
54 var refresh_called = false;
55 var board_changed = false;
57 var construct_interval;
59 var page_load_amount = 1000;
61 //sets global data in table and count if not set already. First to be called.
62 function loadFunction(){
63 //set a refresh message
64 if(init)count.innerHTML = "...Refreshing...";
65 //else window.location.hash = '#' + 1;
66 //load ledger data
67 var xhttp_ledger = new XMLHttpRequest();
68 xhttp_ledger.onreadystatechange = ajaxTableSetup;
69 xhttp_ledger.open("POST", "Scripts/sql-reader.php", true);
70 xhttp_ledger.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
72 //#page|board|com|reason
73 var hash = window.location.hash;
74 if(hash != ""){
75 var hash_details = hash.split("|");
76 //error check
77 if(hash.indexOf("|") == -1){
78 hash_details = hash.split("%7C");
80 if(hash_details[1] != undefined)
81 board_refine = hash_details[1];
82 if(hash_details[2] != undefined)
83 comment_refine = hash_details[2];
84 if(hash_details[3] != undefined)
85 rule_refine = hash_details[3];
87 xhttp_ledger.send("Query=4&Board=" + board_refine + "&Comment=" + comment_refine+ "&Rule=" + rule_refine);
89 else {
90 xhttp_ledger.send("Query=4&Board=&Comment=&Rule=");
94 function ajaxTableSetup(){
95 if (this.readyState == 4 && this.status == 200) {
96 //read the total entries in file
97 max_counter = this.responseText;
98 max_page = Math.floor(this.responseText/1000);
99 first_page_max = this.responseText % 1000;
100 first_page_max = first_page_max == 0 ? 1000 : first_page_max;
101 current_page = max_page;
103 var hash = window.location.hash;
104 if(hash != ""){
105 var hash_details = hash.split("|");
106 //error check
107 if(hash.indexOf("|") == -1){
108 hash_details = hash.split("%7C");
110 if(hash_details[0] != undefined)
111 current_page = max_page - hash_details[0].substring(1) + 1;
112 if(hash_details[1] != undefined)
113 board_refine = hash_details[1];
114 if(hash_details[2] != undefined)
115 comment_refine = hash_details[2];
116 if(hash_details[3] != undefined)
117 rule_refine = hash_details[3];
119 document.getElementById("refinement").value = decodeURI(hash_details[1]);
120 document.getElementById("commentrefine").value = decodeURI(hash_details[2]);
121 document.getElementById("rulerefine").value = decodeURI(hash_details[3]);
123 if(current_page < 0){
124 current_page=0;
125 actual_page = max_page - current_page + 1;
126 window.location.hash = '#' + actual_page + "|" + board_refine + "|" + comment_refine + "|" + rule_refine;
128 else actual_page = max_page - current_page + 1;
130 window_width = window.innerWidth;
131 //check if loaded
132 if(global_data[current_page] === undefined || refresh_called || board_changed){
133 if(board_changed){
134 global_data.forEach(function(page,index){
135 global_data[index] = [];
138 board_changed = false;
139 //load the log data
140 var xhttp_log = new XMLHttpRequest();
141 xhttp_log.onreadystatechange = function(){
142 table = document.getElementById("bansTable");
143 count = document.getElementById("count");
144 if (this.readyState == 4 && this.status == 200) {
145 while(table.hasChildNodes()) table.removeChild(table.lastChild);
147 global_data[current_page] = [];
148 sql_data = this.responseText;
149 sql_data = sql_data.split("</>");
150 sql_data.forEach(function(data, index){
151 if(data=="") return;
152 var row = data.split("<>");
153 row[3] = insertWBR(row[3]);
154 global_data[current_page][index] = {board:row[0], name:row[1], trip:row[2],com:row[3],action:row[4],length:row[5],reason:row[6],now:row[7]};
155 addArchiveToComment(index, row[8]);
157 table_built[current_page] = false;
159 constructTable();
160 buildPages();
162 init = true;
163 refresh_called = false;
165 else if(this.readyState == 4 && this.status != 200){
166 table.innerHTML = "<tr><td>Page Load Error. Try Changing Pages</td></tr>";
169 xhttp_log.open("POST", "Scripts/sql-reader.php", true);
170 xhttp_log.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
171 xhttp_log.send("Query=5&Page=" + current_page +"&Board="+ board_refine+"&Comment="+ comment_refine +"&Rule="+ rule_refine);
173 else {
174 constructTable();
175 buildPages();
177 init = true;
178 refresh_called = false;
181 else if(this.readyState == 4 && this.status != 200){
182 table.innerHTML = "<tr><td>Ledger Load Error . Try Refreshing</td></tr>";
186 function refreshFunction(){
187 table_built[current_page] = false;
188 refresh_called = true;
189 loadFunction();
192 function refineFunction(){
193 //reloads page from index onhashchange
194 board_refine = document.getElementById("refinement").value;
195 comment_refine = document.getElementById("commentrefine").value;
196 rule_refine = document.getElementById("rulerefine").value;
197 if(actual_page === undefined) actual_page = "";
198 board_changed = true;
199 window.location.hash = '#' + actual_page + "|" + board_refine + "|" + comment_refine + "|" + rule_refine;
202 function insertWBR(row){
204 var wbr_interval = 40;
206 row = row.replace(/<wbr>/g, "");
207 var dummy_node = document.createElement("P");
208 dummy_node.innerHTML = row; //4chan moderator here. I will BAN the next person who honks
210 var text_nodes = [];
211 var text_walker=document.createTreeWalker(dummy_node, NodeFilter.SHOW_TEXT);
212 var node;
213 while(node=text_walker.nextNode()) {
214 text_nodes.push(node);
216 var len = text_nodes.length;
217 var total_index_counter = 0;
218 for(var text_node = 0 ; text_node < len; text_node++){
219 var text = text_nodes[text_node].nodeValue ;
220 if(text != null && !isNaN(text.length)){
221 total_index_counter += text.length;
223 if(total_index_counter > wbr_interval){
224 if(text.length < wbr_interval){
225 text_nodes[text_node].parentNode.appendChild(document.createElement("WBR"));
227 else{
228 var replacement = text_nodes[text_node].splitText(wbr_interval);
229 text_nodes[text_node].parentNode.insertBefore(document.createElement("WBR"), replacement);
230 text_nodes.push(replacement);
231 len++;
233 total_index_counter = 0;
237 return dummy_node.innerHTML;
240 function addArchiveToComment(index, filename){
242 Thanks to http://archive.nyafuu.org/ : c / e / n / news / out / p / toy / vip/ vp / w / wg / wsr
243 Thanks to http://4plebs.org/ : adv / hr / o / pol / s4s / sp / trv / tv / x
244 Thanks to http://desuarchive.org : a / aco / an / co / d / fit / gif / his / int / k / m / mlp / qa / r9k / tg / trash / vr / wsg
245 Thanks to http://archive.loveisover.me : i / lgbt / t / u
246 Thanks to https://boards.fireden.net : cm / ic / sci / v / vg / y
247 Thanks to http://archiveofsins.com/ : h / hc / hm / r / s / soc
248 Thanks to http://thebarchive.com : b / bant
249 Thanks to https://rbt.asia : cgl / g / mu
251 var A = "";
252 switch(global_data[current_page][index]["board"]){
253 case "a": case "cm": case "co":case "ic":case "sci":case "tg":case "v":case "vg":case "y":
254 A = "https://boards.fireden.net/" + global_data[current_page][index]["board"] + "/search/";
255 break;
256 case "adv": case "f": case "hr":case "o":case "pol":case "s4s":case "sp":case "tg":case "trv":case "tv": case "x":
257 A = "https://archive.4plebs.org/" + global_data[current_page][index]["board"] + "/search/";
258 break;
259 case "aco": case "an": case "c":case "d":case "fit":case "gif":case "his":case "int":case "k":case "m": case "mlp": case "qa":case "r9k":case "trash":case "vr":case "wsg":
260 A = "https://desuarchive.org/" + global_data[current_page][index]["board"] + "/search/";
261 break;
262 case "mu": case "cgl": case "g":
263 A = "https://rbt.asia/" + global_data[current_page][index]["board"] + "/search/";
264 break;
265 case "bant": case "vp": case "c":case "con":case "e":case "n":case "news":case "out":case "p":case "toy":case "vip":case "vp":case "w":case "wg":case "wsr":
266 A = "https://archive.nyafuu.org/" + global_data[current_page][index]["board"] + "/search/";
267 break;
268 /*case "c": case "d": case "e":*/ case "i": case "lgbt": case "t": case "u":
269 A = "https://archive.loveisover.me/" + global_data[current_page][index]["board"] + "/search/";
270 break;
271 default:
272 A = "https://archived.moe/" + global_data[current_page][index]["board"] + "/search/";
274 var B = "";
275 var comment = global_data[current_page][index]["com"] + "";
276 if(comment !== ""){
277 var Bi = comment.replace(/<br>/g, " ");
278 var dummy_node = document.createElement("P");
279 dummy_node.innerHTML = Bi;
280 var Bii = dummy_node.textContent + " ";
281 var Biii = Bii.substr(0,Bii.indexOf(" ", Bii.length > 50 ? 50 : Bii.length - 1)).trim();
282 Biv = Biii.replace(/\s+/g, " ");
283 B = encodeURIComponent(Biv);
284 B = "text/" + B + "/";
286 else B = "";
287 var C = (function(){
288 var S = global_data[current_page][index]["now"].split("/");
289 return "end/20" + S[2].substr(0,2) + "-" + S[0] + "-" + (parseInt(S[1])+1) + "/";
290 })();
291 var D
292 if(filename !== undefined)
293 D = "filename/" + filename;
294 else D = "";
295 var URL = A + B + C + D;
296 if(B !== ""){
297 global_data[current_page][index]["com"] = global_data[current_page][index]["com"] + "</br></br><details><summary>" + archive_URL_Text + "</summary><a href = \"" + URL + "\">" + URL + "</a></details>";
299 else
300 global_data[current_page][index]["com"] = global_data[current_page][index]["com"] + "<details><summary>" + archive_URL_Text + "</summary><a href = \"" + URL + "\">" + URL + "</a></details>";
303 function stopFunction(){
304 clearInterval(construct_interval);
307 var interval_counter = 0;
308 function buildFullTableInterval(){
309 var len = global_data[current_page].length;
310 //current_page == max_page ? counter = 0 : counter = 0;
312 //go through all retrived JSON
314 var fake_continue = false;
316 if(interval_counter == -1){
317 stopFunction();
318 buildEntryCounter(board_refine);
319 return;
322 var tr = document.createElement("TR");
323 table.appendChild(tr);
325 if(!fake_continue){
326 counter++;
327 //build table with data
328 var line = global_data[current_page][interval_counter];
329 buildRow(tr, line);
331 interval_counter--;
332 if(interval_counter == -1){
333 table_built[current_page] = true;
335 //change the counter
336 buildEntryCounter(board_refine);
339 function buildRow(tr, line){
341 var width_ratio = window_width / WINDOW_CONSTANT;
342 width_ratio = (width_ratio < 0.0 ? 0.0:width_ratio) ;
344 var vw_size = '1.025vw';
345 var px_size = '18.0px'
347 var fontSize = "font-size:" + vw_size + ";"
348 var td = document.createElement("TD");
349 td.setAttribute("class","boardItem");
350 var tdBoard;
351 if(line["board"] == "s4s") tdBoard = document.createTextNode("[" + line["board"] + "]");
352 else tdBoard = document.createTextNode("/" + line["board"] + "/");
353 td.setAttribute("style", fontSize);
354 td.appendChild(tdBoard);
355 tr.appendChild(td);
357 var fontSize = "font-size:" + vw_size + ";"
358 var td = document.createElement("TD");
359 td.setAttribute("class","nameItem");
360 //if(line["name"].length > 10){}
361 var tdName = document.createTextNode(line["name"]);
362 td.setAttribute("style", fontSize);
363 td.appendChild(tdName);
364 tr.appendChild(td);
366 var fontSize = "font-size:" + vw_size + ";"
367 if(line["trip"] === undefined || line["trip"] === null) line["trip"] = "";
368 var td = document.createElement("TD");
369 td.setAttribute("class","tripItem");
370 var tdTrip = document.createTextNode(line["trip"]);
371 td.setAttribute("style", fontSize);
372 td.appendChild(tdTrip);
373 tr.appendChild(td);
375 var fontSize = "font-size:" + vw_size + ";"
376 var td = document.createElement("TD");
377 td.setAttribute("class","comItem");
378 td.setAttribute("style", fontSize);
379 td.innerHTML = (line["com"]);
380 tr.appendChild(td);
382 var fontSize = "font-size:" + vw_size + ";"
383 var td = document.createElement("TD");
384 td.setAttribute("class","actionItem");
385 td.setAttribute("style", fontSize);
386 td.innerHTML = (line["action"]);
387 tr.appendChild(td);
389 var fontSize = "font-size:" + vw_size + ";"
390 var td = document.createElement("TD");
391 td.setAttribute("class","lengthItem");
392 td.setAttribute("style", fontSize);
393 td.innerHTML = (line["length"]);
394 tr.appendChild(td);
396 var fontSize = "font-size:" + vw_size + ";"
397 var td = document.createElement("TD");
398 td.setAttribute("class","reasonItem");
399 td.setAttribute("style", fontSize);
400 td.innerHTML = (line["reason"]);
401 tr.appendChild(td);
403 var fontSize = "font-size:" + vw_size + ";"
404 var td = document.createElement("TD");
405 td.setAttribute("class","nowItem");
406 td.setAttribute("style", fontSize);
407 td.innerHTML = (line["now"]);
408 tr.appendChild(td);
411 //make alterations to the table without effecting the data.
412 function constructTable(){
413 minus_counter = 0;
415 //rebuild
416 while(table.hasChildNodes()) table.removeChild(table.lastChild);
417 counter = 0;
418 interval_counter = global_data[current_page].length - 1;
419 construct_interval = setInterval(function(){
420 for(var i = 0 ; i < 100; i++)
421 buildFullTableInterval();
422 },25);
425 function buildEntryCounter(board_refine){
426 var temp_counter = counter;
427 if(current_page - max_page != 0) temp_counter += page_load_amount * (actual_page - 2) + max_counter % page_load_amount;
428 //current
429 var rhs = Math.floor(temp_counter / 1000) + "";
430 var lhs = temp_counter % 1000 + "";
431 while(lhs.length < 3) lhs = "0" + lhs;
432 var current;
433 if(rhs == 0) current = lhs;
434 else current = rhs + "," + lhs;
435 //max
436 var rhs_max = Math.floor(max_counter / 1000)+ "";
437 var lhs_max = max_counter % 1000 + "";
438 while(lhs_max.length < 3) lhs_max = "0" + lhs_max;
439 var max;
440 if(rhs_max == 0) max = lhs_max;
441 else max = rhs_max + "," + lhs_max;
442 //min(maybe for use later?)
443 temp_counter -= page_load_amount * (actual_page) + max_counter % page_load_amount;
444 var rhs_min = Math.floor(temp_counter / 1000);
445 var lhs_min = temp_counter % 1000 + "";
446 while(lhs_min.length < 3) lhs_min = "0" + lhs_min;
447 var min;
448 if(rhs_min == 0) min = lhs_min;
449 else min = rhs_min + "," + lhs_min;
451 count.innerHTML = "Displaying <span class='font-weight-bold px-1 py0'> " + current + " </span> of <span class='font-italic px-1 py0'> " + max + " </span> results";
453 if(counter == 0 ){
454 document.getElementById("bansTable").innerHTML = "<tr><td colspan=8>No Results Found on search" + "" + "...</td></tr>";
458 function buildPages(){
459 var page_tables = document.getElementsByClassName("page_table");
460 var page_limit = parseInt(max_page) + 1;
461 window_width = window.innerWidth;
462 for(var table_number = 0; table_number < 2 ; table_number++){
463 //clear for rebuild
464 while(page_tables[table_number].hasChildNodes()){
465 page_tables[table_number].removeChild(page_tables[table_number].firstChild);
467 var top_table = !top_table;
468 for(var page = 1; page <= page_limit; page++){
469 var entry = document.createElement("DIV");
470 entry.setAttribute("onmouseover", 'this.style.backgroundColor=\"rgb(250,250,255)\"');
471 entry.setAttribute("onmouseout", 'this.style.backgroundColor=\"white\"');
472 entry.setAttribute("style","min-width:50px;background-color:white");
473 entry.setAttribute("class","text-center border rounded view overlay");
474 var entry_link = document.createElement("SPAN");
475 var fontSize = "font-size:18px;"
476 //creation for upper page list
477 if(top_table){
478 if(page == actual_page){
479 entry_link.innerHTML = "<a href = \"javascript:void(0)\" style='color:red;" + fontSize +"' >" + page + "</a>";
481 else{
482 entry_link.innerHTML = "<a href = \"javascript:void(0)\" style='" + fontSize +"'>" + page + "</a>";
485 //creation for lower page list
486 else {
487 if(page == actual_page){
488 entry_link.innerHTML = "<a href = \"javascript:void(0)\" style='color:red'>" + page + "</a>";
490 else{
491 entry_link.innerHTML = "<a href = \"javascript:void(0)\">" + page + "</a>";
494 //click logic
495 (function (_page){
496 entry_link.addEventListener("click", function(){
497 if(actual_page != _page){
498 current_page = max_page - (_page - 1);
499 actual_page = _page;
500 table.innerHTML = "<tr><td colspan=8>...Loading New Entries - page " + _page + " ...</td></tr>";
501 //reloads page from index onhashchange
502 //reloads page from index onhashchange
503 board_refine = document.getElementById("refinement").value;
504 comment_refine = encodeURIComponent(document.getElementById("commentrefine").value);
505 rule_refine = document.getElementById("rulerefine").value;
506 window.location.hash = '#' + String(_page) + "|" + board_refine + "|" + comment_refine + "|" + rule_refine;
507 document.getElementById("pages").innerHTML = "Page " + actual_page;
510 })(page);
511 document.getElementById("pages").innerHTML = "Page " + actual_page;
512 entry.appendChild(entry_link);
513 page_tables[table_number].appendChild(entry);