diff options
Diffstat (limited to 'static')
-rw-r--r-- | static/js/autorefresh.js | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/static/js/autorefresh.js b/static/js/autorefresh.js index 0ed3e06..aa04bf1 100644 --- a/static/js/autorefresh.js +++ b/static/js/autorefresh.js @@ -36,13 +36,11 @@ function loadJSON() { function updateThread(posts, total_replies, serverTime) { thread_div = document.getElementsByClassName("thread")[0]; - if (serviceType == 2) - last_elem = document.getElementsByClassName("size")[0]; - else - last_elem = document.getElementsByClassName("cut")[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"; @@ -57,10 +55,10 @@ function updateThread(posts, total_replies, serverTime) { 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) div.innerHTML = '<h4 class="deleted">' + (thread_length + i + 1) + ' : Mensaje eliminado por el usuario.</h4>'; - else if (post.IS_DELETED == 2) div.innerHTML = '<h4 class="deleted">' + (thread_length + i + 1) + ' : Mensaje eliminado por miembro del staff.</h4>'; + if (post.IS_DELETED == 1) div.innerHTML = '<h4 class="deleted">' + num + ' : Mensaje eliminado por el usuario.</h4>'; + else if (post.IS_DELETED == 2) div.innerHTML = '<h4 class="deleted">' + num + ' : Mensaje eliminado por miembro del staff.</h4>'; else - div.innerHTML = '<h4>' + (thread_length + i + 1) + ' : ' + s_name + ' : <span class="date" data-unix="' + post.timestamp + '">' + post.timestamp_formatted + '</span> <span class="del"><a href="/cgi/report/' + board + '/' + post.id + '/' + (thread_length + i + 1) + '" rel="nofollow">rep</a> <a href="#">del</a></span></h4>' + s_img + '<div class="msg">' + post.message + '</div>'; + div.innerHTML = '<h4>' + num + ' : ' + s_name + ' : <span class="date" data-unix="' + post.timestamp + '">' + post.timestamp_formatted + '</span> <span class="del"><a href="/cgi/report/' + board + '/' + post.id + '/' + num + '" rel="nofollow">rep</a> <a href="#">del</a></span></h4>' + s_img + '<div class="msg">' + post.message + '</div>'; } else { if (post.file) { if (post.image_width != 0) { @@ -79,20 +77,21 @@ function updateThread(posts, total_replies, serverTime) { } } - thread_div.insertBefore(div, last_elem); - thread_div.setAttribute("data-length",(thread_length + i + 1)); - if (serviceType == 2) - document.getElementsByTagName("h3")[0].getElementsByTagName("span")[0].innerText = "(" + (thread_length + i + 1) + " respuestas)"; + if (serviceType == 2) thread_div.appendChild(div); + else thread_div.insertBefore(div, document.getElementsByClassName("cut")[0]); + thread_div.setAttribute("data-length",num); + if (serviceType == 2) { + var res=document.getElementsByTagName("h3")[0].getElementsByTagName("span")[0]; + res.innerText = res.innerText.replace(/[0-9]+/, num); + } } if (posts.length > 0) { if (!manual) refreshMaxTime = 10; if (!document.hasFocus()) - if (posts.length > 1) - notif(thread_title, posts.length + ' nuevos mensajes'); - else - notif(thread_title, 'Un nuevo mensaje'); + if (posts.length > 1) notif(thread_title, posts.length + ' nuevos mensajes'); + else notif(thread_title, 'Un nuevo mensaje'); } else { if (refreshMaxTime <= 60) refreshMaxTime += 5; |