Skip to content

Instantly share code, notes, and snippets.

@ZiTAL
Last active October 22, 2023 07:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZiTAL/d9159d61caf148524ee32f88c828aa87 to your computer and use it in GitHub Desktop.
Save ZiTAL/d9159d61caf148524ee32f88c828aa87 to your computer and use it in GitHub Desktop.
violentmonkey: convert youtube links to yewtu.be
// ==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)
})()
@ZiTAL
Copy link
Author

ZiTAL commented Oct 22, 2023

open links in new tab

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment