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

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

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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);
    }
})();