summaryrefslogtreecommitdiff
path: root/youtube-auto-timestamper.user.js
diff options
context:
space:
mode:
authorewy <ewy0@protonmail.com>2026-05-05 03:02:32 +0200
committerewy <ewy0@protonmail.com>2026-05-05 03:02:32 +0200
commita0026e0b7c798b07ad3a6ce8d3706e9f3b9ba1af (patch)
treea07ebb3a579e5ac05c1173ac52878cd123f0a188 /youtube-auto-timestamper.user.js
parentdadb5a1350724a517feb002336c74efb28bfd600 (diff)
add autoplay cancelHEADmaster
Diffstat (limited to 'youtube-auto-timestamper.user.js')
-rw-r--r--youtube-auto-timestamper.user.js43
1 files changed, 27 insertions, 16 deletions
diff --git a/youtube-auto-timestamper.user.js b/youtube-auto-timestamper.user.js
index b2efcef..490a2f6 100644
--- a/youtube-auto-timestamper.user.js
+++ b/youtube-auto-timestamper.user.js
@@ -3,21 +3,22 @@
// @namespace Violentmonkey Scripts
// @match *://www.youtube.com/*
// @grant none
-// @version 1.0
+// @version 1.2
// @author -
// @description 12/17/2025, 5:12:31 PM
// ==/UserScript==
-// interval in ms
-const interval = 1000;
-// start delay in ms
-const startDelay = 10000;
-// substracted time in seconds
-const timeDelay = 0;
+// 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]+)/
-
-let lastTime = undefined;
+// 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");
@@ -25,16 +26,27 @@ const tick = () => {
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=")
@@ -43,16 +55,15 @@ const tick = () => {
currentUrl = currentUrl + "&t=" + time
}
- if (time == lastTime) {
- return
- }
- lastTime = time
- history.replaceState(currentUrl, "", currentUrl)
+ history.replaceState(baseUrl, "", currentUrl)
}
-const script =
-setTimeout(() => {
+console.debug(`autotimestamper will init in ${startDelay/1000}s`)
+
+
+const script = setTimeout(() => {
setInterval(tick, interval)
console.debug("autotimestamper initialized")
}, startDelay)
+