forked from NiaoBlush/GoogleResultLanguageSwitcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GoogleResultLanguageSwitcher.js
46 lines (38 loc) · 1.52 KB
/
GoogleResultLanguageSwitcher.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// ==UserScript==
// @name 临时更改谷歌搜索结果中英文
// @name Google Result Language Switcher
// @namespace https://github.com/NiaoBlush/GoogleResultLanguageSwitcher
// @version 1.1
// @description 将google结果切换为中文结果, 不改变Google界面语言
// @author NiaoBlush
// @license MIT
// @grant none
// @include https://www.google.com/search?*
// ==/UserScript==
(function () {
'use strict';
const urlParams = new URLSearchParams(window.location.search);
const currentLang = urlParams.get("lr") || "en";
const btnId = "btn-language-switcher";
let parent = document.getElementById("hdtb-tls").parentElement;
let className = parent.lastElementChild.className;
let button = document.createElement("a");
button.innerHTML = currentLang === 'en' ? "<font color=#5f6368>简体中文结果</font>" : "<font color=#5f6368>结果不限语言</font>";
button.className = className;
button.id = btnId;
button.onclick = () => reload();
parent.appendChild(button);
/**
* 重载页面
*/
function reload() {
document.getElementById(btnId).innerHTML = "<font color=#5f6368>正在重新加载</font>";
if (currentLang === 'lang_zh-CN') {
urlParams.delete("lr");
} else {
urlParams.append("lr", "lang_zh-CN")
}
const newUrl = `${location.origin}${location.pathname}?${urlParams.toString()}`;
location.href = newUrl;
}
})();