The version of vichan running on lainchan.org
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

117 строки
2.9KB

  1. /*****************************************************************
  2. * ------- WARNING! --------- *
  3. *****************************************************************
  4. * This script is at the current time undocumented and *
  5. * unsupported. It is still a work in progress and will likely *
  6. * change. You are on your own. *
  7. *****************************************************************/
  8. +function() {
  9. var uniq = function(a) {
  10. var b = {};
  11. var c = [];
  12. a.forEach(function(i) {
  13. if (!b[i]) {
  14. c.push(i);
  15. b[i] = true;
  16. }
  17. });
  18. return c;
  19. };
  20. if (active_page == 'thread' || active_page == 'index') {
  21. var board = null;
  22. $(function() {
  23. board = $('input[name="board"]').first().val();
  24. });
  25. $(document).on('ajax_after_post', function(e, r) {
  26. var threads = JSON.parse(localStorage.obthreads || '[]');
  27. var thread = null;
  28. if (active_page == 'index') {
  29. thread = r.id|0;
  30. }
  31. else {
  32. thread = $('[id^="thread_"]').first().attr('id').replace("thread_", "")|0;
  33. }
  34. threads.push([board, thread]);
  35. threads = uniq(threads);
  36. localStorage.obthreads = JSON.stringify(threads);
  37. });
  38. }
  39. var loaded = false;
  40. $(function() {
  41. loaded = true;
  42. });
  43. var activate = function() {
  44. if (document.location.hash != '#own') return false;
  45. if (loaded) late_activate();
  46. else $(function() { late_activate(); });
  47. return true;
  48. };
  49. var late_activate = function() {
  50. $('[id^="thread_"]').remove();
  51. var threads = JSON.parse(localStorage.obthreads || '[]');
  52. threads.forEach(function(v) {
  53. var board = v[0];
  54. var thread = v[1];
  55. var url = "/"+board+"/res/"+thread+".html";
  56. $.get(url, function(html) {
  57. var s = $(html).find('[id^="thread_"]');
  58. s[0].bumptime = (new Date(s.find("time").last().attr("datetime"))).getTime();
  59. var added = false;
  60. $('[id^="thread_"]').each(function() {
  61. if (added) return;
  62. if (s[0].bumptime > this.bumptime) {
  63. added = true;
  64. s.insertBefore(this);
  65. }
  66. });
  67. if (!added) {
  68. s.appendTo('[name="postcontrols"]');
  69. }
  70. s.find('.post.reply').addClass('hidden').hide().slice(-3).removeClass('hidden').show();
  71. s.find('.post.reply.hidden').next().addClass('hidden').hide(); // Hide <br> elements
  72. var posts_omitted = s.find('.post.reply.hidden').length;
  73. var images_omitted = s.find('.post.reply.hidden img').length;
  74. if (posts_omitted > 0) {
  75. var omitted = $(fmt('<span class="omitted">'+_('{0} posts and {1} images omitted.')+' '+_('Click reply to view.')+'</span>',
  76. [posts_omitted, images_omitted]));
  77. omitted.appendTo(s.find('.post.op'));
  78. }
  79. var reply = $('<a href="'+url+'">['+_('Reply')+']</a>').appendTo(s.find('.intro').first());
  80. $(document).trigger('new_post', s[0]);
  81. });
  82. });
  83. };
  84. $(window).on("hashchange", function() {
  85. return !activate();
  86. });
  87. activate();
  88. }();