Force X/Twitter to xcancel.com

Redirects x.com and twitter.com to xcancel.com (preserves path, query, and hash). Skips OAuth to avoid breaking auth flows.

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

You will need to install an extension such as Tampermonkey to install this script.

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         Force X/Twitter to xcancel.com
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Redirects x.com and twitter.com to xcancel.com (preserves path, query, and hash). Skips OAuth to avoid breaking auth flows.
// @author       you
// @match        https://x.com/*
// @match        https://twitter.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
  'use strict';

  const host = window.location.host;
  const path = window.location.pathname || '/';
  const search = window.location.search || '';
  const hash = window.location.hash || '';
  const href = window.location.href;

  const isOnXOrTwitter = host === 'x.com' || host === 'twitter.com';
  const isOAuthUrl = () => {
    // Keep this conservative: do NOT redirect OAuth/authorize flows.
    // Common paths: /i/oauth2/authorize, /oauth, /oauth2
    const p = path.toLowerCase();
    return p.includes('/i/oauth2/authorize') || p === '/oauth' || p.startsWith('/oauth2');
  };

  const redirectToXCancel = () => {
    const newUrl = `https://xcancel.com${path}${search}${hash}`;
    if (newUrl !== href) {
      window.location.replace(newUrl);
    }
  };

  if (isOnXOrTwitter) {
    if (isOAuthUrl()) {
      // Do not modify OAuth flows to prevent breaking logins/app authorization.
      return;
    }
    redirectToXCancel();
  }
})();