diff options
author | Choom | 2022-12-18 05:29:23 -0300 |
---|---|---|
committer | Choom | 2022-12-18 06:43:53 -0300 |
commit | 28b8f6106eadf5c94d79509df7a311b9dfe529c2 (patch) | |
tree | 0426770fdc6a1beeecbcc2f235edfcbff527e36f /static/js/autorefresh.js | |
parent | 7c1cd0237b9ab7446b5528f6586342600641c785 (diff) | |
download | weabot-28b8f6106eadf5c94d79509df7a311b9dfe529c2.tar.gz weabot-28b8f6106eadf5c94d79509df7a311b9dfe529c2.tar.xz weabot-28b8f6106eadf5c94d79509df7a311b9dfe529c2.zip |
Fix autorefresh
Diffstat (limited to 'static/js/autorefresh.js')
-rw-r--r-- | static/js/autorefresh.js | 110 |
1 files changed, 45 insertions, 65 deletions
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 = - '<a href="mailto:' + - post.email + - '"><span class="name"><b>' + - post.name + - "</b> " + - post.tripcode + - "</span></a>"; - else - s_name = - '<a href="mailto:' + - post.email + - '"><span class="name"><b>' + - post.name + - "</b></span></a>"; + 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 = - '<span class="name"><b>' + - post.name + - "</b> " + - post.tripcode + - "</span>"; - else s_name = '<span class="name"><b>' + post.name + "</b></span>"; + div.className = "replycont"; } + + var s_name = ''; + if (post.email) s_name += '<a href="mailto:' + post.email + '>'; + s_name += '<span class="name"><b>' + post.name + '</b>'; + if (post.tripcode) s_name += ' ' + post.tripcode; + s_name += '</span>'; + if (post.email) s_name += '</a>'; + + var s_img = ''; if (serviceType == 2) { if (post.file) { - s_img = - '<a href="/' + - board + - "/src/" + - post.file + - '" target="_blank" class="thumb"><img src="/' + - board + - "/thumb/" + - post.thumb + - '" width="' + - post.thumb_width + - '" height="' + - post.thumb_height + - '" /><br />' + - Math.round(post.file_size / 1024) + - "KB " + - post.file - .substring(post.file.lastIndexOf(".") + 1, post.file.length) - .toUpperCase() + - "</a>"; - } else s_img = ""; - if (post.IS_DELETED == 1) + s_img = '<a class="thumb" href="/' + board + '/src/' + post.file + '" target="_blank">' + + '<img src="/' + board + '/thumb/' + post.thumb + '" width="' + post.thumb_width + + '" height="' + post.thumb_height + '" title="' + post.file + '-(' + post.file_size + ' B)" /></a>'; + } + + if (post.IS_DELETED == 1) { div.innerHTML = - '<h4 class="deleted">' + - num + - " : Mensaje eliminado por el usuario.</h4>"; - else if (post.IS_DELETED == 2) + '<h4>' + num + " : Mensaje eliminado por usuario.</h4>"; + } else if (post.IS_DELETED == 2) { div.innerHTML = - '<h4 class="deleted">' + - num + - " : Mensaje eliminado por miembro del staff.</h4>"; - else + '<h4>' + num + " : Mensaje eliminado por staff.</h4>"; + } else { div.innerHTML = - '<h4><a class="num" href="#">' + + '<h4>' + num + - "</a> : " + + " : " + s_name + ' : <span class="date" data-unix="' + post.timestamp + @@ -131,7 +104,9 @@ function updateThread(posts, total_replies, serverTime) { '<div class="msg">' + post.message + "</div>"; + } } else { + var s_msg = ''; if (post.file) { if (post.image_width != 0) { s_img = @@ -199,7 +174,6 @@ function updateThread(posts, total_replies, serverTime) { post.message + "</blockquote>"; } else { - s_img = ""; s_msg = "<blockquote>" + post.message + "</blockquote>"; } 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] |