Skip to content

Instantly share code, notes, and snippets.

@RulerOf
Created June 30, 2020 01:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RulerOf/066bd913316eaeb4af9a9a193c61cdd1 to your computer and use it in GitHub Desktop.
Save RulerOf/066bd913316eaeb4af9a9a193c61cdd1 to your computer and use it in GitHub Desktop.
Bookmarklet to make a youtube video fill the window

Use the minified code inside of a bookmarklet. You can test it directly in your browser console on any YouTube video page. It ought to work anywhere but was only tested in Chrome 83.

When you're on a YouTube page, click the bookmarklet and it'll take you to the embedded version of the player that fills the entire window without requiring you to go to full screen mode. This is particularly useful if you have a 16:10 monitor.

The non-minified code is included as a reference to show how it works. There are other window-filling bookmarklets out there. I made this one because I wanted to write it.

if (document.location.host == "www.youtube.com" && document.location.pathname == "/watch") {
// Get embedded video HTML element and the current timestamp
var videoEmbedCode = document.getElementById("movie_player").getVideoEmbedCode();
var videoTimestamp = Math.floor(document.getElementById("movie_player").getCurrentTime());
// Parse the element
var parser = new DOMParser();
var videoEmbedDoc = parser.parseFromString(videoEmbedCode, 'text/html');
// Extract the embed URL
var videoEmbedURL = videoEmbedDoc.getElementsByTagName("iframe")[0].src;
// Navigate to the embedded version
document.location.href = videoEmbedURL + "?start=" + videoTimestamp;
}
if("www.youtube.com"==document.location.host&&"/watch"==document.location.pathname){var videoEmbedCode=document.getElementById("movie_player").getVideoEmbedCode(),videoTimestamp=Math.floor(document.getElementById("movie_player").getCurrentTime()),parser=new DOMParser,videoEmbedDoc=parser.parseFromString(videoEmbedCode,"text/html"),videoEmbedURL=videoEmbedDoc.getElementsByTagName("iframe")[0].src;document.location.href=videoEmbedURL+"?start="+videoTimestamp}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment