重定向x.com到Twitter.com

Redirects x.com URLs to Twitter.com and ensures the 'mx=1' parameter is present.

当前为 2025-05-24 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name X.com to Twitter.com Redirect
  3. // @name:zh-CN 重定向x.com到Twitter.com
  4. // @namespace NTE
  5. // @version 1.0
  6. // @description Redirects x.com URLs to Twitter.com and ensures the 'mx=1' parameter is present.
  7. // @description:zh-cn 重定向x.com到Twitter.com并确保后面有“mx=1"参数
  8. // @author NTE
  9. // @match *://x.com/*
  10. // @match *://twitter.com/*
  11. // @grant none
  12. // @license AGPL-3.0-or-later
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. console.log('Tampermonkey script is running.');
  19.  
  20. const currentUrl = new URL(window.location.href);
  21. let newUrl = new URL(window.location.href); // Start with a copy of the current URL
  22.  
  23. let shouldRedirect = false;
  24.  
  25. // Case 1: If the hostname ends with x.com
  26. if (currentUrl.hostname.endsWith('x.com')) {
  27. newUrl.hostname = 'twitter.com';
  28. newUrl.searchParams.set('mx', '1');
  29.  
  30. // Handle the root path redirection specifically for x.com
  31. if (currentUrl.pathname === '/') {
  32. newUrl.pathname = ''; // Remove the trailing slash for the root path
  33. }
  34. shouldRedirect = true;
  35. console.log('Detected x.com, preparing to redirect to twitter.com.');
  36. }
  37. // Case 2: If the hostname ends with twitter.com and 'mx' parameter is missing
  38. else if (currentUrl.hostname.endsWith('twitter.com') && !currentUrl.searchParams.has('mx')) {
  39. newUrl.searchParams.set('mx', '1');
  40. shouldRedirect = true;
  41. console.log('Detected twitter.com without mx=1, preparing to add parameter.');
  42. }
  43.  
  44. // Perform redirection if needed
  45. if (shouldRedirect && newUrl.toString() !== currentUrl.toString()) {
  46. console.log('Redirecting from:', currentUrl.toString());
  47. console.log('Redirecting to:', newUrl.toString());
  48. window.location.replace(newUrl.toString());
  49. } else {
  50. console.log('No redirection needed for:', currentUrl.toString());
  51. }
  52.  
  53. })();

QingJ © 2025

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