Created
April 7, 2009 09:13
-
-
Save mgng/91156 to your computer and use it in GitHub Desktop.
Google翻訳APIで選択文字列を翻訳する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function trs(){ | |
google.load('language','1',{'callback':function(){ | |
var d=document,w=window,b=d.createElement('input'); | |
b.type='button'; | |
b.value='translate'; | |
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)+''; | |
if(s!='')google.language.translate(s,'en','ja',function(r){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=trs'; | |
document.body.appendChild(s) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment