Invidio.us embed

Replace YouTube embeds with Invidio.us embeds.

目前为 2018-07-20 提交的版本。查看 最新版本

  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. // @version 2.1
  8. // ==/UserScript==
  9. var a = 0; //set to 1 to autoplay embedded videos present on initial page load (not recommended)
  10. var b = 0; //set to 1 to autoplay embedded videos that appear on page interaction
  11. var observer = new MutationObserver(mutate);
  12. observer.observe(document,{childList:true,attributes:true,subtree:true});
  13. function mutate(){
  14. go(b);
  15. }
  16. function go(auto){
  17. var filter = Array.filter || Benchmark.filter;
  18. var frames = document.getElementsByTagName("iframe");
  19. frames = filter(frames, youtubeiFrame);
  20. for(var i=0; i<frames.length; i++){
  21. var frame = frames[i];
  22. var src = frame.getAttribute('src');
  23. var invid = src.replace('www.youtube.com', 'invidio.us');
  24. if(invid.indexOf('?') === -1){
  25. invid += '?autoplay=' + auto;
  26. }else{
  27. invid += '&autoplay=' + auto;
  28. }
  29. frame.setAttribute('src', invid);
  30. }
  31. }
  32. function youtubeiFrame(el) {
  33. if(el.hasAttribute('src')){
  34. return el.getAttribute('src').indexOf('youtube') !== -1;
  35. }
  36. return false;
  37. }
  38. go(a);