Skip to content

Instantly share code, notes, and snippets.

@aijadugar
Created July 17, 2026 10:03
Show Gist options
  • Select an option

  • Save aijadugar/82e739ba595839d18fd288d91c2e48ca to your computer and use it in GitHub Desktop.

Select an option

Save aijadugar/82e739ba595839d18fd288d91c2e48ca to your computer and use it in GitHub Desktop.
(function () {
// type in console: allow pasting
if (window.__shortsAutoScroll) {
console.log('Auto-scroll already running.');
return;
}
window.__shortsAutoScroll = true;
let lastTime = 0;
let hasScrolled = false;
function getActiveVideo() {
const videos = document.querySelectorAll('video');
for (const v of videos) {
const rect = v.getBoundingClientRect();
if (rect.height > 0 && rect.top >= 0 && rect.top < window.innerHeight) {
return v;
}
}
return null;
}
function scrollToNextShort() {
document.dispatchEvent(new KeyboardEvent('keydown', {
key: 'ArrowDown',
code: 'ArrowDown',
keyCode: 40,
which: 40,
bubbles: true
}));
}
setInterval(() => {
const video = getActiveVideo();
if (!video || !video.duration) return;
const t = video.currentTime;
if (lastTime > video.duration - 0.5 && t < 0.5 && !hasScrolled) {
hasScrolled = true;
console.log('Short finished once — scrolling to next.');
scrollToNextShort();
}
if (t > 1) {
hasScrolled = false;
}
lastTime = t;
}, 200);
console.log('Shorts auto-scroll-on-complete is active.');
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment