Skip to content

Instantly share code, notes, and snippets.

@danthemango
Last active September 2, 2024 20:33
Show Gist options
  • Save danthemango/03f11546fc4082446ab55a7a27853d63 to your computer and use it in GitHub Desktop.
Save danthemango/03f11546fc4082446ab55a7a27853d63 to your computer and use it in GitHub Desktop.
quick javascript function to fetch youtube timestamp from livestream, for pasting into devtools
javascript:(function getURLTime() { const params = (new URL(document.location)).searchParams; const v = params.get('v'); const ytplayer = document.getElementById("movie_player"); const t = Math.round(ytplayer.getCurrentTime()); const newUrl = `https://youtu.be/${v}?t=${t}`; return alert(newUrl); })()
(function getURLTime() {
const params = (new URL(document.location)).searchParams
if(params.has('v')) {
const v = params.get('v');
const ytplayer = document.getElementById("movie_player");
const t = Math.round(ytplayer.getCurrentTime())
const newUrl = `https://youtu.be/${v}?t=${t}`;
return newUrl;
}
return document.location;
})()
@danthemango
Copy link
Author

Prepend with "javascript:" in the URL section of a chrome bookmark. This script allows me to fetch the current timestamp of a youtube livestream while it is broadcasting

@danthemango
Copy link
Author

To use with a bookmark link:

  • create a new bookmark
    • right-click on bookmarks bar
    • click "Add Page"
  • Give it a name
  • paste the chrome-bookmark-code
  • click Save
    Then, when you're watching youtube video or livestream click on it and it will give you an alert with the current video timestamp link, which you can share.

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