Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* EMBED YOUTUBE LINKS */
- if (getValue("embedYoutube") === "true"){
- $('a').each(function(i, o){
- var videoid = false;
- if ($(this).attr('href') === undefined){
- return;
- }
- if ($(this).attr('href').toLowerCase().indexOf('www.youtube.') !== -1 && $(this).attr('href').toLowerCase().indexOf('/watch?') !== -1){
- videoid = $(this).attr('href').split('?')[1]; // only params
- videoid = videoid.split('#')[0]; // discard hash
- videoid = videoid.split('&'); // split params
- videoid.forEach(function(o, i){ // find videoid
- var sp = o.split('=');
- if (sp[0] === 'v'){ // we found v=?? param, so we have our guy
- videoid = sp[1];
- return false;
- }
- return true;
- });
- } else if ($(this).attr('href').toLowerCase().indexOf('youtu.be') !== -1){
- videoid = $(this).attr('href').split('?')[0]; // only before params
- videoid = videoid.split('/');
- videoid = videoid[videoid.length - 1]; // only last url bit
- }
- if (videoid !== false){
- var embedstring;
- if (getValue("embedYoutubeNewstyle") === "true"){
- embedstring = '<br/><iframe width="640" height="360" src="http://www.youtube.com/embed/' + videoid + '" frameborder="0" allowfullscreen></iframe><br/>';
- } else {
- embedstring = '<br/><object width="640" height="360"><param name="movie" value="http://www.youtube.com/v/' + videoid + '?version=3&hl=en_GB"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' + videoid + '?version=3&hl=en_GB" type="application/x-shockwave-flash" width="640" height="360" allowscriptaccess="always" allowfullscreen="true"></embed></object><br/>';
- }
- if (getValue("embedYoutubeButtons") === "true"){
- (function(that, embedstring){
- var youtubebutton = $('<button>').html('embed').css('padding', '0').click(function(){
- $(this).replaceWith(embedstring);
- });
- $(that).after(youtubebutton);
- })(this, embedstring);
- } else {
- $(this).after(embedstring);
- }
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment