Skip to content

Instantly share code, notes, and snippets.

@mgng
Created April 8, 2009 04:13
Show Gist options
  • Save mgng/91624 to your computer and use it in GitHub Desktop.
Save mgng/91624 to your computer and use it in GitHub Desktop.
Google翻訳APIを使った選択文字列翻訳ブックマークレット(英→日)
function _trsen_(){
google.load('language','1',{'callback':function(){
var d=document,w=window,b=d.createElement('input');
b.type='button';
b.value='英→日翻訳';
b.style.zIndex=99;
b.style.position='fixed';
b.style.top=0;
b.style.left='50%';
b.style.display='block';
b.onclick=function(){
var s=(w.getSelection?w.getSelection():d.selection.createRange().text)+'';
var n=function(f){b.disabled=f;b.value=(f)?'英→日翻訳中...':'英→日翻訳'};
if(s!=''){
n(true);
google.language.translate(s,'en','ja',function(r){n(false);alert(r.translation);});
}
};
d.body.insertBefore(b,d.body.firstChild)
}
})
};
(function(){
var s=document.createElement('script');
s.type='text/javascript';
s.src='http://www.google.com/jsapi?callback=_trsen_';
document.body.appendChild(s)
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment