Google の検索結果ページの言語を切り替えるユーザスクリプト


Google の検索結果を、日本語 <-> 英語でトグルさせるユーザスクリプトを書いた。
ロジックはこちらから拝借した。
検索結果ページをダブルクリックで、hl を en と ja でトグルさせる。

toggleLanguage.user.js

// ==UserScript==
// @name           Toggle Google results page language
// @namespace      http://kaihatsubu.com/
// @description    Japanese <-> English
// @include        http://*.google.*/search?*
// ==/UserScript==
(function() {
document.addEventListener('dblclick', function(e) {
//thanks to http://d.hatena.ne.jp/ymorimo/20070719/1184847240
var r=RegExp,l=location;
if (l.href.match(new r("(http://[^/]+\\.google\\.[^/]+/search)(\\?.+)"))) {
var u=r.$1,p=r.$2,q=(p.match(/[&\?]q=([^&]*)/))[1];
if (q) {
if (p.match(/[&\?]hl=([^&]*)/)) var hl=r.$1;
var nhl=(hl=="en"?"ja":"en");
l.href=u+"?q="+q+"&hl="+nhl+"&lr="+{"en":"","ja":"lang_ja"}[nhl];
}
}
}, true);
})();

Google で調べ物をする際、英語の検索結果だけ欲しいときに便利。

カテゴリー: Greasemonkey, JavaScript   パーマリンク

コメントをどうぞ

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

*

次のHTML タグと属性が使えます: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>