Auto Click "Change to English" on Google

Automatically clicks the "Change to English" link when it appears on Google.

// ==UserScript==
// @name         Auto Click "Change to English" on Google
// @description  Automatically clicks the "Change to English" link when it appears on Google.
// @match        *://www.google.com/*
// @run-at       document-idle
// @version 0.0.1.20250506075555
// @namespace https://greasyfork.org/users/1435046
// ==/UserScript==

(function() {
    'use strict';

    function clickChangeToEnglish() {
        const candidates = document.querySelectorAll('a[href*="/setprefs"]');
        const link = Array.from(candidates).find(
            a => a.textContent.trim() === "Change to English"
        );
        if (link) {
            link.click();
            observer.disconnect();  // no need to keep observing once we've clicked
        }
    }

    // Try once immediately
    clickChangeToEnglish();

    // Observe DOM for dynamically‑inserted links
    const observer = new MutationObserver(clickChangeToEnglish);
    observer.observe(document.body, { childList: true, subtree: true });
})();