The version of vichan running on lainchan.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
3.6KB

  1. (function(){
  2. var cache = new Array(),
  3. thread = false,
  4. loading = false,
  5. ukkotimer = false;
  6. if (localStorage.hiddenboards === undefined) {
  7. localStorage.hiddenboards = "{}";
  8. }
  9. // Load data from HTML5 localStorage
  10. var hiddenboards = JSON.parse(localStorage.hiddenboards);
  11. var storeboards = function() {
  12. localStorage.hiddenboards = JSON.stringify(hiddenboards);
  13. };
  14. $(document).ready(function() {
  15. var addukkohide = function() {
  16. var ukkohide = $('<a href="javascript:void(0);" class="unimportant ukkohide"></a>');
  17. var board = $(this).next().data("board");
  18. var hr = $("<hr />");
  19. $(this).append(ukkohide);
  20. $(this).append(hr);
  21. if (hiddenboards[board] !== true) {
  22. ukkohide.html(_("(hide threads from this board)"));
  23. hr.hide();
  24. }
  25. else {
  26. ukkohide.html(_("(show threads from this board)"));
  27. $(this).next().hide();
  28. }
  29. ukkohide.click(function() {
  30. hiddenboards[board] = (hiddenboards[board] !== true);
  31. if (hiddenboards[board] !== true) {
  32. $('[data-board="'+board+'"]:not([data-cached="yes"])').show().prev().
  33. find('.ukkohide').html(_("(hide threads from this board)")).
  34. parent().find('hr').hide();
  35. }
  36. else {
  37. $('[data-board="'+board+'"]:not([data-cached="yes"])').hide().prev().
  38. find('.ukkohide').html(_("(show threads from this board)"))
  39. .parent().find('hr').show();
  40. }
  41. storeboards();
  42. return false;
  43. });
  44. };
  45. $("h2").each(addukkohide);
  46. $('.pages').hide();
  47. var loadnext = function() {
  48. if (overflow.length == 0) {
  49. $('.pages').show().html(_("No more threads to display"));
  50. }
  51. while($(window).scrollTop() + $(window).height() + 1000 > $(document).height() && !loading && overflow.length > 0) {
  52. var page = modRoot + overflow[0].board + '/' + overflow[0].page;
  53. thread = $('div#thread_' + overflow[0].id + '[data-board="' + overflow[0].board + '"]');
  54. if (thread.length > 0 && thread.attr("data-cached") !== 'yes') { // already present
  55. overflow.shift();
  56. continue;
  57. }
  58. var boardheader = $('<h2><a href="/' + overflow[0].board + '/">/' + overflow[0].board + '/</a> </h2>');
  59. if($.inArray(page, cache) != -1) {
  60. if (thread.length > 0) {
  61. $('div[id*="thread_"]').last().after(thread.attr('data-board', overflow[0].board).attr("data-cached", "no").css('display', 'block'));
  62. boardheader.insertBefore(thread);
  63. addukkohide.call(boardheader);
  64. $(document).trigger('new_post', thread);
  65. }
  66. overflow.shift();
  67. } else {
  68. loading = true;
  69. $('.pages').show().html(_("Loading..."));
  70. $.get(page, function(data) {
  71. cache.push(page);
  72. $(data).find('div[id*="thread_"]').each(function() {
  73. var checkout = $(this).attr('id').replace('thread_', '');
  74. if ($('div#thread_' + checkout + '[data-board="' + overflow[0].board + '"]').length == 0) {
  75. $('form[name="postcontrols"]').prepend($(this).css('display', 'none').attr("data-cached", "yes").attr('data-board', overflow[0].board));
  76. }
  77. });
  78. thread = $('div#thread_' + overflow[0].id + '[data-board="' + overflow[0].board + '"][data-cached="yes"]');
  79. if(thread.length > 0) {
  80. $('div[id*="thread_"]').last().after(thread.attr('data-board', overflow[0].board).attr("data-cached", "no").css('display', 'block'));
  81. boardheader.insertBefore(thread);
  82. addukkohide.call(boardheader);
  83. $(document).trigger('new_post', thread);
  84. }
  85. overflow.shift();
  86. loading = false;
  87. $('.pages').hide().html("");
  88. });
  89. break;
  90. }
  91. }
  92. clearTimeout(ukkotimer);
  93. ukkotimer = setTimeout(loadnext, 1000);
  94. };
  95. $(window).on('scroll', loadnext);
  96. ukkotimer = setTimeout(loadnext, 1000);
  97. });
  98. })();