Advertisement
Guest User

tgchan autoupdate

a guest
Mar 13th, 2018
439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         tgchan autoupdate
  3. // @namespace    http://tampermonkey.net/
  4. // @version      0.2
  5. // @description  tgchan autoupdate
  6. // @author       Rex
  7. // @include      http*://tgchan.org/kusaba/quest/res/*
  8. // @include      http*://tgchan.org/kusaba/questarch/res/*
  9. // @grant        none
  10. // @require      https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
  11. // @run-at       document-start
  12. // ==/UserScript==
  13. jQuery.noConflict();
  14.  
  15. jQuery(document).ready(function($) {
  16.     function checkWTForUpdates(timeout) {
  17.         var urlparts = window.location.href.split('/');
  18.         new Ajax.Request(ku_boardspath + '/threadwatch.php?board=' + urlparts[4] + '&threadid=' + /*urlparts.pop().split('.')[0]*/'0',
  19.         {
  20.             method:'get',
  21.             onSuccess: function(transport){
  22.                 var response = transport.responseText;
  23.                 if(!response)
  24.                     location.reload();
  25.                 var resObject = jQuery('<div>').append(transport.responseText).find('strong');
  26.                 if(resObject.html() != '0') {
  27.                     jQuery.get(window.location.href, function( data ) {
  28.                         var n = data.indexOf('<div style="display: none;" class="unicorn">');
  29.                         var d = data.substring(n);
  30.                         d = d.substring(0, d.indexOf('</form>'));
  31.                         var pagedata = jQuery('<div>').append(d);
  32.                         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; }));
  33.                         window.location.replace(resObject.parent().attr('href'));
  34.                         setTimeout(function() {
  35.                             checkWTForUpdates(5000);
  36.                         }, 5000);
  37.                     });
  38.                 }
  39.                 else {
  40.                     var newTimeout = timeout >= 30000 ? timeout : timeout + 5000;
  41.                     setTimeout(function() {
  42.                         checkWTForUpdates(newTimeout);
  43.                     }, timeout);
  44.                 }
  45.             },
  46.             onFailure: function(){ location.reload(); }
  47.         });
  48.     }
  49.     setTimeout(function() {
  50.         checkWTForUpdates(5000);
  51.     }, 5000);
  52. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement