Greasy Fork 支持简体中文。

Google Search Result Toggle Chinese/English

Toggle the result language for Google searches

目前為 2021-07-06 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Google Search Result Toggle Chinese/English
// @namespace    http://tampermonkey.net/
// @version      1.5
// @description  Toggle the result language for Google searches
// @author       tgxhx
// @match        https://www.google.com/search*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    //return;
    const settingsBtn = document.querySelector('#hdtb-tls');
    const settingsBtnParent = settingsBtn.parentElement;
    const a = document.createElement('a');
    const query = new URLSearchParams(decodeURIComponent(location.search));
    const isChinese = (query.get('hl') || '').toLowerCase() === 'zh-cn';

    if (isChinese) {
        query.delete('hl');
        query.delete('lr');
        query.delete('tbs');
        a.textContent = 'English';
    } else {
        query.set('hl', 'zh-cn');
        query.set('lr', 'lang_zh-CN|lang_zh-TW');
        query.set('tbs', 'lr:lang_1zh-CN|lang_1zh-TW');
        a.textContent = 'Chinese';
    }

    const href = `${location.origin}${location.pathname}?${query.toString()}`;
    a.setAttribute('href', href);
    a.classList.add('t2vtad');
    a.style.cssText = 'margin-right: 0;'
    settingsBtnParent.insertBefore(a, settingsBtn);

    settingsBtn.addEventListener(
        'click',
        () =>
        setTimeout(
            () =>
            Object.assign(document.querySelector('.yyoM4d').style, {
                top: '97px',
            }),
            100
        ),
        false
    );
})();