YouTube Auto-Player

Auto plays a video at given timestamp.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         YouTube Auto-Player
// @namespace    https://www.youtube.com/
// @version      1.0
// @description  Auto plays a video at given timestamp.
// @author       SaberSpeed77
// @match        https://www.youtube.com/*
// @icon         https://w7.pngwing.com/pngs/566/248/png-transparent-computer-icons-youtube-play-button-button-angle-text-triangle.png
// ==/UserScript==

function autoPlay() {
    const min = 1; // change to whatever (other than 0 because it bugs out; if using just sec, replace lines 15-16 with: `#t=${sec}s`
    const sec = 30; // change to whatever

    if (window.location.href.includes(`#t=${min}m${sec}s`)) {return;}
    const url = window.location.href + `#t=${min}m${sec}s`;
    const curTime = parseFloat(document.getElementsByClassName("ytp-time-current")[0].innerHTML);
    if (curTime < min) {
        window.location.href = url;
        document.getElementsByClassName("ytp-play-button ytp-button")[0].click();
    }
}
window.addEventListener("yt-navigate", () => {autoPlay();});
window.addEventListener("yt-navigate-start", () => {autoPlay();});
window.addEventListener("yt-navigate-finish", () => {autoPlay();});