The version of vichan running on lainchan.org
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

106 linhas
3.0KB

  1. /*
  2. * live-index.js
  3. * https://github.com/vichan-devel/Tinyboard/blob/master/js/live-index.js
  4. *
  5. * Released under the MIT license
  6. * Copyright (c) 2014 Marcin Łabanowski <marcin@6irc.net>
  7. *
  8. * Usage:
  9. * $config['api']['enabled'] = true;
  10. * $config['additional_javascript'][] = 'js/jquery.min.js';
  11. * $config['additional_javascript'][] = 'js/expand.js';
  12. * $config['additional_javascript'][] = 'js/live-index.js';
  13. *
  14. */
  15. if (active_page == 'index' && (""+document.location).match(/\/(index\.html)?(\?|$|#)/))
  16. +function() {
  17. // Make jQuery respond to reverse()
  18. $.fn.reverse = [].reverse;
  19. var board_name = (""+document.location).match(/\/([^\/]+)\/[^/]*$/)[1];
  20. var handle_one_thread = function() {
  21. if ($(this).find(".new-posts").length <= 0) {
  22. $(this).find("br.clear").before("<div class='new-posts'>"+_("No new posts.")+"</div>");
  23. }
  24. };
  25. $(function() {
  26. $("hr:first").before("<hr /><div class='new-threads'>"+_("No new threads.")+"</div>");
  27. $('div[id^="thread_"]').each(handle_one_thread);
  28. setInterval(function() {
  29. $.getJSON(configRoot+board_name+"/0.json", function(j) {
  30. var new_threads = 0;
  31. j.threads.forEach(function(t) {
  32. var s_thread = $("#thread_"+t.posts[0].no);
  33. if (s_thread.length) {
  34. var my_posts = s_thread.find(".post.reply").length;
  35. var omitted_posts = s_thread.find(".omitted");
  36. if (omitted_posts.length) {
  37. omitted_posts = omitted_posts.html().match("^[^0-9]*([0-9]+)")[1]|0;
  38. my_posts += omitted_posts;
  39. }
  40. my_posts -= t.posts[0].replies|0;
  41. my_posts *= -1;
  42. update_new_posts(my_posts, s_thread);
  43. }
  44. else {
  45. new_threads++;
  46. }
  47. });
  48. update_new_threads(new_threads);
  49. });
  50. }, 20000);
  51. });
  52. $(document).on("new_post", function(e, post) {
  53. if (!$(post).hasClass("reply")) {
  54. handle_one_thread.call(post);
  55. }
  56. });
  57. var update_new_threads = function(i) {
  58. var msg = i ?
  59. (fmt(_("There are {0} new threads."), [i]) + " <a href='javascript:void(0)'>"+_("Click to expand")+"</a>.") :
  60. _("No new threads.");
  61. if ($(".new-threads").html() != msg) {
  62. $(".new-threads").html(msg);
  63. $(".new-threads a").click(fetch_new_threads);
  64. }
  65. };
  66. var update_new_posts = function(i, th) {
  67. var msg = (i>0) ?
  68. (fmt(_("There are {0} new posts in this thread."), [i])+" <a href='javascript:void(0)'>"+_("Click to expand")+"</a>.") :
  69. _("No new posts.");
  70. if ($(th).find(".new-posts").html() != msg) {
  71. $(th).find(".new-posts").html(msg);
  72. $(th).find(".new-posts a").click(window.expand_fun);
  73. }
  74. };
  75. var fetch_new_threads = function() {
  76. $.get(""+document.location, function(data) {
  77. $(data).find('div[id^="thread_"]').reverse().each(function() {
  78. if ($("#"+$(this).attr("id")).length) {
  79. // okay, the thread is there
  80. }
  81. else {
  82. var thread = $(this).insertBefore('div[id^="thread_"]:first');
  83. $(document).trigger("new_post", this);
  84. }
  85. });
  86. });
  87. };
  88. }();