Skip to content

Instantly share code, notes, and snippets.

@AndrewMast
Created April 9, 2026 03:11
Show Gist options
  • Select an option

  • Save AndrewMast/9a391183fed6eb76754eabd5d4fb870a to your computer and use it in GitHub Desktop.

Select an option

Save AndrewMast/9a391183fed6eb76754eabd5d4fb870a to your computer and use it in GitHub Desktop.
Saves the YouTube video's current time to the url when the video is paused or when you seek through it.
function setupVideoListeners(firstLoad) {
let videoPlayer = document.querySelector("ytd-player video");
if (!videoPlayer || !videoPlayer instanceof HTMLVideoElement) {
return;
}
if (firstLoad) {
videoPlayer.hasEventListenersAdded = false;
}
if (videoPlayer.hasEventListenersAdded) {
return;
}
videoPlayer.addEventListener("pause", (event) => {
setPageTime(videoPlayer.currentTime);
console.log('Paused');
});
videoPlayer.addEventListener("seeked", (event) => {
setPageTime(videoPlayer.currentTime);
console.log('Seeked');
});
videoPlayer.hasEventListenersAdded = true;
}
function setPageTime(time) {
const url = new URL(window.location.href);
const seconds = Math.floor(time);
if (seconds == 0) {
url.searchParams.delete('t');
} else {
url.searchParams.set('t', seconds + 's');
}
console.log('Time: ' + seconds + 's');
window.history.replaceState({}, '', url);
}
window.addEventListener("load", (event) => { setTimeout(() => setupVideoListeners(true), 500); });
navigation.addEventListener('navigate', (event) => { setupVideoListeners(false); });

Youtube Timestamp Saver

Saves the YouTube video's current time to the url when the video is paused or when you seek through it. Made for Brave, but will probably work on other browsers too.

Instructions

  1. Go to brave://settings/shields/filters.
  2. Turn on Developer mode (Allow adding custom filters and scriptlets).
  3. Click Add new scriptlet and enter the name user-youtube-time-save.js.
  4. Paste in the contents of the user-youtube-time-save.js file in this gist as the script's content and hit save.
  5. Add the custom filter youtube.com##+js(user-youtube-time-save.js) to ensure the scriptlet is run on YouTube.

Credits

Created by Andrew Mast, parts of code taken from a Firefox add-on created by ridiche34 and a Brave scriptlet created by andyface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment