Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name hima auto-update
- // @namespace himasugi.org
- // @description autoreload for himasugi.org
- // @include https://himasugi.org/*
- // @include http://himasugi.org/*
- // @grant none
- // ==/UserScript==
- /* Auto-update
- */
- // only run on thread page
- if($('div.banner').length > 0 && $(".post.op").size() == 1 ) {
- var poll_interval;
- var reload_timeout = 5; // seconds
- var count = reload_timeout;
- var orig_title = document.title;
- var new_posts = 0;
- var first_new_post = null;
- var update_title = function() {
- document.title = (new_posts ? "("+new_posts+") " : "") + orig_title;
- };
- /* From: https://github.com/savetheinternet/Tinyboard/blob/master/js/auto-reload.js */
- var poll = function() {
- $.ajax({
- url: document.location,
- success: function(data) {
- $(data).find('div.post.reply').each(function() {
- var id = $(this).attr('id');
- if($('#' + id).length == 0) {
- if (!new_posts) {
- first_new_post = this;
- }
- $(this).insertAfter($('div.post:last').next()).after('<br class="clear">');
- new_posts++;
- $(document).trigger('new_post', this);
- recheck_activated();
- }
- });
- }
- });
- $('#autoreload-counter').html(reload_timeout);
- poll_interval = setTimeout(countdown, 1000);
- };
- var countdown = function() {
- if (count <= 1) {
- count = reload_timeout;
- $('#autoreload-counter').html('...');
- // poll in 1 second
- poll_interval = setTimeout(poll, 1000);
- }
- else {
- count--;
- $('#autoreload-counter').html(count);
- // count down again in 1 second
- poll_interval = setTimeout(countdown, 1000);
- }
- };
- };
- var toggle_autoreload = function() {
- if (poll_interval) {
- clearTimeout(poll_interval);
- poll_interval = false;
- }
- else {
- countdown();
- }
- };
- // add counter to bottom left corner
- // click to toggle autoreloading
- $('<style type="text/css">\
- a.autoreload-counter {\
- position: fixed;\
- left: 0;\
- top: 100%;\
- display: block;\
- margin-top: -20px;\
- padding: 0px 13px;\
- text-decoration: none;\
- }\
- </style>').appendTo($('head'));
- $('<a href="javascript:void(0)" class="autoreload-counter" id="autoreload-counter">'+count+'</a>')
- .click(toggle_autoreload).prependTo($('body'));
- $(window).on('quick-reply', function() {
- $('.quick-reply-btn').remove();
- });
- // start timer
- poll_interval = setTimeout(countdown, 1000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement