Greasy Fork is available in English.
Instantly redirects any x.com page to xcancel.com in a new tab, including homepage and direct links (SPA-safe).
当前为
// ==UserScript==
// @name X → XCancel Redirect
// @namespace http://tampermonkey.net/
// @version v2
// @license MIT
// @description Instantly redirects any x.com page to xcancel.com in a new tab, including homepage and direct links (SPA-safe).
// @author 83
// @match https://x.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=x.com
// @grant none
// ==/UserScript==
(function() {
'use strict';
const redirectToXCancel = (url) => {
const newUrl = url.replace("https://x.com", "https://xcancel.com");
// Avoid infinite opening
if (newUrl !== url) {
console.log(`[Tampermonkey] Redirecting to: ${newUrl}`);
window.open(newUrl, "_blank");
}
};
let lastUrl = location.href;
const checkUrlChange = () => {
const currentUrl = location.href;
if (currentUrl !== lastUrl) {
lastUrl = currentUrl;
redirectToXCancel(currentUrl);
}
};
// Check regularly for SPA changes
setInterval(checkUrlChange, 500);
// Redirect immediately on initial page load
redirectToXCancel(location.href);
})();