Reddit Infinite Scrolling

Adds infinite scrolling to subreddits and to comments.

  1. // ==UserScript==
  2. // @name Reddit Infinite Scrolling
  3. // @namespace darkred
  4. // @version 2018.4.25
  5. // @description Adds infinite scrolling to subreddits and to comments.
  6. // @author darkred
  7. // @license MIT
  8. // @include https://www.reddit.com/*
  9. // @include https://old.reddit.com/*
  10. // @grant unsafeWindow
  11. // @require http://code.jquery.com/jquery-2.1.4.min.js
  12. // @require https://cdnjs.cloudflare.com/ajax/libs/jscroll/2.4.1/jquery.jscroll.min.js
  13. // @supportURL https://github.com/darkred/Userscripts/issues
  14. // ==/UserScript==
  15.  
  16. // Jscroll code
  17. $('#siteTable').jscroll({
  18. nextSelector: 'span.nextprev a:last',
  19. contentSelector: '#siteTable .thing, .nav-buttons',
  20. callback: function() {
  21. $('.nav-buttons').remove();
  22. }
  23. });
  24.  
  25.  
  26. //if current URL contains the string 'comments', then click the 'more comments' button when scrolling at the end of the page
  27. if (/(.*comments.*)/.test(document.location)) {
  28. $(window).scroll(function() {
  29. if ($(window).scrollTop() + $(window).height() > $(document).height() - 100) {
  30. // console.log('bottom!');
  31. var element = unsafeWindow.document.getElementsByClassName('morecomments');
  32. var last = element.length;
  33. element[last - 1].firstChild.click();
  34. }
  35. });
  36. }