Skip to content

Instantly share code, notes, and snippets.

@avyavya
Created September 16, 2012 07:41
Show Gist options
  • Save avyavya/3731472 to your computer and use it in GitHub Desktop.
Save avyavya/3731472 to your computer and use it in GitHub Desktop.
Bookmarklet as play all embeddable youtube videos with embed player.
javascript:(function(){var%20embeds,iframes,links,ids,url;function%20getVideoId(nodes)%20{var%20i,j,match,attr,list=[],regex=[/http:\/\/([a-z]+\.)?youtube\.com\/v\/([-\w]+)/,/http:\/\/([a-z]+\.)?youtube\.com\/watch\?v=([-\w]+)/,/http:\/\/youtu\.be\/([-\w]+)/];loop:for(i=0;i<nodes.length;++i){if(nodes[i].src){attr=nodes[i].src;}else%20if(nodes[i].href){attr=nodes[i].href;}else{continue;}%20for(j=0;j<regex.length;++j){match=attr.match(regex[j]);if(match){list.push(match.pop());continue%20loop;}}}%20return%20list;}%20function%20unique(arr)%20{var%20i,uniq=[],d={};for(i=0;i<arr.length;++i){if(d[arr[i]]){continue;}%20uniq.push(arr[i]);d[arr[i]]=1;}%20return%20uniq;}%20embeds=getVideoId(document.getElementsByTagName('embed'));iframes=getVideoId(document.getElementsByTagName('iframe'));links=getVideoId(document.getElementsByTagName('a'));ids=unique(embeds.concat(iframes,links));if(!ids.length)return;url='http://youtube.com/v/'+ids.shift()+'?hd=1&autoplay=1&version=3&playlist='+ids.join(',');window.open(url,'YoutubeEmbeddedPlayer','width=480,height=350,menubar=no,toolbar=no,scrollbars=yes');})()
// vim: set sw=2 ts=2 sts=2 et ft=javascript :
/**
* Bookmarklet as play all embeddable youtube videos with embed player.
*/
(function () {
var embeds, iframes, links, ids, url;
function getVideoId(nodes)
{
var i, j, match, attr,
list = [],
regex = [
/http:\/\/([a-z]+\.)?youtube\.com\/v\/([-\w]+)/,
/http:\/\/([a-z]+\.)?youtube\.com\/watch\?v=([-\w]+)/,
/http:\/\/youtu\.be\/([-\w]+)/
];
loop: for (i = 0; i < nodes.length; ++i) {
if (nodes[i].src) {
attr = nodes[i].src;
} else if (nodes[i].href) {
attr = nodes[i].href;
} else {
continue;
}
for (j = 0; j < regex.length; ++j) {
match = attr.match(regex[j]);
if (match) {
list.push(match.pop());
continue loop;
}
}
}
return list;
}
function unique(arr)
{
var i, uniq = [], d = {};
for (i = 0; i < arr.length; ++i) {
if (d[arr[i]]) {
continue;
}
uniq.push(arr[i]);
d[arr[i]] = 1;
}
return uniq;
}
embeds = getVideoId(document.getElementsByTagName('embed'));
iframes = getVideoId(document.getElementsByTagName('iframe'));
links = getVideoId(document.getElementsByTagName('a'));
ids = unique(embeds.concat(iframes, links));
// console.log(ids.length+' youtube vids found.');
if (!ids.length) return;
url = 'http://youtube.com/v/' + ids.shift() + '?hd=1&autoplay=1&version=3&playlist=' + ids.join(',');
window.open(url, 'YoutubeEmbeddedPlayer', 'width=480,height=350,menubar=no,toolbar=no,scrollbars=yes');
})()
Copy link

ghost commented Feb 8, 2022

which one do i bookmark

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