Auto Youtube Shorts Scroller

Automatically scrolls through Shorts when a video ends!!! You should use ViolentMonkey because Tampermonkey requires enabling developer mode!!!

  1. // ==UserScript==
  2. // @name Auto Youtube Shorts Scroller
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.2
  5. // @description Automatically scrolls through Shorts when a video ends!!! You should use ViolentMonkey because Tampermonkey requires enabling developer mode!!!
  6. // @author hiensumi
  7. // @match *://www.youtube.com/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. 'use strict';
  14. let pollingInterval = null;
  15. let lastUrl = 'nothing';
  16. let enabled = false;
  17.  
  18. function log(...args) {
  19. console.log('[AutoShorts]', ...args);
  20. }
  21.  
  22. function scrollToNextShort() {
  23. if (!enabled) return;
  24. const buttons = document.querySelectorAll('.yt-spec-button-shape-next');
  25. for (const btn of buttons) {
  26. const svg = btn.querySelector('svg path');
  27. if (!svg) continue;
  28. const d = svg.getAttribute('d');
  29. if (d === 'M4.116 13.884a1.25 1.25 0 011.768-1.768l4.866 4.866V4a1.25 1.25 0 112.5 0v12.982l4.866-4.866a1.25 1.25 0 011.768 1.768L12 21.768l-7.884-7.884Z') {
  30. btn.click();
  31. log('Scrolled to next short');
  32. break;
  33. }
  34. }
  35. }
  36.  
  37. function activateShortsScript() {
  38. enabled = true;
  39. if (pollingInterval) clearInterval(pollingInterval);
  40.  
  41. log('Activated for Shorts page');
  42. let scrolled = false;
  43.  
  44. pollingInterval = setInterval(() => {
  45. // console.log(enabled);
  46. if(!enabled) return;
  47. let vids = document.querySelectorAll('video');
  48. if(window.location.href.includes('short') == true && vids.length){
  49. let vid = Array.from(vids).find(v => v.duration);
  50. //log(vid.duration - vid.currentTime);
  51.  
  52. if (vid.duration > 2.0 && (vid.duration - vid.currentTime <= 1)) {
  53. if (!scrolled) {
  54. log('Video ends, scrolling');
  55. scrolled = true;
  56. setTimeout(() => {
  57. scrollToNextShort();
  58. }, 2000);
  59. }
  60. } else {
  61. scrolled = false;
  62. }
  63. }
  64. else{
  65. enabled = false;
  66. setTimeout(() => {
  67. log('False activation');
  68. }, 1000);
  69. return;
  70. }
  71. }, 500);
  72. }
  73.  
  74. function deactivateShortsScript() {
  75. enabled = false;
  76. if (pollingInterval) {
  77. clearInterval(pollingInterval);
  78. pollingInterval = null;
  79. log('Deactivated (not on Shorts page)');
  80. }
  81. }
  82.  
  83. navigation.addEventListener("navigate", e => {
  84. setTimeout(() => {
  85. log('Navigation: ' + window.location.href);
  86. if(window.location.href.includes('short')){
  87. deactivateShortsScript();
  88. setTimeout(() => {
  89. activateShortsScript();
  90. }, 1000);
  91. }
  92. else{
  93. deactivateShortsScript();
  94. }
  95. }, 3000);
  96. });
  97. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址