From 28b8f6106eadf5c94d79509df7a311b9dfe529c2 Mon Sep 17 00:00:00 2001
From: Choom
Date: Sun, 18 Dec 2022 05:29:23 -0300
Subject: Fix autorefresh
---
static/js/autorefresh.js | 110 +++++++++++++++++++----------------------------
1 file changed, 45 insertions(+), 65 deletions(-)
(limited to 'static/js/autorefresh.js')
diff --git a/static/js/autorefresh.js b/static/js/autorefresh.js
index cec1e33..cd4bf39 100644
--- a/static/js/autorefresh.js
+++ b/static/js/autorefresh.js
@@ -41,80 +41,53 @@ function loadJSON() {
}
function updateThread(posts, total_replies, serverTime) {
- var thread_div = document.getElementsByClassName("thread")[0];
- if (serviceType == 2) var last_elem = document.getElementById("size");
- else var last_elem = document.getElementsByClassName("cut")[0];
+ var threadDiv = document.getElementsByClassName("thread")[0];
+ if (serviceType == 2) {
+ var repliesDiv = threadDiv.getElementsByClassName("replies")[0];
+ }
+
for (var i = 0; i < posts.length; i++) {
post = posts[i];
var num = thread_length + i + 1;
+
var div = document.createElement("div");
- if (serviceType == 2) div.className = "reply";
- else div.className = "replycont";
- if (post.email) {
- if (post.tripcode)
- s_name =
- '' +
- post.name +
- " " +
- post.tripcode +
- "";
- else
- s_name =
- '' +
- post.name +
- "";
+ div.id = 'p' + post.id;
+ if (serviceType == 2) {
+ div.dataset.n = num;
+ div.className = "reply";
+ if (post.IS_DELETED > 0) {
+ div.className += " deleted";
+ }
} else {
- if (post.tripcode)
- s_name =
- '' +
- post.name +
- " " +
- post.tripcode +
- "";
- else s_name = '' + post.name + "";
+ div.className = "replycont";
}
+
+ var s_name = '';
+ if (post.email) s_name += '' + post.name + '';
+ if (post.tripcode) s_name += ' ' + post.tripcode;
+ s_name += '';
+ if (post.email) s_name += '';
+
+ var s_img = '';
if (serviceType == 2) {
if (post.file) {
- s_img =
- '
' +
- Math.round(post.file_size / 1024) +
- "KB " +
- post.file
- .substring(post.file.lastIndexOf(".") + 1, post.file.length)
- .toUpperCase() +
- "";
- } else s_img = "";
- if (post.IS_DELETED == 1)
+ s_img = '' +
+ '';
+ }
+
+ if (post.IS_DELETED == 1) {
div.innerHTML =
- '
" + post.message + ""; } if (post.IS_DELETED == 0) { @@ -234,8 +208,14 @@ function updateThread(posts, total_replies, serverTime) { } } - thread_div.insertBefore(div, last_elem); - thread_div.setAttribute("data-length", num); + if (serviceType == 2) { + repliesDiv.appendChild(div); + } else { + threadDiv.appendChild(div); + } + + threadDiv.setAttribute("data-length", num); + if (serviceType == 2) document .getElementsByTagName("h3")[0] -- cgit v1.2.1-18-gbd029