Advertisement
Guest User

Untitled

a guest
Aug 28th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. // ==UserScript==
  2. // @name hima auto-update
  3. // @namespace himasugi.org
  4. // @description autoreload for himasugi.org
  5. // @include https://himasugi.org/*
  6. // @include http://himasugi.org/*
  7. // @grant none
  8.  
  9. // ==/UserScript==
  10.  
  11. /* Auto-update
  12. */
  13.  
  14. // only run on thread page
  15. if($('div.banner').length > 0 && $(".post.op").size() == 1 ) {
  16.  
  17.  
  18. var poll_interval;
  19. var reload_timeout = 5; // seconds
  20. var count = reload_timeout;
  21.  
  22. var orig_title = document.title;
  23. var new_posts = 0;
  24. var first_new_post = null;
  25. var update_title = function() {
  26. document.title = (new_posts ? "("+new_posts+") " : "") + orig_title;
  27.  
  28. };
  29.  
  30. /* From: https://github.com/savetheinternet/Tinyboard/blob/master/js/auto-reload.js */
  31.  
  32.  
  33. var poll = function() {
  34. $.ajax({
  35. url: document.location,
  36. success: function(data) {
  37. $(data).find('div.post.reply').each(function() {
  38. var id = $(this).attr('id');
  39. if($('#' + id).length == 0) {
  40. if (!new_posts) {
  41. first_new_post = this;
  42. }
  43. $(this).insertAfter($('div.post:last').next()).after('<br class="clear">');
  44. new_posts++;
  45. $(document).trigger('new_post', this);
  46. recheck_activated();
  47. }
  48. });
  49. }
  50. });
  51.  
  52.  
  53. $('#autoreload-counter').html(reload_timeout);
  54. poll_interval = setTimeout(countdown, 1000);
  55. };
  56.  
  57. var countdown = function() {
  58. if (count <= 1) {
  59. count = reload_timeout;
  60. $('#autoreload-counter').html('...');
  61. // poll in 1 second
  62. poll_interval = setTimeout(poll, 1000);
  63. }
  64. else {
  65. count--;
  66. $('#autoreload-counter').html(count);
  67. // count down again in 1 second
  68. poll_interval = setTimeout(countdown, 1000);
  69. }
  70. };
  71. };
  72. var toggle_autoreload = function() {
  73. if (poll_interval) {
  74. clearTimeout(poll_interval);
  75. poll_interval = false;
  76. }
  77. else {
  78. countdown();
  79. }
  80. };
  81.  
  82. // add counter to bottom left corner
  83. // click to toggle autoreloading
  84. $('<style type="text/css">\
  85. a.autoreload-counter {\
  86. position: fixed;\
  87. left: 0;\
  88. top: 100%;\
  89. display: block;\
  90. margin-top: -20px;\
  91. padding: 0px 13px;\
  92. text-decoration: none;\
  93. }\
  94. </style>').appendTo($('head'));
  95. $('<a href="javascript:void(0)" class="autoreload-counter" id="autoreload-counter">'+count+'</a>')
  96. .click(toggle_autoreload).prependTo($('body'));
  97.  
  98. $(window).on('quick-reply', function() {
  99. $('.quick-reply-btn').remove();
  100. });
  101.  
  102. // start timer
  103. poll_interval = setTimeout(countdown, 1000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement