Skip to content

Commit

Permalink
new script: yt normalize links
Browse files Browse the repository at this point in the history
  • Loading branch information
k3rielit committed Dec 7, 2021
1 parent 87dd25e commit ec7421f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
11 changes: 11 additions & 0 deletions youtube/README.md
Original file line number Diff line number Diff line change
@@ -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.
24 changes: 24 additions & 0 deletions youtube/normalize-links.user.js
Original file line number Diff line number Diff line change
@@ -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 });
})();

0 comments on commit ec7421f

Please sign in to comment.