// ==UserScript== // @name YouTube auto-timestamper // @namespace Violentmonkey Scripts // @match *://www.youtube.com/* // @grant none // @version 1.2 // @author - // @description 12/17/2025, 5:12:31 PM // ==/UserScript== // interval in milliseconds const interval = 1000; // time before start in ms const startDelay = 5000; // regex used for determining url time const timeRegex = /(([&?])t=[0-9]+)/ // negative time added to the url const timeDelay = 0; // how many seconds before the end do we mash the cancel autoplay button const prefire = 5; const tick = () => { const ytplayer = document.getElementById("movie_player"); if (!ytplayer) { return } let shouldPreventAutoplay = false let time = ytplayer.getCurrentTime(); time = Math.floor(time) if (time + prefire >= ytplayer.getDuration()) { shouldPreventAutoplay = true } time -= timeDelay if (time <= 0) { return } if (shouldPreventAutoplay) { document.querySelector("button[aria-label=\"Cancel autoplay\"]").click() } let currentUrl = window.location.href const baseUrl = window.location.href.replace(timeRegex, "") if (currentUrl.includes("t=")) { const match = currentUrl.match(timeRegex, "t=") currentUrl = currentUrl.replace(timeRegex, match[2] + "t=" + time) } else { currentUrl = currentUrl + "&t=" + time } history.replaceState(baseUrl, "", currentUrl) } console.debug(`autotimestamper will init in ${startDelay/1000}s`) const script = setTimeout(() => { setInterval(tick, interval) console.debug("autotimestamper initialized") }, startDelay)