daily pastebin goal
48%
SHARE
TWEET

Untitled

a guest May 3rd, 2018 3,414 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        Youtube embed to Hooktube
  3. // @namespace   Krul & Brood
  4. // @description Scan page for youtube embeds and replace with a Hooktube embed.
  5. // @include     *
  6. // @version     2.1
  7. // ==/UserScript==
  8.  
  9. var a = 0; //set to 1 to autoplay embedded videos present on initial page load (not recommended)
  10. var b = 1; //set to 0 to not autoplay embedded videos that appear on page interaction
  11.  
  12. var observer = new MutationObserver(mutate);
  13. observer.observe(document,{childList:true,attributes:true,subtree:true});
  14.  
  15. function mutate(){
  16.   go(b);
  17. }
  18.  
  19. function go(auto){
  20.   var filter = Array.filter || Benchmark.filter;  
  21.   var frames = document.getElementsByTagName("iframe");
  22.   frames = filter(frames, youtubeiFrame);
  23.  
  24.   for(var i=0; i<frames.length; i++){
  25.     var frame = frames[i];
  26.     var src = frame.getAttribute('src');
  27.     var hookTube = src.replace('youtube', 'hooktube');
  28.     if(hookTube.indexOf('?') === -1){
  29.       hookTube += '?autoplay=' + auto;
  30.     }else{
  31.       hookTube += '&autoplay=' + auto;
  32.     }
  33.     frame.setAttribute('src', hookTube);
  34.   }
  35. }
  36.  
  37. function youtubeiFrame(el) {
  38.   if(el.hasAttribute('src')){
  39.     return el.getAttribute('src').indexOf('youtube') !== -1;
  40.   }
  41.   return false;
  42. }
  43.  
  44. go(a);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top