URL Redirect Redirecter

Redirect the Redirected Url

  1. // ==UserScript==
  2. // @name URL Redirect Redirecter
  3. // @namespace FaustVXUrlRedirect
  4. // @version 0.4.6
  5. // @description Redirect the Redirected Url
  6. // @author FaustVX
  7. // @match http*://www.curseforge.com/*
  8. // @match http*://legacy.curseforge.com/*
  9. // @match http*://*.youtube.com/*
  10. // @match http*://twitter.com/*
  11. // @match http*://github.com/*
  12. // @match http*://calendar.google.com/*
  13. // @match http*://*.ygg.re/*
  14. // @grant none
  15. // @supportURL https://gist.github.com/FaustVX/0deb00258929a517a6e2796f9020e17c#comments
  16. // @contributionURL https://www.paypal.com/donate/?cmd=_donations&business=jonathan-035@hotmail.fr&item_name=TamperMonkey+Url+Redirect
  17. // @license MIT
  18. // ==/UserScript==
  19.  
  20. function run() {
  21. 'use strict';
  22.  
  23. const urlSplit = window.location.href.split('/');
  24. const domainName = urlSplit[2].split('.');
  25.  
  26. function changeHref(query) {
  27. return function (a) {
  28. const urlParams = new URLSearchParams(a.search);
  29. const url = urlParams.get(query);
  30. a.href = decodeURIComponent(url);
  31. }
  32. }
  33.  
  34. function changeTag(node, tag) {
  35. const clone = createElement(tag)
  36. for (const attr of node.attributes) {
  37. clone.setAttributeNS(null, attr.name, attr.value)
  38. }
  39. while (node.firstChild) {
  40. clone.appendChild(node.firstChild)
  41. }
  42. node.replaceWith(clone)
  43. return clone
  44. }
  45.  
  46. function createElement(tag) {
  47. return document.createElementNS(tag === 'svg' ? 'http://www.w3.org/2000/svg' : 'http://www.w3.org/1999/xhtml', tag)
  48. }
  49.  
  50. function execute(i, url, selectorAll, foreach) {
  51. if (domainName[i] === url) {
  52. document.querySelectorAll(selectorAll).forEach(foreach);
  53. return true;
  54. }
  55. return false;
  56. }
  57.  
  58. execute(1, "curseforge", 'a[href*="/linkout"]', changeHref("remoteUrl"))
  59. || execute(1, "youtube", 'a[href*="/redirect"]', changeHref("q"))
  60. || execute(0, "calendar", 'a[href*="/url"]', changeHref("q"))
  61. || execute(0, "github", '.Box-sc-g0xbh4-0.iiAnVG span[data-testid="compare-text"]:not(:has(a))', function(s) {
  62. const href = "compare/" + s.lastChild.textContent;
  63. const a = createElement('a');
  64. a.href = href;
  65. a.innerHTML = s.lastChild.textContent;
  66. s.lastChild.replaceWith(a)
  67. })
  68. || execute(1, "ygg", 'a[href*="/misc/safe_redirect?url="]', function(s) {
  69. const urlParams = new URLSearchParams(s.search);
  70. s.href = detectYgg(urlParams.get('url'));
  71.  
  72. function detectYgg(url) {
  73. const split = atob(url).split('/');
  74. const href = split.slice(split.findIndex((e) => e.includes('ygg')) + 1).join('/');
  75. if (!href.startsWith('http')) {
  76. return '/' + href;
  77. }
  78. return href;
  79. }
  80. })
  81. || execute(0, "twitter", 'a[href*="t.co/"]', function(a) {
  82. if (a.innerHTML.startsWith('<span')) {
  83. a.href = a.innerHTML = a.innerText.replace(/…$/, '');
  84. }
  85. })
  86. };
  87.  
  88. function runWhenReady(callback) {
  89. const tryNow = function() {
  90. try {
  91. callback();
  92. } catch { }
  93. setTimeout(tryNow, 250);
  94. };
  95. tryNow();
  96. }
  97.  
  98. runWhenReady(run);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址