Force Google Results in English

Automatically adds &hl=en to Google search URLs to force English results

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Force Google Results in English
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Automatically adds &hl=en to Google search URLs to force English results
// @author       You
// @match        *://www.google.com/*
// @match        *://google.com/*
// @match        *://www.google.co.*/*
// @match        *://google.co.*/*
// @match        *://www.google.com.au/*
// @match        *://www.google.ca/*
// @match        *://www.google.de/*
// @match        *://www.google.fr/*
// @match        *://www.google.es/*
// @match        *://www.google.it/*
// @match        *://www.google.jp/*
// @match        *://www.google.ru/*
// @match        *://www.google.br/*
// @match        *://www.google.in/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';
    
    // Run immediately to minimize any visible delay
    const enforceEnglishResults = () => {
        // Only proceed if this is a Google search page
        if (!window.location.href.includes('google.')) return;
        
        // Don't modify the URL if it already has the language parameter
        if (window.location.href.includes('&hl=en') || window.location.href.includes('?hl=en')) return;
        
        // Get the current URL
        let currentUrl = window.location.href;
        
        // Add the English language parameter
        if (currentUrl.includes('?')) {
            // URL already has parameters, append our parameter
            if (!currentUrl.endsWith('&')) {
                currentUrl += '&';
            }
            currentUrl += 'hl=en';
        } else {
            // URL doesn't have parameters yet, add our parameter as the first one
            currentUrl += '?hl=en';
        }
        
        // Update the URL without refreshing the page
        window.history.replaceState({}, document.title, currentUrl);
        
        // For cases where the page is still loading, also change the location
        // This provides a fallback but will cause a page refresh
        if (document.readyState !== 'complete') {
            window.location.href = currentUrl;
        }
    };
    
    // Run the function immediately
    enforceEnglishResults();
    
    // Monitor URL changes for single-page behavior
    let lastUrl = window.location.href;
    new MutationObserver(() => {
        if (lastUrl !== window.location.href) {
            lastUrl = window.location.href;
            enforceEnglishResults();
        }
    }).observe(document, {subtree: true, childList: true});
    
    // Add event listener for when the page is loaded
    window.addEventListener('load', enforceEnglishResults);
})();