Skip to content

Commit 883e133

Browse files
authored
Merge pull request #3410 from B-Umesh66/dev
Added Shorts Auto-Scroll
2 parents c01fb9f + ecfaa29 commit 883e133

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

js&css/web-accessible/init.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ ImprovedTube.init = function () {
106106
if (ImprovedTube.storage.prevent_shorts_autoloop) {
107107
ImprovedTube.stop_shorts_autoloop();
108108
}
109+
ImprovedTube.shortsAutoScroll();
109110
}
110111
if (window.matchMedia) {
111112
document.documentElement.dataset.systemColorScheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
@@ -162,6 +163,7 @@ document.addEventListener('yt-navigate-finish', function () {
162163
if (ImprovedTube.storage.prevent_shorts_autoloop) {
163164
ImprovedTube.stop_shorts_autoloop();
164165
}
166+
ImprovedTube.shortsAutoScroll();
165167
}
166168
if (document.documentElement.dataset.pageType === 'home' && ImprovedTube.storage.youtube_home_page === 'search') {
167169
document.querySelector('body').style.setProperty('visibility', 'visible', 'important');

js&css/web-accessible/www.youtube.com/player.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2166,3 +2166,44 @@ ImprovedTube.addYouTubeReturnButton = function () {
21662166
}
21672167
}
21682168
};
2169+
2170+
/*------------------------------------------------------------------------------
2171+
SHORTS AUTO SCROLL
2172+
------------------------------------------------------------------------------*/
2173+
ImprovedTube.shortsAutoScroll = function () {
2174+
if (this.storage.shorts_auto_scroll) {
2175+
if (!ImprovedTube.shortsAutoScrollInterval) {
2176+
ImprovedTube.shortsAutoScrollInterval = setInterval(() => {
2177+
if (!location.pathname.startsWith('/shorts/')) return;
2178+
2179+
const activeRenderer = document.querySelector('ytd-reel-video-renderer[is-active]');
2180+
const video = activeRenderer ? activeRenderer.querySelector('video') : null;
2181+
2182+
if (video && !video.dataset.itShortsScrollAttached) {
2183+
video.dataset.itShortsScrollAttached = 'true';
2184+
2185+
video.addEventListener('timeupdate', function () {
2186+
if (!ImprovedTube.storage.shorts_auto_scroll) return;
2187+
if (this.paused) return;
2188+
2189+
if (this.duration && this.currentTime >= this.duration - 0.25) {
2190+
const nextButton = activeRenderer.querySelector('#navigation-button-down button')
2191+
|| document.querySelector('#navigation-button-down button')
2192+
|| document.querySelector('button[aria-label="Next video"]');
2193+
2194+
if (nextButton) {
2195+
this.pause();
2196+
nextButton.click();
2197+
}
2198+
}
2199+
});
2200+
}
2201+
}, 1000);
2202+
}
2203+
} else {
2204+
if (ImprovedTube.shortsAutoScrollInterval) {
2205+
clearInterval(ImprovedTube.shortsAutoScrollInterval);
2206+
ImprovedTube.shortsAutoScrollInterval = null;
2207+
}
2208+
}
2209+
};

menu/skeleton-parts/player.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ extension.skeleton.main.layers.section.player.on.click = {
8484
text: 'preventShortVideoAutoloop',
8585
storage: 'prevent_shorts_autoloop',
8686
},
87+
shorts_auto_scroll: {
88+
component: 'switch',
89+
text: 'autoPlayNextShort',
90+
storage: 'shorts_auto_scroll'
91+
},
8792
autoplay_disable: {
8893
component: 'switch',
8994
text: 'autoplayDisable',

0 commit comments

Comments
 (0)