Replace youtube redirect links

Replace youtube redirect links with direct links

当前为 2022-10-20 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Replace youtube redirect links
  3. // @description Replace youtube redirect links with direct links
  4. // @author MK
  5. // @namespace max44
  6. // @homepage https://greasyfork.org/en/users/309172-max44
  7. // @match *://*.youtube.com/*
  8. // @match *://*.youtu.be/*
  9. // @icon https://cdn.icon-icons.com/icons2/1488/PNG/512/5295-youtube-i_102568.png
  10. // @version 1.1
  11. // @license MIT
  12. // @require https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
  13. // @run-at document-idle
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. 'use strict';
  18.  
  19. document.querySelectorAll("a[href*='/redirect?']").forEach(replaceRedirect);
  20.  
  21. $( window ).scroll(function() {
  22. document.querySelectorAll("a[href*='/redirect?']").forEach(replaceRedirect);
  23. });
  24.  
  25. function replaceRedirect(link) {
  26. link.href = decodeURIComponent(link.href.replace (/^.*\?(.*&)q=([^&]+)(&.*)?$/, '$2'));
  27. const wrpLink = link.wrappedJSObject || link;
  28. if (wrpLink.data && wrpLink.data.urlEndpoint)
  29. wrpLink.data.urlEndpoint.url = link.href;
  30. }
  31.  
  32. })();