Invidio.us embed

Replace YouTube embeds with Invidio.us embeds.

  1. // ==UserScript==
  2. // @name Invidio.us embed
  3. // @namespace Backend
  4. // @description Replace YouTube embeds with Invidio.us embeds.
  5. // @include *
  6. // @exclude https://www.youtube.com/*
  7. // @exclude https://*.google.com/*
  8. // @version 2.52
  9. // ==/UserScript==
  10. var a = 0; //set to 1 to autoplay embedded videos present on initial page load (not recommended)
  11. var b = 0; //set to 1 to autoplay embedded videos that appear on page interaction
  12.  
  13. var observer = new MutationObserver(mutate);
  14. observer.observe(document,{childList:true,attributes:true,subtree:true});
  15.  
  16. function mutate(){
  17. go(b);
  18. }
  19. function go(auto){
  20. var filter = Array.filter || Benchmark.filter;
  21. var frames = document.getElementsByTagName("iframe");
  22. frames = filter(frames, youtubeiFrame);
  23. for(var i=0; i<frames.length; i++){
  24. var frame = frames[i];
  25. var src = frame.getAttribute('src');
  26. var invid = src.
  27. replace('www.youtube.com', 'invidio.us').
  28. replace('www.youtube-nocookie.com','invidio.us').
  29. replace('youtu.be/', 'invidio.us/watch?v=')
  30. .replace('autoplay=','');
  31.  
  32. if(invid.indexOf('?') === -1){
  33. invid += '?autoplay=' + auto;
  34. }else{
  35. invid += '&autoplay=' + auto;
  36. }
  37. frame.setAttribute('src', invid);
  38. }
  39. }
  40. function youtubeiFrame(el) {
  41. if(el.hasAttribute('src')){
  42. return el.getAttribute('src').indexOf('youtube') !== -1;
  43. }
  44. return false;
  45. }
  46. go(a);