YouTube Link Cleaner

Removes unneeded parameters and redirection pages from YouTube links.

  1. // ==UserScript==
  2. // @name YouTube Link Cleaner
  3. // @name:de YouTube Link Cleaner
  4. // @namespace tfr
  5. // @description Removes unneeded parameters and redirection pages from YouTube links.
  6. // @description:de Entfernt unnötige Parameter und Weiterleitungsseiten aus YouTube-Links.
  7. // @author tfr (https://github.com/t-fr/)
  8. // @license CC0; https://creativecommons.org/publicdomain/zero/1.0/
  9. // @license MIT license; https://pastebin.com/raw.php?i=4TMeeUXC
  10. // @compatible firefox Works with Firefox and Greasemonkey
  11. // @compatible chrome Works with Chrome and Tampermonkey
  12. // @compatible opera Works with Opera and Tampermonkey Beta or Violent monkey
  13. // @oujs:author tfr
  14. // @include http://youtube.com/*
  15. // @include http://www.youtube.com/*
  16. // @include https://youtube.com/*
  17. // @include https://www.youtube.com/*
  18. // @version 8
  19. // @grant none
  20. // ==/UserScript==
  21.  
  22. /* This script is dual-licensed under CC0 and the MIT license.
  23. * You can choose which one you want to use.
  24. * CC0 license: http://creativecommons.org/publicdomain/zero/1.0/deed.en
  25. * MIT license: https://pastebin.com/raw.php?i=4TMeeUXC
  26. *
  27. * Dieses Skript steht sowohl unter CC0 als auch unter der MIT-Lizenz.
  28. * Sie können sich aussuchen, welche Lizenz Sie nutzen.
  29. * CC0-Lizenz: http://creativecommons.org/publicdomain/zero/1.0/deed.de
  30. * MIT-Lizenz: https://pastebin.com/raw.php?i=4TMeeUXC
  31. */
  32. /* Version 8: Accidentally removed the disabling of redirect pages, restore it
  33. * Version 7: Found another way to disable SPF
  34. * Version 6: Update license data
  35. * Version 5: update metadata, German description
  36. * Version 4: change URL parameters without reloading
  37. */
  38. /* If on a redirect page, redirect */
  39. if(window.location.pathname == "/redirect") {
  40. window.location.href.match(/(&|\?)q=(.*?)(&|$)/);
  41. window.location.replace(window.decodeURIComponent(RegExp.$2));
  42. }
  43. /* If a unneeded parameter exists, remove it */
  44. if(window.location.href.match(/(&(feature|src_vid|annotation_id|gl|hl)=[a-zA-Z0-9_\-\.]*|\?(feature|src_vid|annotation_id|gl|hl)=[a-zA-Z0-9_\-\.]*$)/)) {
  45. window.history.replaceState({}, window.document.title, window.location.href.replace(/(&(feature|src_vid|annotation_id|gl|hl)=[a-zA-Z0-9_\-\.]*|\?(feature|src_vid|annotation_id|gl|hl)=[a-zA-Z0-9_\-\.]*$)/g, ''));
  46. }
  47. for (var i = 0; i < window.document.links.length; i++) {
  48. /* Remove unneeded parameters */
  49. window.document.links[i].href = window.document.links[i].href.replace(/(&(feature|src_vid|annotation_id|gl|hl)=[a-zA-Z0-9_\-\.]*|\?(feature|src_vid|annotation_id|gl|hl)=[a-zA-Z0-9_\-\.]*$)/g, '');
  50. /* Do not use redirect pages */
  51. window.document.links[i].className = window.document.links[i].className.replace(/(yt-uix-redirect-link)/g, "");
  52. }
  53. // Disable SPF, inspired by https://openuserjs.org/scripts/JoeSimmons/YouTube_-_Disable_Red_Bar_aka_SPF/source
  54. if(window && window._spf_state && window._spf_state.config) {
  55. window._spf_state.config["navigate-limit"] = 0;
  56. }