Last active
January 20, 2022 04:21
-
-
Save Greydus/577aadfcbedde0e43fe6ecec176832c8 to your computer and use it in GitHub Desktop.
Replaces all YouTube embed URLs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Yoshino | |
// @namespace moe.greydus | |
// @version 2.28.0 | |
// @description Replaces all YouTube embed URLs | |
// @match *://*/* | |
// @exclude-match https://www.youtube.com/* | |
// ==/UserScript== | |
var iframe_list = document.querySelectorAll('iframe[src*="www.youtube.com"]'); | |
for(var i = 0; iframe_list.length > 0 && i < iframe_list.length; i++) { | |
var iframe = iframe_list[i]; | |
// Some embeds use the `data-src` attribute | |
if(iframe.getAttribute("data-src") != null) | |
iframe.setAttribute("data-src", Zadkiel(iframe.getAttribute("data-src")).invidious.url); | |
if(iframe.getAttribute("src") != null) | |
iframe.setAttribute("src", Zadkiel(iframe.getAttribute("src")).invidious.url); | |
} | |
function Zadkiel(youtube_video_url) { | |
var youtube_video_url_regexp = /(http(?:s)?:)?\/\/(www\.youtube(?:-nocookie)?\.com)(\/(?:watch\?v=|embed\/))([A-Za-z0-9-_]+)/, _protocol, _domain, _path, _id; | |
if(youtube_video_url != undefined) { | |
_protocol = ((youtube_video_url.match(youtube_video_url_regexp)[1] != undefined) ? youtube_video_url.match(youtube_video_url_regexp)[1] : ""); | |
_domain = youtube_video_url.match(youtube_video_url_regexp)[2]; | |
_path = youtube_video_url.match(youtube_video_url_regexp)[3]; | |
_id = youtube_video_url.match(youtube_video_url_regexp)[4]; | |
return { | |
id: _id, | |
youtube: { | |
url: _protocol + "//" + _domain + _path + _id, | |
short_url: "https://youtu.be/" + _id | |
}, | |
invidious: { | |
url: _protocol + "//invidio.us" + _path + _id | |
}, | |
hooktube: { | |
url: _protocol + "//hooktube.com" + _path + _id | |
} | |
} | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment