Greasy Fork 还支持 简体中文。

Reddit Expand Post

Expand posts on Reddit feeds and dynamically detect new posts to expand

  1. // ==UserScript==
  2. // @name Reddit Expand Post
  3. // @namespace https://rant.li/boson
  4. // @match *://*.reddit.com/*
  5. // @grant none
  6. // @version 1.7
  7. // @author Boson
  8. // @description Expand posts on Reddit feeds and dynamically detect new posts to expand
  9. // @license GNU AGPLv3
  10. // ==/UserScript==
  11. (function () {
  12. 'use strict';
  13.  
  14. let expandingInProgress = false;
  15.  
  16. function detectAndClickExpandos() {
  17. const expandos = document.querySelectorAll('.expando-button.collapsed');
  18. if (expandos.length === 0 || expandingInProgress) return;
  19. expandingInProgress = true;
  20. let delay = 0;
  21. const expandosArray = Array.from(expandos);
  22. const postsToExpand = expandosArray.slice(0, 10);
  23.  
  24. if (postsToExpand.length > 0) {
  25. postsToExpand.forEach((expando, index) => {
  26. if (!expando.classList.contains('clicked')) {
  27. setTimeout(() => {
  28. expando.click();
  29. expando.classList.add('clicked');
  30. }, delay);
  31. delay += 1000;
  32. }
  33. });
  34. }
  35.  
  36. setTimeout(() => {
  37. expandingInProgress = false;
  38. }, delay);
  39. }
  40.  
  41. function setupIntersectionObserver() {
  42. const observer = new IntersectionObserver((entries) => {
  43. entries.forEach(entry => {
  44. if (entry.isIntersecting && !entry.target.classList.contains('expanded')) {
  45. detectAndClickExpandos();
  46. entry.target.classList.add('expanded');
  47. }
  48. });
  49. }, { threshold: 0.5 });
  50.  
  51. const posts = document.querySelectorAll('.expando-button.collapsed');
  52. posts.forEach(post => observer.observe(post));
  53. }
  54.  
  55. window.addEventListener('load', () => {
  56. detectAndClickExpandos();
  57. setupIntersectionObserver();
  58. });
  59.  
  60. setInterval(() => {
  61. detectAndClickExpandos();
  62. }, 1000);
  63. })();