invidio_embed.user.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // ==UserScript==
  2. // @name Invidious Embed
  3. // @namespace InvidiousEmbed
  4. // @author Jesús E.
  5. // @license GPL version 3 or any later version::: https://www.gnu.org/licenses/gpl-3.0.html
  6. // @description Replace YouTube embeds with invidious instance
  7. // @homepageURL https://git.sr.ht/~heckyel/book/blob/master/scripts-greasemonkey
  8. // @include *
  9. // @exclude /^http(s|)://(www[.]|)youtube[.]com/.*$/
  10. // @exclude /^http(s|)://(www[.]|)invidio[.]us/.*$/
  11. // @exclude /^http(s|)://(www[.]|proxy[.]|)invidious[.]snopyta[.]org/.*$/
  12. // @exclude /^http(s|)://(www[.]|)vid[.]wxzm[.]sx/.*$/
  13. // @exclude /^http(s|)://(www[.]|)invidious[.]kabi[.]tk/.*$/
  14. // @exclude /^http(s|)://(www[.]|)invidiou[.]sh/.*$/
  15. // @exclude /^http(s|)://(www[.]|)yewtu[.]be/.*$/
  16. // @exclude /^http(s|)://(www[.]|)invidious[.]ggc-project[.]de/.*$/
  17. // @exclude /^http(s|)://(www[.]|)invidious[.]enkirton[.]net/.*$/
  18. // @exclude /^http(s|)://(www[.]|)tube[.]poal[.]co/.*$/
  19. // @exclude /^http(s|)://(www[.]|)invidious[.]13ad[.]de/.*$/
  20. // @version 1.0.5
  21. // @grant none
  22. // ==/UserScript==
  23. let instance = 'invidious.13ad.de' // set instance
  24. // Console Style - Debug
  25. const consoleCSS = 'background: #000; color: #00FF00; padding: 0px 7px; border: 1px solid #00FF00; line-height: 16px;';
  26. const name = GM_info.script.name;
  27. const version = GM_info.script.version;
  28. const log = (...args) => console.log('%cUSERSCRIPT | %s %s | %s', consoleCSS, name, version, ...args);
  29. let i, j, k, index;
  30. let video_id, video_url, video_link;
  31. let risky_elements, risky_attributes, risky_node;
  32. let risky_tags = ["object", "embed", "iframe", "div"];
  33. let bad_elements = [];
  34. let bad_ids = [];
  35. for (i = 0; i < risky_tags.length; i++) {
  36. risky_elements = document.getElementsByTagName(risky_tags[i]);
  37. for (j = 0; j < risky_elements.length; j++) {
  38. index = 0;
  39. risky_attributes = risky_elements[j].attributes;
  40. for (k = 0; k < risky_attributes.length; k++) {
  41. risky_node = risky_attributes[k].value;
  42. if ((risky_node.indexOf("youtube.com") >= 0) || (risky_node.indexOf("ytimg.com") >= 0) || (risky_node.indexOf("youtube-nocookie.com") >= 0)) {
  43. risky_elements[j].style.display = "none";
  44. if (risky_node.indexOf("/v/") >= 0) {
  45. index = risky_node.indexOf("/v/") + 3;
  46. } else if (risky_node.indexOf("?v=") >= 0) {
  47. index = risky_node.indexOf("?v=") + 3;
  48. } else if (risky_node.indexOf("/embed/") >= 0) {
  49. index = risky_node.indexOf("/embed/") + 7;
  50. }
  51. if (index > 0) {
  52. video_id = risky_node.substring(index, index + 11);
  53. bad_elements.push(risky_elements[j]);
  54. bad_ids.push(video_id);
  55. }
  56. break;
  57. }
  58. }
  59. }
  60. }
  61. for (i = 0; i < bad_ids.length; i++) {
  62. video_id = bad_ids[i];
  63. video_url = "//" + instance + "/embed/" + video_id;
  64. video_link = document.createElement("iframe");
  65. video_link.setAttribute("src", video_url);
  66. // Set the width, if present
  67. width = bad_elements[i].getAttribute("width");
  68. if ( width !== null ) {
  69. video_link.setAttribute("width", width);
  70. }
  71. // Set the height, if present
  72. height = bad_elements[i].getAttribute("height");
  73. if ( height !== null ) {
  74. video_link.setAttribute("height", height);
  75. }
  76. video_link.setAttribute("frameborder", "0");
  77. video_link.setAttribute("allowfullscreen", "1");
  78. bad_elements[i].parentNode.replaceChild(video_link, bad_elements[i]);
  79. }
  80. log('successfully initialized');