123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- // ==UserScript==
- // @name Invidious Embed
- // @namespace InvidiousEmbed
- // @author Jesús E.
- // @license GPL version 3 or any later version::: https://www.gnu.org/licenses/gpl-3.0.html
- // @description Replace YouTube embeds with invidious instance
- // @homepageURL https://git.sr.ht/~heckyel/book/blob/master/scripts-greasemonkey
- // @include *
- // @exclude /^http(s|)://(www[.]|)youtube[.]com/.*$/
- // @exclude /^http(s|)://(www[.]|)invidio[.]us/.*$/
- // @exclude /^http(s|)://(www[.]|proxy[.]|)invidious[.]snopyta[.]org/.*$/
- // @exclude /^http(s|)://(www[.]|)vid[.]wxzm[.]sx/.*$/
- // @exclude /^http(s|)://(www[.]|)invidious[.]kabi[.]tk/.*$/
- // @exclude /^http(s|)://(www[.]|)invidiou[.]sh/.*$/
- // @exclude /^http(s|)://(www[.]|)yewtu[.]be/.*$/
- // @exclude /^http(s|)://(www[.]|)invidious[.]ggc-project[.]de/.*$/
- // @exclude /^http(s|)://(www[.]|)invidious[.]enkirton[.]net/.*$/
- // @exclude /^http(s|)://(www[.]|)tube[.]poal[.]co/.*$/
- // @exclude /^http(s|)://(www[.]|)invidious[.]13ad[.]de/.*$/
- // @version 1.0.5
- // @grant none
- // ==/UserScript==
- let instance = 'invidious.13ad.de' // set instance
- // Console Style - Debug
- const consoleCSS = 'background: #000; color: #00FF00; padding: 0px 7px; border: 1px solid #00FF00; line-height: 16px;';
- const name = GM_info.script.name;
- const version = GM_info.script.version;
- const log = (...args) => console.log('%cUSERSCRIPT | %s %s | %s', consoleCSS, name, version, ...args);
- let i, j, k, index;
- let video_id, video_url, video_link;
- let risky_elements, risky_attributes, risky_node;
- let risky_tags = ["object", "embed", "iframe", "div"];
- let bad_elements = [];
- let bad_ids = [];
- for (i = 0; i < risky_tags.length; i++) {
- risky_elements = document.getElementsByTagName(risky_tags[i]);
- for (j = 0; j < risky_elements.length; j++) {
- index = 0;
- risky_attributes = risky_elements[j].attributes;
- for (k = 0; k < risky_attributes.length; k++) {
- risky_node = risky_attributes[k].value;
- if ((risky_node.indexOf("youtube.com") >= 0) || (risky_node.indexOf("ytimg.com") >= 0) || (risky_node.indexOf("youtube-nocookie.com") >= 0)) {
- risky_elements[j].style.display = "none";
- if (risky_node.indexOf("/v/") >= 0) {
- index = risky_node.indexOf("/v/") + 3;
- } else if (risky_node.indexOf("?v=") >= 0) {
- index = risky_node.indexOf("?v=") + 3;
- } else if (risky_node.indexOf("/embed/") >= 0) {
- index = risky_node.indexOf("/embed/") + 7;
- }
- if (index > 0) {
- video_id = risky_node.substring(index, index + 11);
- bad_elements.push(risky_elements[j]);
- bad_ids.push(video_id);
- }
- break;
- }
- }
- }
- }
- for (i = 0; i < bad_ids.length; i++) {
- video_id = bad_ids[i];
- video_url = "//" + instance + "/embed/" + video_id;
- video_link = document.createElement("iframe");
- video_link.setAttribute("src", video_url);
- // Set the width, if present
- width = bad_elements[i].getAttribute("width");
- if ( width !== null ) {
- video_link.setAttribute("width", width);
- }
- // Set the height, if present
- height = bad_elements[i].getAttribute("height");
- if ( height !== null ) {
- video_link.setAttribute("height", height);
- }
- video_link.setAttribute("frameborder", "0");
- video_link.setAttribute("allowfullscreen", "1");
- bad_elements[i].parentNode.replaceChild(video_link, bad_elements[i]);
- }
- log('successfully initialized');
|