From ec7421f2d2c9b0f5866271750d73571b317b2a0c Mon Sep 17 00:00:00 2001 From: szialajoscosplay <70654182+k3rielit@users.noreply.github.com> Date: Tue, 7 Dec 2021 18:32:42 +0100 Subject: [PATCH] new script: yt normalize links --- youtube/README.md | 11 +++++++++++ youtube/normalize-links.user.js | 24 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 youtube/README.md create mode 100644 youtube/normalize-links.user.js diff --git a/youtube/README.md b/youtube/README.md new file mode 100644 index 0000000..f589b09 --- /dev/null +++ b/youtube/README.md @@ -0,0 +1,11 @@ +## NORMALIZE LINKS +Just replaces ```youtube.com/redirect``` links with the real one. Mostly pointless though. +## HOW TO USE +1. Install the Tampermonkey extension. ([Link](https://www.tampermonkey.net)) +2. [Install](https://github.com/k3rielit/scripts/raw/main/youtube/normalize-links.user.js) +## UPDATES +If it breaks, I'll try fixing it + +(If youtube changes their use of class names, it will break. Which didn't happen to ```yt-formatted-string``` for a long time, but whatever...) + +Last tested: 2021.12.07. diff --git a/youtube/normalize-links.user.js b/youtube/normalize-links.user.js new file mode 100644 index 0000000..6a64653 --- /dev/null +++ b/youtube/normalize-links.user.js @@ -0,0 +1,24 @@ +// ==UserScript== +// @name YT Normalize Links +// @namespace yt_normalize_links +// @version 1.0 +// @description replaces external links with the actual url instead of youtube's own redirect page +// @author k3rielit +// @match *://*.youtube.com/watch?* +// @icon https://www.google.com/s2/favicons?domain=youtube.com +// @grant none +// ==/UserScript== + +(function() { + 'use strict'; + const callback = () => { + let redirects = [...document.getElementsByClassName('yt-formatted-string')].filter(f => f.href && f.href.startsWith('https://www.youtube.com/redirect')); + redirects.forEach(a => { + let decode = decodeURIComponent(a.href.split('q=')[1]); + a.href = decode; + a.innerText = decode.length > 100 ? decode.substring(0,100)+'...' : decode; + }); + }; + const observer = new MutationObserver(callback); + observer.observe(document.documentElement || document.body, { attributes: true, childList: true, subtree: true }); +})(); \ No newline at end of file