.test Domain Redirect

Automatically redirect .test domains from search results

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         .test Domain Redirect
// @version      1.0
// @description  Automatically redirect .test domains from search results
// @author       Ant-V
// @match        *://*/* 
// @run-at       document-start
// @namespace    antv
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // Get the current URL
    const currentURL = window.location.href;

    // Define a regular expression to detect .test domains, including possible paths or query strings
    const testDomainRegex = /^[a-z0-9.-]+\.test(\/.*)?$/i;

    // Check if the URL is a search engine result page (you can customize this part for your specific search engine)
    const searchQuery = new URLSearchParams(window.location.search).get('q');
    
    console.log(searchQuery)

    // If the search query looks like a .test domain
    if (searchQuery && testDomainRegex.test(searchQuery)) {
        const newURL = 'http://' + searchQuery;
        // Redirect to the correct .test domain with http
        window.location.href = newURL;
    }
})();