Last active
October 22, 2023 07:55
-
-
Save ZiTAL/d9159d61caf148524ee32f88c828aa87 to your computer and use it in GitHub Desktop.
violentmonkey: convert youtube links to yewtu.be
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 YouTube Link Replacer | |
// @namespace Violentmonkey Scripts | |
// @match https://www.youtube.com/* | |
// @match https://m.youtube.com/* | |
// @grant none | |
// @run-at document-end | |
// ==/UserScript== | |
(function() | |
{ | |
'use strict' | |
function replaceYouTubeLinks() | |
{ | |
var links = document.querySelectorAll('a') | |
links.forEach(link => | |
{ | |
const href = link.getAttribute('href') | |
if (href && href.match(/^\//)) | |
link.setAttribute('href', "https://yewtu.be"+href) | |
}) | |
} | |
replaceYouTubeLinks() | |
const observer = new MutationObserver(replaceYouTubeLinks) | |
const observerConfig = | |
{ | |
childList: true, | |
subtree: true | |
} | |
observer.observe(document.body, observerConfig) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
open links in new tab