You need to be logged in to post in the forums. If you do not have an account, please sign up first.
如何把google的网页翻译做成一个“按钮”?
Google的翻译网页: (英译中)http://translate.google.com/translate?u=%s&langpair=en%7Czh-CN&complete=1&hl=zh-CN&newwindow=1&ie=UTF-8&oe=UTF-8&prev=%2Flanguage_tools
如何把上面的代码做成个按钮,放在Opera的工具栏上,遇到英文网页点一下就会自动对当前网页进行翻译了!可以吗?
楼主试试这个JS,我忘记在哪里下的了:
// ==UserScript==
// @name Google Translation
// @author Ayush
// @version 1.0
// ==/UserScript==
// To use the script -
// Click the "<<" button(bottom-right) then select the text with mouse.
vrEnabled=false;
vrWidth='120pt' ; vrHeight= '40pt'; vrAutoDisappear=10
vrLangPairs={ 'French to English':'fr-en',
'Spanish to English':'es-en',
'Arabic to English':'ar-en',
'German to English':'de-en',
'Italian to English':'it-en',
'Russian to English':'ru-en',
'Portuguese to English':'pt-en',
'Korean to English':'ko-en',
'English to Korean':'en-ko',
'Japanese to English':'ja-en',
'English to Japanese':'en-ja',
'':'',
'Chinese to English':'zh-en',
'English to chinese*':'en-zh'
}
vrDisabledOn=['Button','Input','Select','IMG','Image','Map']
var vrsel,vrifr,vrlp,vrdv,vrfo
document.addEventListener("DOMContentLoaded",function(){
if(/google\..*\/translate_t\?.*?by=ayush.*/i.test(location))isGoog();if(top!=window)return;vrht=16
var vrdve=document.createElement("DIV"),vrbut=vrdve.appendChild(document.createElement("button"));vrsel=vrdve.appendChild(document.createElement("select"));
vrifr=document.createElement("iframe");vrifr.style="position:fixed;border:1px dashed gray;width:"+vrWidth+" !important;height:"+vrHeight+" !important;display:none !important";vrifr.src="opera:blank";
vrdve.style='position:fixed !important;z-index:88;bottom:0;right:0;height:'+vrht+'pt !important;background-color:#00aaff !important;max-width:160pt !important;opacity:0.70'
vrbut.style='font:9.1pt verdana;margin-right:1.5pt';vrbut.en=vrEnabled;vrTogg(vrbut);vrbut.addEventListener("click",vrTogg,false)
for(vrlng in vrLangPairs){vrcopt=new Option(vrlng,vrLangPairs[vrlng].replace('-','|'));vrsel.add(vrcopt);if(vrlng.slice(-1)=='*'){vrcopt.selected=1;vrcopt.text=vrlng.slice(0,-1);vrlp=vrLangPairs[vrlng]}};
vrsel.disabled=0;setTimeout(function(){vrsel.addEventListener("change",vrTogg,false);},1)
document.body.appendChild(vrdve);
},false)
vrcont=true;
function vropn(){
//vrifr.src='opera:blank'
vrrxp=new RegExp('^'+vrDisabledOn.join('|')+'$','i')
if(vrrxp.test(event.target.tagName))return
var vrselTxt=getSelection().toString()
if(vrifr && vrselTxt && vrcont){vrifrs=vrifr.style;
vrifrs.left=(+event.pageX-pageXOffset)+3;vrifrs.top=(+event.pageY-pageYOffset)+12;vrifrs.zIndex='90';
vrifr.src="http://google.com/translate_t?text="+vrselTxt+"&by=ayush&langpair="+vrsel.value
vrifrs.display='';vrifrs.opacity='0.8'
vrcont=false;vrsc=0
setTimeout(function(){vrcont=true},1200);
addEventListener("scroll",function(){vrcEf(1)},false)
vrfo=setTimeout(function(){vrcEf(5)},vrAutoDisappear*1000)
}else{
if(vrfo && vrifrs){clearTimeout(vrfo);vrcEf(1)}
}
}
function vrcEf(){if(event && event.type.toLowerCase()=='scroll' && vrsc)return;vrsc=1
var vrifrs=vrifr.style;
vrav=setInterval(function(){vrifrs.opacity-=0.1;if(+vrifrs.opacity<0.1){vrifrs.display='none';clearInterval(vrav);vrifr.src='opera:blank'}},arguments[0])
vrfo=0
removeEventListener("scroll",function(){vrcEf(1)},false)
}
function isGoog(){
var vrresb=document.getElementById("result_box");if(!vrresb)return;vrdb=document.body
vrdb.innerHTML=vrresb.textContent
vrdb.style.fontSize=11;vrdb.style.fontFamily="verdana"
}
function vrTogg(vrev){
var vrev=vrev.target||vrev
if(/button/i.test(vrev.tagName)){
var en=!vrev.en;vrev.en=en;vrev.innerHTML=en?'«':'»';vrsel.style.display=!en?'':'none'
if(!en && !vrev.ft){
if(vrev.ft===undefined)vrifr=document.body.appendChild(vrifr)
document.addEventListener("mouseup",vropn,false);vrev.ft=1
}else if(vrev.ft){vrifr.style.display='none';vrev.ft=0;document.removeEventListener("mouseup",vropn,false)}
}else if(/select/i.test(vrev)){
vrlp=vrev.value
}
}
-------------------------------
莊子云:泉涸,魚相與處於陸,相濡以沫,相掬以濕,不若相忘於江湖。
——
莊子云:泉涸,魚相與處於陸,相濡以沫,相掬以濕,不若相忘於江湖。
——
书签版
javascript:var t=((window.getSelection&&window.getSelection())||(document.getSelection&&document.getSelection())||(document.selection &&document.selection.createRange&&document.selection.createRange().text));var e=(document.charset||document.characterSet);if(t!=''){location.href='http://translate.google.com/translate_t?text=%27+t+%27&hl=zh-CN&langpair=en|zh-CN&tbb=1&ie='+e;}else{location.href='http://translate.google.com/translate?u=%27+escape(location.href)+%27&hl=zh-CN&langpair=en|zh-CN&tbb=1&ie='+e;};
按钮版
button
菜单版
javascript:var t=((window.getSelection&&window.getSelection())||(document.getSelection&&document.getSelection())||(document.selection &&document.selection.createRange&&document.selection.createRange().text));var e=(document.charset||document.characterSet);if(t!=''){location.href='http://translate.google.com/translate_t?text=%27+t+%27&hl=zh-CN&langpair=en|zh-CN&tbb=1&ie='+e;}else{location.href='http://translate.google.com/translate?u=%27+escape(location.href)+%27&hl=zh-CN&langpair=en|zh-CN&tbb=1&ie='+e;};
按钮版
button
菜单版
Item, "↓部分网页无法翻译→"="Go to page, "http://www.google.com/language_tools?hl=zh-CN",,,"google"" Item, "英语 >>简体"="Go to page, "http://translate.google.com/translate?u=%u&langpair=en|zh-CN&hl=zh-CN&newwindow=1&ie=UTF-8&oe=UTF-8&prev=.Flanguage_tools",,,"google"" Item, "德语 >>英语"="Go to page, "http://translate.google.com/translate?u=%u&langpair=de|en&hl=zh-CN&newwindow=1&ie=UTF-8&oe=UTF-8&prev=.Flanguage_tools",,,"google"" Item, "法语 >>英语"="Go to page, "http://translate.google.com/translate?u=%u&langpair=fr|en&hl=zh-CN&newwindow=1&ie=UTF-8&oe=UTF-8&prev=.Flanguage_tools",,,"google"" Item, "日语 >>英语"="Go to page, "http://translate.google.com/translate?u=%u&langpair=ja|en&hl=zh-CN&newwindow=1&ie=UTF-8&oe=UTF-8&prev=.Flanguage_tools",,,"google"" Item, "朝鲜语 >>英语"="Go to page, "http://translate.google.com/translate?u=%u&langpair=ko|en&hl=zh-CN&newwindow=1&ie=UTF-8&oe=UTF-8&prev=.Flanguage_tools",,,"google"" Item, "西班牙语>>英语"="Go to page, "http://translate.google.com/translate?u=%u&langpair=es|en&hl=zh-CN&newwindow=1&ie=UTF-8&oe=UTF-8&prev=.Flanguage_tools",,,"google"" Item, "意大利语>>英语"="Go to page, "http://translate.google.com/translate?u=%u&langpair=it|en&hl=zh-CN&newwindow=1&ie=UTF-8&oe=UTF-8&prev=.Flanguage_tools",,,"google"" Item, "葡萄牙语>>英语"="Go to page, "http://translate.google.com/translate?u=%u&langpair=pt|en&hl=zh-CN&newwindow=1&ie=UTF-8&oe=UTF-8&prev=.Flanguage_tools",,,"google"" Item, "阿拉伯语>>英语"="Go to page, "http://translate.google.com/translate?u=%u&langpair=ar|en&hl=zh-CN&newwindow=1&ie=UTF-8&oe=UTF-8&prev=.Flanguage_tools",,,"google"" Item, "简体中文>>英语"="GO to page, "http://translate.google.com/translate?u=%u&langpair=zh-CN|en&hl=zh-CN&newwindow=1&ie=UTF-8&oe=UTF-8&prev=.Flanguage_tools",,,"google""
Originally posted by wusehuatian:
你们都是怎么用的呀,教教我呀!我在线,wusehuatian@live.cn 教教我吧,实在没办法了
http://bbs.operachina.com/viewtopic.php?f=41&t=59511
Moderated by:
Langeline
Thruth
musiccow
markpoleon