diff options
| author | Ewy~ <ewy0@protonmail.com> | 2025-12-23 15:23:45 +0100 |
|---|---|---|
| committer | Ewy~ <ewy0@protonmail.com> | 2025-12-23 15:23:45 +0100 |
| commit | 5385ef1fcb058b639b8ee532a42dde3edf6bf09d (patch) | |
| tree | 79604ea18ac9e9e6adad9f67163d91abee83ae80 | |
initial commit
| -rw-r--r-- | README.md | 0 | ||||
| -rw-r--r-- | script.js | 47 |
2 files changed, 47 insertions, 0 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/README.md diff --git a/script.js b/script.js new file mode 100644 index 0000000..105cb08 --- /dev/null +++ b/script.js @@ -0,0 +1,47 @@ +// ==UserScript== +// @name YouTube auto-timestamper +// @namespace Violentmonkey Scripts +// @match *://www.youtube.com/* +// @grant none +// @version 1.0 +// @author - +// @description 12/17/2025, 5:12:31 PM +// ==/UserScript== + +// interval in seconds +const interval = 1000; +const startDelay = 10000; +const timeRegex = /(([&?])t=[0-9]+)/ +const timeDelay = 0; + +const tick = () => { + const ytplayer = document.getElementById("movie_player"); + if (!ytplayer) { + return + } + + let time = ytplayer.getCurrentTime(); + time = Math.floor(time) + + time -= timeDelay + + if (time <= 0) { + return + } + + let currentUrl = window.location.href + + 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(currentUrl, "", currentUrl) +} + +const script = +setTimeout(() => { + setInterval(tick, interval) + console.debug("autotimestamper initialized") +}, startDelay) |
