Invidio.us embed

Replace YouTube embeds with Invidio.us embeds.

当前为 2019-02-19 提交的版本,查看 最新版本

  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.4
  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.  
  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. function go(auto){
  19. var filter = Array.filter || Benchmark.filter;
  20. var frames = document.getElementsByTagName("iframe");
  21. frames = filter(frames, youtubeiFrame);
  22. for(var i=0; i<frames.length; i++){
  23. var frame = frames[i];
  24. var src = frame.getAttribute('src');
  25. var invid = src.
  26. replace('www.youtube.com', 'invidio.us').
  27. replace('youtu.be/', 'invidio.us/watch?v=')
  28. .replace('-nocookie','')
  29. .replace('autoplay=','');
  30.  
  31. if(invid.indexOf('?') === -1){
  32. invid += '?autoplay=' + auto;
  33. }else{
  34. invid += '&autoplay=' + auto;
  35. }
  36. frame.setAttribute('src', invid);
  37. }
  38. }
  39. function youtubeiFrame(el) {
  40. if(el.hasAttribute('src')){
  41. return el.getAttribute('src').indexOf('youtube') !== -1;
  42. }
  43. return false;
  44. }
  45. go(a);