Redirect X & Twitter to xcancel.com in address bar

Redirect x.com and twitter.com URLs to xcancel.com in address bar. The behaviour of this script changed as it now fires on the windows.location property.

当前为 2025-10-12 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name 			Redirect X & Twitter to xcancel.com in address bar
// @namespace		x.com-xcancel.com-redirect
// @version			2.0.1
// @description	Redirect x.com and twitter.com URLs to xcancel.com in address bar. The behaviour of this script changed as it now fires on the windows.location property.
// @author			github.com/localhorst
// @license MIT
// @match 			*://*.x.com/*
// @match 			*://*.twitter.com/*
// @exclude 		*://*.x.com/i/*
// @exclude 		*://*.twitter.com/i/*
// @run-at 			document-start
// @grant           none
// ==/UserScript==

// Enforce strict mode for better code quality
'use strict';

// Declare constant for current URL
const currentUrl = window.location.href;

// Declare constant for old reddit URL
const xCancelUrl = 'https://xcancel.com/';

// Check if the current URL does not include old.x.com
if (currentUrl.includes("twitter.com") || currentUrl.includes("x.com")) {
  // Use regex literal and constant for new URL
	const newUrl = currentUrl.replace(/^https?:\/\/(www\.)?(x|twitter)\.com\//, xCancelUrl);
  // Redirect to new URL without history entry
  window.location.replace(newUrl);
}