ForceTwitterURL

Redirects x.com to twitter.com and enforces ?mx=1 on all URLs

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

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

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         ForceTwitterURL
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Redirects x.com to twitter.com and enforces ?mx=1 on all URLs
// @author       nyathea
// @match        https://x.com/*
// @match        https://twitter.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    const currentUrl = window.location.href;
    const path = window.location.pathname || '/home';
    
    // Check if the URL is an OAuth URL
    const isOAuthUrl = () => {
        return path.includes('/i/oauth2/authorize');
    };

    // Redirect to twitter.com with ?mx=1
    const redirectToTwitterWithMx = (redirectPath = '/home') => {
        const newUrl = `https://twitter.com${redirectPath}?mx=1`;
        window.location.replace(newUrl);
    };

    if (currentUrl.startsWith('https://x.com')) {
        if (isOAuthUrl()) {
            // For OAuth URLs on x.com, redirect to twitter.com preserving all query parameters
            const newUrl = `https://twitter.com${path}${window.location.search}`;
            window.location.replace(newUrl);
        } else {
            // For non-OAuth URLs on x.com, redirect to twitter.com with ?mx=1
            redirectToTwitterWithMx(path);
        }
    } else if (currentUrl.startsWith('https://twitter.com')) {
        // For twitter.com URLs
        if (isOAuthUrl()) {
            // Don't modify OAuth URLs on twitter.com
            return;
        } else if (!currentUrl.includes('?mx=1')) {
            // Ensure ?mx=1 is appended
            redirectToTwitterWithMx(path);
        } else if (currentUrl === 'https://twitter.com/') {
            // Redirect twitter.com/ to twitter.com/home?mx=1
            redirectToTwitterWithMx('/home');
        }
    }
})();