Skip to content

Instantly share code, notes, and snippets.

@oogatta
Created May 4, 2010 06:14
Show Gist options
  • Save oogatta/389025 to your computer and use it in GitHub Desktop.
Save oogatta/389025 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Toggle Google results page language
// @namespace http://bitmap.dyndns.org/
// @description Japanese <-> English
// @include http://*.google.*/search?*
// ==/UserScript==
(function() {
window.__toggleGoogleLinkClickFlag = false;
document.addEventListener('mousedown', function(e) {
window.__toggleGoogleLinkClickFlag = ( e.target.tagName == 'A' );
}, false);
document.addEventListener('dblclick', function(e) {
if ( window.__toggleGoogleLinkClickFlag ) return;
//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];
}
}
}, false);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment