Redirect X & Twitter to xcancel.com in address bar

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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);
}