Forked from SubhrajitPrusty/yt-shorts-autoplay.js
Last active
April 12, 2023 12:52
-
-
Save liponex/619060ddbbfa24c373843e6ee4d7050f to your computer and use it in GitHub Desktop.
Script that automatically scroll YouTube Shorts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name YouTube Shorts autoscroll | |
// @version v0.0.2 | |
// @grant none | |
// @author Subhrajit Prusty, liponex | |
// @description Just auto scroll through youtube shorts | |
// @match https://www.youtube.com/* | |
// ==/UserScript== | |
(function () { | |
let interval = null; | |
let oldHref = document.location.href; | |
function init() { | |
if (!document.location.href.startsWith("https://www.youtube.com/shorts/")) { | |
if (interval = null) return; | |
clearInterval(interval); | |
interval = null; | |
return; | |
} | |
interval = setInterval(function () { | |
let player = document.querySelector(".html5-video-player"); | |
if (!player) { | |
console.log("======== No Active player, skipping ======= ") | |
return | |
} | |
let video = player.querySelector("video") // to get video | |
let down = document.querySelector("#navigation-button-down") | |
video.loop = false | |
if (video.currentTime === video.duration) { | |
let actualButton = down.getElementsByClassName("style-scope ytd-shorts") | |
if (actualButton.length > 0) { | |
console.log("======== Playing next video ======= ") | |
actualButton[0].click() | |
} | |
} | |
}, 1000); | |
} | |
var observer = new MutationObserver(function(mutations) { | |
mutations.forEach(function(mutation) { | |
if (oldHref != document.location.href) { | |
oldHref = document.location.href; | |
init() | |
} | |
}); | |
}); | |
observer.observe(document.querySelector("body"), { | |
childList: true, | |
subtree: true | |
}); | |
init(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment