Guest User

youtube linkswap

a guest
Nov 18th, 2012
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* EMBED YOUTUBE LINKS */
  2. if (getValue("embedYoutube") === "true"){
  3.   $('a').each(function(i, o){
  4.     var videoid = false;
  5.     if ($(this).attr('href') === undefined){
  6.       return;
  7.     }
  8.     if ($(this).attr('href').toLowerCase().indexOf('www.youtube.') !== -1 && $(this).attr('href').toLowerCase().indexOf('/watch?') !== -1){
  9.       videoid = $(this).attr('href').split('?')[1]; // only params
  10.       videoid = videoid.split('#')[0]; // discard hash
  11.       videoid = videoid.split('&'); // split params
  12.       videoid.forEach(function(o, i){ // find videoid
  13.         var sp = o.split('=');
  14.         if (sp[0] === 'v'){ // we found v=?? param, so we have our guy
  15.           videoid = sp[1];
  16.           return false;
  17.         }
  18.         return true;
  19.       });
  20.     } else if ($(this).attr('href').toLowerCase().indexOf('youtu.be') !== -1){
  21.       videoid = $(this).attr('href').split('?')[0]; // only before params
  22.       videoid = videoid.split('/');
  23.       videoid = videoid[videoid.length - 1]; // only last url bit
  24.     }
  25.     if (videoid !== false){
  26.       var embedstring;
  27.       if (getValue("embedYoutubeNewstyle") === "true"){
  28.         embedstring = '<br/><iframe width="640" height="360" src="http://www.youtube.com/embed/' + videoid + '" frameborder="0" allowfullscreen></iframe><br/>';
  29.       } else {
  30.         embedstring = '<br/><object width="640" height="360"><param name="movie" value="http://www.youtube.com/v/' + videoid + '?version=3&amp;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&amp;hl=en_GB" type="application/x-shockwave-flash" width="640" height="360" allowscriptaccess="always" allowfullscreen="true"></embed></object><br/>';
  31.       }
  32.       if (getValue("embedYoutubeButtons") === "true"){
  33.         (function(that, embedstring){
  34.           var youtubebutton = $('<button>').html('embed').css('padding', '0').click(function(){
  35.             $(this).replaceWith(embedstring);
  36.           });
  37.           $(that).after(youtubebutton);
  38.         })(this, embedstring);
  39.       } else {
  40.         $(this).after(embedstring);
  41.       }
  42.     }
  43.   });
  44. }
Advertisement
Add Comment
Please, Sign In to add comment