Created
April 15, 2009 01:17
-
-
Save mgng/95532 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 _trsja_(){ | |
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='2em'; | |
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,'ja','en',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=_trsja_'; | |
document.body.appendChild(s) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment