改进一下 Google Search Language Select脚本

本文介绍了一款用于Google搜索页面的用户脚本,能够为用户提供更多语言选项以筛选搜索结果。该脚本通过简单的界面操作,允许用户快速切换搜索语言。
今天还真闲,看了下userscripts.
发现这个[url=http://greasefire.userscripts.org/scripts/show/49918] Google Search Language Select[/url] 还真不错,可以切换查询结果的语言

[img]http://10e.org/elup/img/elup2728.jpg[/img]
[img]http://10e.org/elup/img/elup2729.jpg[/img]

但是没有中文的菜单,手多给加了一个


// ==UserScript==
// @name Google Search Language Select
// @namespace Yamamaya
// @description You can select language options.
// @include http://www.google.*/search*
// @include http://www.google.*/webhp?*
// @version 0.0.2
// ==/UserScript==

(function(){
evalInPage(function(){
var GOOGLE = google;
var LANGUAGE = GOOGLE.kHL;

var googleSearch = {
init: function(){
this.createLanguageSelect();
this.launguageSelectToggle();
this.formSubmit();
},
createLanguageSelect: function(){
var language = (LANGUAGE === 'ja') && {
'英語': 'lang_en',
'スペイン語': 'lang_es',
'ポルトガル語': 'lang_pt',
'フランス語': 'lang_fr',
'イタリア語': 'lang_it',
'ドイツ語': 'lang_de',
'ロシア語': 'lang_ru',
'中国語 簡体': 'lang_zh-CN',
'中国語 繁体': 'lang_zh-TW',
'韓国語': 'lang_ko',
'日本語': 'lang_ja'
}
|| (LANGUAGE === 'zh-CN') && {
'英文': 'lang_en',
'西班牙文': 'lang_es',
'葡萄牙文': 'lang_pt',
'法文': 'lang_fr',
'意大利文': 'lang_it',
'德文': 'lang_de',
'俄文': 'lang_ru',
'简体中文': 'lang_zh-CN',
'繁体中文': 'lang_zh-TW',
'韩文': 'lang_ko',
'日文': 'lang_ja'
}
|| (LANGUAGE === 'zh-TW') && {
'英文': 'lang_en',
'西班牙文': 'lang_es',
'葡萄牙文': 'lang_pt',
'法文': 'lang_fr',
'意大利文': 'lang_it',
'德文': 'lang_de',
'俄文': 'lang_ru',
'簡體中文': 'lang_zh-CN',
'正體中文': 'lang_zh-TW',
'韓文': 'lang_ko',
'日文': 'lang_ja'
}
|| {
'English': 'lang_en',
'Spanish': 'lang_es',
'Portuguese': 'lang_pt',
'French': 'lang_fr',
'Italian': 'lang_it',
'German': 'lang_de',
'Russian': 'lang_ru',
'Chinese (Simplified)': 'lang_zh-CN',
'Chinese (Traditional)': 'lang_zh-TW',
'Korean': 'lang_ko',
'Japanese': 'lang_ja'
};

var point = document.getElementById('prs');
var a = document.createElement('a');
with(a.style){
margin = '0px 20px';
};
a.href = '#';
a.id = 'language_select_toggle';
a.textContent = 'Language Options';
point.appendChild(a);

var t = a.offsetTop + 5;
var l = a.offsetLeft;
var ul = document.createElement('ul');
ul.id = 'language_select_ul';
with(ul.style){
padding = '10px';
backgroundColor = '#3274D0';
position = 'absolute';
top = t + 'px';
left = l + 'px';
zIndex = '9999999';
visibility = 'hidden';
};
for(var i in language){
var li = document.createElement('li');
with(li.style){
listStyle = 'none';
margin = '5px 0px';
};
li.innerHTML = '<input type="radio" value="'+language[i]+'" name="lr"/><label for="lr" style="color: #FFFFFF !important;">'+i+'</label>';
ul.appendChild(li);
};
point = document.getElementsByName('btnG')[0];
point.parentNode.appendChild(ul);
},
launguageSelectToggle: function(){
var ul = document.getElementById('language_select_ul');
var uStyle = ul.style;
document.addEventListener('click',function(e){
var target = e.target;
if(e.button !== 0)
return;
if(target.parentNode.id === 'language_select_ul' || target.parentNode.parentNode.id === 'language_select_ul')
return;
if(target.id === 'language_select_toggle'){
(uStyle.visibility === 'hidden') ?
uStyle.visibility = 'visible': uStyle.visibility = 'hidden';
e.preventDefault();
}
else{
uStyle.visibility = 'hidden';
}
},false);
},
formSubmit: function(target){
var form = document.forms[0];
document.addEventListener('click',function(e){
if(e.button !== 0) return;
var target = e.target;
if(target.id === 'all' || target.id === 'il' || target.name === 'lr' && (target.nodeName.toLowerCase() === 'input')){
form.submit();
}
},false);
}
};

googleSearch.init();
});

function evalInPage(f){
location.href = 'javascript:void('+f+')()';
};
})();

直接覆盖上去吧, ff3.5.1下测试通过
Search Search v0.5.6 released 2020-02-24 (ti:"artificial intelligence" OR ti:"AI algorithm") AND submittedDate:[2020-01-01 TO 2024-12-31] AND language:en AND comment:"6 pages" OR comment:"7 pages" OR comment:"8 pages" All fields Show abstracts Hide abstracts Advanced Search Searching by Author Name Using the Author(s) field produces best results for author name searches. For the most precise name search, follow surname(s), forename(s) or surname(s), initial(s) pattern: example Hawking, S or Hawking, Stephen For best results on multiple author names, separate individuals with a ; (semicolon). Example: Jin, D S; Ye, J Author names enclosed in quotes will return only exact matches. For example, "Stephen Hawking" will not return matches for Stephen W. Hawking. Diacritic character variants are automatically searched in the Author(s) field. Queries with no punctuation will treat each term independently. Searching by subcategory To search within a subcategory select All fields. A subcategory search can be combined with an author or keyword search by clicking on add another term in advanced search. Tips Wildcards: Use ? to replace a single character or * to replace any number of characters. Can be used in any field, but not in the first character position. See Journal References tips for exceptions. Expressions: TeX expressions can be searched, enclosed in single $ characters. Phrases: Enclose phrases in double quotes for exact matches in title, abstract, and comments. Dates: Sorting by announcement date will use the year and month the original version (v1) of the paper was announced. Sorting by submission date will use the year, month and day the latest version of the paper was submitted. Journal References: If a journal reference search contains a wildcard, matches will be made using wildcard matching as expected. For example, math* will match math, maths, mathematics. If a journal reference search does not contain a wildcard, only exact phrases entered will be matched. For example, math would match math or math and science but not maths or mathematics. All journal reference searches that do not contain a wildcard are literal searches: a search for Physica A will match all papers with journal references containing Physica A, but a search for Physica A, 245 (1997) 181 will only return the paper with journal reference Physica A, 245 (1997) 181. About Help Contact Subscribe Copyright Privacy Policy Web Accessibility Assistance arXiv Operational Status Get status notifications via
最新发布
05-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值