Transfermarkt Redirect (all TLDs to .com, www and non-www)

Redirect all transfermarkt.* domains (except .com) to transfermarkt.com as early as possible

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Transfermarkt Redirect (all TLDs to .com, www and non-www)
// @namespace    http://tampermonkey.net/
// @version      2.0
// @description  Redirect all transfermarkt.* domains (except .com) to transfermarkt.com as early as possible
// @match        https://transfermarkt.*/*
// @match        https://www.transfermarkt.*/*
// @run-at       document-start
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';
    // List of supported TLDs except .com
    const supportedTlds = [
        "de","ch","com.tr","fr","pl","at","com.ar","com.br","co","es","gr","co.in","jp","mx","pe","pt",
        "co.uk","be","co.id","it","co.kr","nl","ro","co.za","us","world"
    ];
    const host = location.hostname.replace(/^www\./, "");
    if (host === "transfermarkt.com") return;

    // Build regex for all supported TLDs
    const tldPattern = supportedTlds.map(tld => tld.replace('.', '\\.')).join('|');
    const regex = new RegExp(`^https://(www\\.)?transfermarkt\\.(${tldPattern})/`);

    if (regex.test(location.href)) {
        const newUrl = location.href.replace(regex, "https://www.transfermarkt.com/");
        window.location.replace(newUrl);
    }
})();