Infinite Scroll Spotify Episodes

Automatically clicks the "Load More Episodes" button when scrolling down the page on Spotify

当前为 2024-07-05 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Infinite Scroll Spotify Episodes
  3. // @namespace https://greasyfork.org/en/users/1200587-trilla-g
  4. // @version 1.0
  5. // @description Automatically clicks the "Load More Episodes" button when scrolling down the page on Spotify
  6. // @author Trilla_G
  7. // @match *://*.open.spotify.com/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. let isPaused = false;
  16.  
  17. // Define the selector for the button with the exact class name
  18. const buttonSelector = '.vqQmhCMZq7eUtTV7YYOQ.epDbBe.LegacyChipInner__ChipInnerComponent-sc-1qguixk-0';
  19.  
  20. // Function to check for the button and click it
  21. function checkForButtonAndClick() {
  22. if (isPaused) return;
  23. const button = document.querySelector(buttonSelector);
  24. if (button) {
  25. button.click();
  26. console.log('Button clicked!');
  27. }
  28. }
  29.  
  30. // Function to handle scroll events
  31. function onScroll() {
  32. if (!isPaused) {
  33. checkForButtonAndClick();
  34. }
  35. }
  36.  
  37. // Add scroll event listener
  38. window.addEventListener('scroll', onScroll);
  39.  
  40. // Use a MutationObserver to detect when the button is added to the DOM
  41. const observer = new MutationObserver((mutations) => {
  42. mutations.forEach((mutation) => {
  43. if (!isPaused && mutation.addedNodes.length > 0) {
  44. checkForButtonAndClick();
  45. }
  46. });
  47. });
  48.  
  49. // Start observing the body for added nodes
  50. observer.observe(document.body, { childList: true, subtree: true });
  51.  
  52. // Initial check in case the button is already present when the script runs
  53. checkForButtonAndClick();
  54.  
  55. // Add an event listener for the specific keystroke to pause the function
  56. document.addEventListener('keydown', (event) => {
  57. if (event.code === 'Delete') {
  58. isPaused = true;
  59. console.log('Paused for 15 seconds');
  60. setTimeout(() => {
  61. isPaused = false;
  62. console.log('Resumed');
  63. }, 15000); // 15000 milliseconds = 15 seconds
  64. }
  65. });
  66. })();