Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Disqus: Load All
- // @namespace my-disqus-load-all-script
- // @description Trigger all the Disqus "read more comments" links, because that's AWFUL.
- // @include https://disqus.com/embed/comments/*
- // @version 1
- // @grant none
- // ==/UserScript==
- (function(document, window) {
- var waitForLoad = function() {
- if (typeof(window.DISQUS) == "undefined" || typeof(window.jQuery) == "undefined") {
- // Still waiting for Disqus and jQuery libraries to load.
- window.setTimeout(waitForLoad, 500);
- }
- else {
- // The 'show more' links to look for.
- var clickable = 'a.show-children:visible, a.load-more__button:visible';
- // Process all the visible 'show more' links.
- var processUnclickedLinks = function() {
- jQuery('section#conversation').find(clickable).each(function(idx, el) {
- var link = jQuery(el);
- // And, unless they have already been clicked,
- // or have been hidden, click them.
- if (!link.hasClass('busy')) {
- // console.log(el);
- link.click();
- }
- });
- }
- // Whenever *any* AJAX loading finishes...
- jQuery(document).ajaxComplete(function(event, jqXHR, ajaxOptions) {
- // Check to see if the element in question was a
- // Disqus 'load more' link.
- var activeElement = jQuery(event.target.activeElement);
- if (activeElement.hasClass('show-children') || activeElement.hasClass('load-more__button')) {
- window.setTimeout(processUnclickedLinks, 500);
- // If the hidden thread is sufficiently lengthy,
- // one click of a given link may be insufficient
- // to load all of its descendants. In addition
- // the request might fail for some reason. In
- // either case we can't assume that the link we
- // clicked has been successfully finished with.
- //
- // As we always filter on the currently-visible
- // links, it's a pretty low-cost workaround to
- // just Try Again a few seconds later in order
- // to deal with any such stragglers.
- window.setTimeout(processUnclickedLinks, 5000);
- }
- });
- }
- };
- // Begin by waiting for the Disqus and jQuery libraries to load.
- window.setTimeout(waitForLoad, 500);
- })(document, window);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement