Infinite Scroll

Enable infinite scrolling on paginated sites

  1. // ==UserScript==
  2. // @name Infinite Scroll
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Enable infinite scrolling on paginated sites
  6. // @author sharmanhall
  7. // @license MIT
  8. // @match *://*/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. const observer = new IntersectionObserver((entries) => {
  14. entries.forEach(entry => {
  15. if (entry.isIntersecting) {
  16. const nextLink = document.querySelector('a[rel="next"], .pagination-next');
  17. if (nextLink) {
  18. fetch(nextLink.href)
  19. .then(res => res.text())
  20. .then(html => {
  21. const parser = new DOMParser();
  22. const doc = parser.parseFromString(html, 'text/html');
  23. const newContent = doc.querySelector('main, .content, .articles'); // Customize selector as needed
  24. if (newContent) {
  25. document.body.appendChild(newContent);
  26. }
  27. });
  28. }
  29. }
  30. });
  31. });
  32. const footer = document.querySelector('footer');
  33. if (footer) observer.observe(footer);
  34. })();