Redirect X & Twitter to xcancel.com in address bar

Redirect x.com and twitter.com URLs to xcancel.com in address bar.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==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.
// @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")) && !currentUrl.includes("twitter.com/i/") && !currentUrl.includes("x.com/i/")) {
  // 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);
}