mackchronus / Youtube - No Redirect Links

// ==UserScript==
// @name         Youtube - No Redirect Links
// @version      0.3
// @description  Clear external links from redirects in video descriptions
// @icon         https://www.youtube.com/favicon.ico
// @author       raingart
// @license      Apache-2.0
// @namespace    youtube-redirect
// @include      http*://*.youtube.com/watch?v=*
// @noframes     
// @run-at       document-end
// ==/UserScript==
/*jshint esversion: 6 */

(function() {
const getQueryURL = (query, urlString) => new URL(urlString || location).searchParams.get(query);
let descriptionInterval = connectInterval();

function processPatch() {
  document.querySelectorAll('a[href*="/redirect?"]')
    .forEach(link => {
      if (q = getQueryURL('q', link.href)) link.href = decodeURIComponent(q);
    });
}

function connectInterval() {
  return setInterval(() => {
   if (document.querySelector('#meta #description:not(:empty)')) {
      clearTimeout(descriptionInterval);
      processPatch();
   }
  }, 1000); // 1 sec
}

document.addEventListener('yt-navigate-start', () => descriptionInterval = connectInterval());
})();