Skip to content

Instantly share code, notes, and snippets.

@marcoos
Created March 14, 2012 20:47
Show Gist options
  • Save marcoos/2039390 to your computer and use it in GitHub Desktop.
Save marcoos/2039390 to your computer and use it in GitHub Desktop.
Bookmarklet replacing oldschoold YouTube Flash embeds with the iframe-based HTML5 embeds
// Replaces obsolete Flash-based embeds of YouTube video
// with new embeds using HTML5.
//
// Useful, if you don't have Flash.
(function () {
var i,
videoId,
frame;
embeds = document.querySelectorAll("embed[src^='http://www.youtube.com/v/']");
for (i = 0; i < embeds.length; i++) {
try {
videoId = (/youtube.com\/v\/([a-zA-Z0-9]+)/).exec(embeds[i].src)[1];
frame = document.createElement("iframe");
frame.width = 640;
frame.height = 385;
frame.style.border = 0;
frame.src = "http://www.youtube.com/embed/" + videoId;
embeds[i].parentNode.replaceChild(frame, embeds[i]);
} catch (e) {}
}
}());
(function(){var i,videoId,frame;embeds=document.querySelectorAll("embed[src^='http://www.youtube.com/v/']");for(i=0;i<embeds.length;i++){try{videoId=(/youtube.com\/v\/([a-zA-Z0-9]+)/).exec(embeds[i].src)[1];frame=document.createElement("iframe");frame.width=640;frame.height=385;frame.style.border=0;frame.src="http://www.youtube.com/embed/"+videoId;embeds[i].parentNode.replaceChild(frame,embeds[i]);}catch(e){}}}());
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2012 Marek Stepien <marek.stepien@gmail.com>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
@marcoos
Copy link
Author

marcoos commented Mar 14, 2012

Go to http://jsfiddle.net/marcoos/RTRVj/embedded/result/ if you just want to install this bookmarklet.

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