Google Search Filter By Language Separately

Google Search's language filter is painful to use for multi-language users. It only support filtering between All language, Your primary language, and all languages you know. So as an chinese user who also know english, google can only show english and chinese results together, I can not filter English content only.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name Google Search Filter By Language Separately
// @description Google Search's language filter is painful to use for multi-language users. It only support filtering between All language, Your primary language, and all languages you know. So as an chinese user who also know english, google can only show english and chinese results together, I can not filter English content only.
// @version 201903112
// @include https://www.google.com/*
// @grant none
// @namespace https://greasyfork.org/users/165728
// ==/UserScript==

(function() {
    function addNewLangFilters() {
        const langList = [
            ['lang_zh-CN', '中文 (简体)'],
            ['lang_ja', '日本語'],
            ['lang_en', 'English'],
        ]
        langList.reverse() 
        let langItems = document.querySelectorAll("ul.hdtbU")[0].querySelectorAll(".hdtbItm")
        let primaryLang = langItems[1]
        let search_qs = primaryLang.querySelector('a').href

        for (const [code, name] of langList) {
            let newLang = primaryLang.cloneNode(true)
            let newLink = newLang.querySelector('a')
            newLink.innerHTML = name
            let url = new URL(newLink.href)
            let qs = new URLSearchParams(url.search);
            qs.set('lr', code)
            url.search = qs.toString()
            newLink.href = url.href
            primaryLang.after(newLang)
        }
    }
    function enableSearchTools() {
        document.getElementById('hdtb-tls').click()
    }

    setTimeout(addNewLangFilters, 1000*3)
})();