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.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==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)
})();