Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        Disqus: Load All
  3. // @namespace   my-disqus-load-all-script
  4. // @description Trigger all the Disqus "read more comments" links, because that's AWFUL.
  5. // @include     https://disqus.com/embed/comments/*
  6. // @version     1
  7. // @grant       none
  8. // ==/UserScript==
  9.  
  10. (function(document, window) {
  11.  
  12.     var waitForLoad = function() {
  13.         if (typeof(window.DISQUS) == "undefined" || typeof(window.jQuery) == "undefined") {
  14.             // Still waiting for Disqus and jQuery libraries to load.
  15.             window.setTimeout(waitForLoad, 500);
  16.         }
  17.         else {
  18.             // The 'show more' links to look for.
  19.             var clickable = 'a.show-children:visible, a.load-more__button:visible';
  20.             // Process all the visible 'show more' links.
  21.             var processUnclickedLinks = function() {
  22.                 jQuery('section#conversation').find(clickable).each(function(idx, el) {
  23.                     var link = jQuery(el);
  24.                     // And, unless they have already been clicked,
  25.                     // or have been hidden, click them.
  26.                     if (!link.hasClass('busy')) {
  27.                         // console.log(el);
  28.                         link.click();
  29.                     }
  30.                 });
  31.             }
  32.             // Whenever *any* AJAX loading finishes...
  33.             jQuery(document).ajaxComplete(function(event, jqXHR, ajaxOptions) {
  34.                 // Check to see if the element in question was a
  35.                 // Disqus 'load more' link.
  36.                 var activeElement = jQuery(event.target.activeElement);
  37.                 if (activeElement.hasClass('show-children') || activeElement.hasClass('load-more__button')) {
  38.                     window.setTimeout(processUnclickedLinks, 500);
  39.                     // If the hidden thread is sufficiently lengthy,
  40.                     // one click of a given link may be insufficient
  41.                     // to load all of its descendants.  In addition
  42.                     // the request might fail for some reason.  In
  43.                     // either case we can't assume that the link we
  44.                     // clicked has been successfully finished with.
  45.                     //
  46.                     // As we always filter on the currently-visible
  47.                     // links, it's a pretty low-cost workaround to
  48.                     // just Try Again a few seconds later in order
  49.                     // to deal with any such stragglers.
  50.                     window.setTimeout(processUnclickedLinks, 5000);
  51.                 }
  52.             });
  53.         }
  54.     };
  55.     // Begin by waiting for the Disqus and jQuery libraries to load.
  56.     window.setTimeout(waitForLoad, 500);
  57.  
  58. })(document, window);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement