YouTube Link Fixer

Remove YouTube redirections and show full links in descriptions.

  1. // ==UserScript==
  2. // @name YouTube Link Fixer
  3. // @namespace Violentmonkey Scripts
  4. // @match *://www.youtube.com/*
  5. // @match *://*.youtu.be/*
  6. // @grant none
  7. // @version 1.0
  8. // @author TimeTravel_0
  9. // @license GPLv3
  10. // @description Remove YouTube redirections and show full links in descriptions.
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. // Function to clean YouTube redirect links
  17. function cleanRedirectLinks() {
  18. document.querySelectorAll('a[href*="youtube.com/redirect"]').forEach(anchor => {
  19. const urlParams = new URLSearchParams(new URL(anchor.href).search);
  20. const directUrl = urlParams.get('q'); // Get actual URL from ?q=
  21. if (directUrl) {
  22. anchor.href = decodeURIComponent(directUrl);
  23. }
  24. });
  25. }
  26.  
  27. // Function to replace truncated text in video descriptions with full URLs
  28. function replaceTruncatedLinks() {
  29. document.querySelectorAll('#description-inline-expander a').forEach(anchor => {
  30. if (anchor.href && !anchor.href.includes('youtube.com') && !anchor.href.includes('youtu.be')) {
  31. anchor.textContent = anchor.href;
  32. }
  33. });
  34. }
  35.  
  36.  
  37. // Run on initial page load
  38. cleanRedirectLinks();
  39. replaceTruncatedLinks();
  40.  
  41. // Use MutationObserver to watch for dynamic content changes
  42. const observer = new MutationObserver(() => {
  43. cleanRedirectLinks();
  44. replaceTruncatedLinks();
  45. });
  46.  
  47. observer.observe(document.body, { childList: true, subtree: true });
  48.  
  49. })();