Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name tgchan autoupdate
- // @namespace http://tampermonkey.net/
- // @version 1.0
- // @description tgchan autoupdate
- // @author Rex
- // @include http*://tgchan.org/kusaba/quest/res/*
- // @include http*://tgchan.org/kusaba/questdis/res/*
- // @grant none
- // @require https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
- // @run-at document-start
- // ==/UserScript==
- jQuery.noConflict();
- jQuery(document).ready(function($) {
- var deadline = null;
- setInterval(function(){
- if(!deadline || jQuery('.spanUpdating').html() == 'Updating...')
- return;
- var t = deadline - new Date();
- jQuery('.spanUpdating').html((t - t % 1000) / 1000);
- },1000);
- function updateReplies() {
- jQuery.get(window.location.href, function( data ) {
- var n = data.indexOf('<div style="display: none;" class="unicorn">');
- var d = data.substring(n);
- d = d.substring(0, d.indexOf('</form>'));
- var pagedata = jQuery('<div>').append(d);
- jQuery('table:has(.reply)').last().after(pagedata.find('table:has(.reply)').toArray().filter(function(x) { return jQuery('#' + jQuery(x).find('.reply').get(0).id).length == 0; }));
- var updateUrl = window.location.href.split('#')[0] + '#' + pagedata.find('.reply').last().get(0).id.replace('reply', '');
- if(updateUrl && window.location.href.split('#').pop() != updateUrl.split('#').pop())
- window.location.replace(updateUrl);
- jQuery('.spanUpdating').html('');
- if(jQuery('.chkAuto').is(':checked')) {
- deadline = new Date(new Date().getTime() + 5000);
- setTimeout(function() {
- checkWTForUpdates(5000);
- }, 5000);
- }
- });
- }
- function checkWTForUpdates(timeout) {
- jQuery('.spanUpdating').html('Updating...');
- var urlparts = window.location.href.split('/');
- new Ajax.Request(ku_boardspath + '/threadwatch.php?board=' + urlparts[4] + '&threadid=' + /*urlparts.pop().split('.')[0]*/'0',
- {
- method:'get',
- onSuccess: function(transport){
- var response = transport.responseText;
- if(!response)
- location.reload();
- console.log(transport.responseText, timeout);
- var resObject = jQuery('<div>').append(transport.responseText).find('strong');
- if(resObject.html() != '0')
- updateReplies();
- //updateReplies(resObject.parent().attr('href'));
- else {
- jQuery('.spanUpdating').html('');
- var newTimeout = timeout >= 30000 ? timeout : timeout + 5000;
- deadline = new Date(new Date().getTime() + newTimeout);
- setTimeout(function() {
- if(jQuery('.chkAuto').is(':checked'))
- checkWTForUpdates(newTimeout);
- }, newTimeout);
- }
- },
- onFailure: function(){ location.reload(); }
- });
- }
- var navbar = jQuery('.navbar');
- navbar.append(' [');
- navbar.append(jQuery('<a class="aUpdate" href="#">Update</a>'));
- jQuery('.aUpdate').click(function() { event.preventDefault(); updateReplies(); });
- navbar.append('] [');
- navbar.append(jQuery('<label><input class="chkAuto" type="checkbox" title="Fetch new replies automatically">Auto</label>'));
- jQuery('.chkAuto').mouseup(function() {
- var chk = jQuery(this).is(':checked');
- jQuery('.chkAuto').prop('checked', !chk);
- checkWTForUpdates(0);
- });
- navbar.append('] ');
- navbar.append(jQuery('<span class="spanUpdating"></span>'));
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement