Created
April 25, 2014 18:28
-
-
Save dergachev/11298816 to your computer and use it in GitHub Desktop.
This file contains 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
'use strict'; | |
window.addEventListener("DOMContentLoaded", SL_GOOGLE_WPT(), false); | |
document.addEventListener('mousedown',function(){SL_HideButton();},!1); | |
document.addEventListener('mouseup',function(e){QuickBubbleInit(e);},!1); | |
window.addEventListener("load", setTimeout('SL_Hider()',500), false); | |
var ARROWS =" »"; | |
var SL_BALLON_W = 350; | |
var SL_BALLON_H = 85; | |
var SL_MoveX="-1000px"; | |
var SL_MoveY="-1000px"; | |
var SL_Xdelta=0; | |
var SL_Ydelta=0; | |
var SL_FROMlng="en"; | |
var SL_TEMP_TEXT=""; | |
var SL_temp_result=""; | |
var SL_Balloon_translation_limit=8000; | |
var SL_PLANSHET_LIMIT = 8000; | |
var SL_GLOBAL_X1=0; | |
var SL_GLOBAL_X2=0; | |
var SL_GLOBAL_Y1=0; | |
var SL_GLOBAL_Y2=0; | |
var SL_TSold=0; | |
var SL_VirtualPIN=0; | |
var SL_DETECT="en"; | |
//-------------------Globals for TRANSFER from BBL to PLANSHET | |
var SL_TRANSFER_SRC="en"; | |
var SL_TRANSFER_DST="es"; | |
var SL_TRANSFER_DET="true"; | |
//-------------------Globals for TRANSFER from BBL to PLANSHET | |
//-------------------STORAGE | |
var SL_ENABLE=false; | |
var SL_OnOff_BTN; | |
var SL_OnOff_PIN; | |
var SL_langSrc; | |
var SL_langDst; | |
var SL_FontSize; | |
var SL_TH_2; | |
//-------------------STORAGE | |
//-------------------SESSION | |
var SL_SID_PIN=""; | |
var SL_SID_TO=""; | |
var SL_SID_FONT=""; | |
var SL_SID_TEMP_TARGET=""; | |
//-------------------SESSION | |
var SL_ListOfAvailableLanguages="af:Afrikaans,sq:Albanian,ar:Arabic,hy:Armenian,az:Azerbaijani,eu:Basque,bn:Bengali,be:Belarusian,bg:Bulgarian,ca:Catalan,zh-CN:Chinese (Simp),zh-TW:Chinese (Trad),hr:Croatian,cs:Czech,da:Danish,nl:Dutch,en:English,eo:Esperanto,et:Estonian,tl:Filipino,fi:Finnish,fr:French,gl:Galician,ka:Georgian,de:German,el:Greek,gu:Gujarati,ht:Haitian Creole,iw:Hebrew,hi:Hindi,hu:Hungarian,is:Icelandic,id:Indonesian,ga:Irish,it:Italian,ja:Japanese,kn:Kannada,ko:Korean,lo:Lao,la:Latin,lv:Latvian,lt:Lithuanian,mk:Macedonian,ms:Malay,mt:Maltese,no:Norwegian,fa:Persian,pl:Polish,pt:Portuguese,ro:Romanian,ru:Russian,sr:Serbian,sk:Slovak,sl:Slovenian,es:Spanish,sw:Swahili,sv:Swedish,ta:Tamil,te:Telugu,th:Thai,tr:Turkish,uk:Ukrainian,ur:Urdu,vi:Vietnamese,cy:Welsh,yi:Yiddish"; | |
//if (window.getSelection()) window.getSelection().removeAllRanges(); | |
(function(){ | |
var d=!0,e=null,g=!1,j, | |
k=function(a){return a.replace(/^\s+|\s+$/g,"")}, | |
o=function(a,b){return function(){return b.apply(a,arguments)} | |
}, | |
p=function(a){ | |
if(a&&a.tagName){ | |
var b=a.tagName.toLowerCase(); | |
if("input"==b||"textarea"==b)return d | |
} | |
for(;a;a=a.parentNode) | |
if(a.isContentEditable)return d;return g | |
}, | |
r=/[0-9A-Za-z]/, | |
A=function(){ | |
chrome.extension.sendRequest({type:"initialize"},o(this, | |
function(a){ | |
this.B=a.instanceId; | |
chrome.extension.onRequest.addListener(z); | |
} | |
) | |
)} | |
var x=function(a,b,c){ | |
document.addEventListener?c.addEventListener(a,b,g):c.attachEvent("on"+a,b) | |
}, | |
w=function(){}; | |
var z=function(a,b,c){ | |
"get_selection"==a.type&&(a=k(window.getSelection().toString()))&&c({selection:a})}; | |
window.SLInstance=new A; | |
chrome.extension.sendMessage({greeting: window.getSelection().toString()}, function(response) { | |
var newElem = document.createElement ("div"); | |
newElem.innerHTML = "<div id='SL_button' class='ImTranslatorLogo'></div><div id='SL_shadow_translation_result2'></div><div id='SL_shadow_translator'><div id='SL_planshet'><div id='SL_TB'><div class='ImTranslatorLogo'></div><table cellspacing='1' border='0' id='SL_tables'><tr><td class='SL_td' align='left' width='20%'><div id='SL_lng_from'>English"+ARROWS+"</div></td><td class='SL_td' align='left' width='20%'><div id='SL_to_'><div id='SL_tocurlng' style='margin-left:5px;'>Spanish</div><div class='SL_arrow'></div><div id='SL_to_list' style='display=\'none\'><div class='SL_DDMENU'>"+SL_LanguageBuilder2('es')+"</div></div></div><select id='SL_lng_to'>"+SL_LanguageBuilder('es')+"</select></td><td class='SL_td' width='13%' align='center'> </td><td class='SL_td' width='8%' align='center'><div id='SL_TTS_voice' title='Listen to the translation'></div></td><td class='SL_td' width='8%' align='center'><div class='SL_copy_hand' id='SL_copy' title='Select text'></div></td><td class='SL_td' width='8%' align='center'><div class='SL_font_off' id='SL_bbl_font' title='Font size'></div></td><td class='SL_td' width='8%' align='center'><a href='"+chrome.extension.getURL('history.html')+"' target='_blank'><div class='SL_TH' title='Translation history'></div></a></td><td class='SL_td' width='5%'></td><td class='SL_td' width='8%' align='right'><div class='SL_pin_off' id='SL_pin' title='Pin pup-up bubble'></div></td></tr></table></div></div><div id='SL_shadow_translation_result'></div><div id='SL_bbl_donate' title='Make a small contribution'></div><div id='SL_Balloon_options'><a href='"+chrome.extension.getURL('feedback.html')+"' class='SL_options' title='Feedback' target='_blank'>Feedback</a> : <a href='"+chrome.extension.getURL('history.html')+"' class='SL_options' title='Translation history' target='_blank'>History</a> : <a href='"+chrome.extension.getURL('options-bbl.html')+"' target='_blank' class='SL_options' title='Show options'>Options</a></div></div>"; | |
var container = document.body; | |
container.appendChild (newElem); | |
document.getElementById('SL_shadow_translation_result2').style.display="none"; | |
}); | |
} | |
)(); | |
function SL_Links(ob,todo){document.getElementById(ob).style.display=todo;} | |
function SL_Hider(){ | |
document.getElementById("SL_shadow_translator").style.display='none'; | |
} | |
function StartImTranslatorWindow(){ | |
var tmpSLstr = window.getSelection().toString(); | |
if(tmpSLstr=="") tmpSLstr=" "; | |
chrome.extension.sendMessage({greeting: tmpSLstr}, function(response) { | |
// console.log(response.farewell); | |
}); | |
} | |
function SL_rightclick() { | |
var rightclick; | |
var e = window.event; | |
if (e.which) rightclick = (e.which == 3); | |
else if (e.button) rightclick = (e.button == 2); | |
return(rightclick); | |
} | |
//---------------BUTTON | |
function SL_ShowButton(){ | |
if(SL_OnOff_BTN=="true"){ | |
if(document.getElementById("SL_shadow_translator").style.backgroundColor==''){ | |
if(SL_rightclick()==false){ | |
var theSLtext=window.getSelection().toString(); | |
if(theSLtext!=""){ | |
SL_CLOBALPosition(window.e,0); | |
document.getElementById("SL_shadow_translator").style.backgroundColor=""; | |
document.getElementById('SL_button').style.display="block"; | |
SL_GetButtonCurPosition(SL_GLOBAL_X1,SL_GLOBAL_Y1,SL_GLOBAL_X2,SL_GLOBAL_Y2); | |
} | |
} | |
} | |
} | |
} | |
function SL_HideButton(){ | |
var SLdivField=document.getElementById("SL_button"); | |
SL_addEvent(SLdivField, 'mouseover', SL_addButtonColor); | |
SL_addEvent(SLdivField, 'mouseout', SL_removeButtonColor); | |
if(SLdivField.style.opacity!="1"){ | |
SL_CLOBALPosition(window.e,1); | |
SLdivField.style.display="none"; | |
if(document.getElementById("SL_shadow_translator").style.display!="block") SL_addEvent(SLdivField, 'mousedown', SL_ShowBalloon); | |
else SL_CloseBalloon(); | |
} | |
} | |
function SL_addButtonColor() { | |
var SLdivField=document.getElementById("SL_button"); | |
SLdivField.style.opacity="1"; | |
} | |
function SL_removeButtonColor() { | |
var SLdivField=document.getElementById("SL_button"); | |
SLdivField.style.opacity="0.4"; | |
} | |
function SL_GetButtonCurPosition(X1,Y1,X2,Y2) { | |
var AVR_X=(X1+X2)/2; | |
var AVR_Y=(Y1+Y2)/2; | |
var PRESENT_Y=0; | |
var MAX_Y=0; | |
var MIN_Y=0; | |
if(Y1-Y2<0) {MIN_Y=Y1;MAX_Y=Y2;} | |
else {MIN_Y=Y2;MAX_Y=Y1;} | |
if(MIN_Y>document.body.scrollTop+30) PRESENT_Y=MIN_Y-30; | |
else PRESENT_Y=MAX_Y+10; | |
var SLdivField=document.getElementById("SL_button"); | |
// SL_MoveX=AVR_X+"px"; | |
// SL_MoveY=PRESENT_Y+"px"; | |
//--------Corrector----------------------- | |
var Y4use=Y1-30; | |
var X4use=X1-30; | |
if(Y4use<20)Y4use=0; | |
// if(document.body.offsetHeight<Y4use) Y4use=document.body.offsetHeight-50; | |
//--------Corrector----------------------- | |
SL_MoveY=Y4use+"px"; | |
SL_MoveX=X4use+"px"; | |
SLdivField.style.left=SL_MoveX; | |
SLdivField.style.top=SL_MoveY; | |
} | |
function SL_CLOBALPosition(e, state) { | |
var posx = 0; | |
var posy = 0; | |
if (!e) var e = window.event; | |
if (e.pageX || e.pageY) { | |
posx = e.pageX; | |
posy = e.pageY; | |
} | |
else if (e.clientX || e.clientY) { | |
posx = e.clientX + document.body.scrollLeft | |
+ document.documentElement.scrollLeft; | |
posy = e.clientY + document.body.scrollTop | |
+ document.documentElement.scrollTop; | |
} | |
// if(document.getElementById("SL_button").style.display=="none"){ | |
if(state==0){ | |
SL_GLOBAL_X1=posx; | |
SL_GLOBAL_Y1=posy; | |
}else{ | |
SL_GLOBAL_X2=posx; | |
SL_GLOBAL_Y2=posy; | |
} | |
// } | |
} | |
//---------------BUTTON | |
//---------------BALLOON | |
function SL_bring_UP(){ | |
this.onmousemove = function () {} | |
} | |
function SL_bring_DOWN(){ | |
} | |
function SL_ShowBalloon(){ | |
document.onmousemove = null; | |
var SLdivField=document.getElementById("SL_shadow_translator"); | |
var SLdivField2=document.getElementById("SL_button"); | |
SLdivField2.style.display="none"; | |
document.getElementById('SL_planshet').style.background="#F4F5F5 url('"+chrome.extension.getURL('img/util/bg2.png')+"')"; | |
document.getElementById('SL_shadow_translation_result').style.background="#FFF url('"+chrome.extension.getURL('img/util/bg.png')+"')"; | |
document.getElementById('SL_Balloon_options').style.background="#F4F5F5 url('"+chrome.extension.getURL('img/util/bg3.png')+"')"; | |
var SLselect=document.getElementById("SL_lng_to"); | |
if(SLdivField.style.display=="none"){ | |
SLselect.value=SL_langDst; | |
} | |
if(SLdivField.style.backgroundColor=="#FEFEFE"){ | |
if(SL_langSrc!="auto"){ | |
var LANGS = SL_ListOfAvailableLanguages.split(","); | |
for (var i=0;i<LANGS.length;i++){ | |
var templang=LANGS[i].split(":"); | |
if(SL_langSrc == templang[0]) {var resp = templang[1]+ARROWS; SL_FROMlng = templang[0];} | |
} | |
document.getElementById('SL_lng_from').innerHTML=resp; | |
}else{ | |
SL_FROMlng=SL_langSrc; | |
} | |
} | |
if(SLdivField.style.backgroundColor==""){ | |
SL_GetTransCurPosition(); | |
var theSLtext=window.getSelection().toString(); | |
if(theSLtext!=""){ | |
var sel = window.getSelection ? window.getSelection() : document.selection; | |
document.getElementById("SL_shadow_translation_result").innerHTML="<div id='SL_indicator'></div>"; | |
theSLtext=theSLtext.substring(0,SL_Balloon_translation_limit); | |
if(theSLtext.length>SL_Balloon_translation_limit) { | |
//SL_BIG_TRANSLATOR(theSLtext); | |
SL_addBalloonColor(); | |
SL_removeBalloonColor(); | |
document.onscroll=SL_FLOATER; | |
SL_VirtualPIN=1; | |
var OBJ=document.getElementById('SL_pin'); | |
OBJ.className="SL_pin_on"; | |
OBJ.title="Unpin pop-up bubble"; | |
// SL_BALLOON_TRANSLATION(theSLtext,evt,0); | |
SL_FLOATER(); | |
}else{ | |
var evt = window.event; | |
SLdivField.style.backgroundColor="#FEFEFE"; | |
if(SL_SID_PIN!="") SL_OnOff_PIN=SL_SID_PIN; | |
if(SL_OnOff_PIN=="false") document.getElementById('SL_pin').className='SL_pin_off'; | |
else document.getElementById('SL_pin').className='SL_pin_on'; | |
if(document.getElementById('SL_pin').className=='SL_pin_on'){SL_FLOATER();} | |
if(SL_SID_TEMP_TARGET!="")SLselect.value=SL_SID_TEMP_TARGET; | |
} | |
theSLtext=theSLtext.replace(/\n/ig,"@"); | |
DODetection(theSLtext); | |
SL_TEMP_TEXT=theSLtext; | |
setTimeout(function() { SL_BALLOON_TRANSLATION(theSLtext,evt,0); }, 750); | |
SL_addEvent(SLdivField, 'mouseup', SL_ShowBalloon); | |
SL_addEvent(SLdivField, 'mousedown', SL_CloseBalloon); | |
SL_addEvent(SLdivField, 'mouseover', SL_addBalloonColor); | |
SL_addEvent(SLdivField, 'mouseout', SL_removeBalloonColor); | |
SL_addEvent(SLselect, 'change', SL_retranslate); | |
SL_addEvent(SL_shadow_translation_result, 'mousedown', SL_bring_UP); | |
SL_addEvent(SL_shadow_translation_result2, 'mouseout', SL_bring_DOWN); | |
SL_addEvent(SL_lng_to, 'mouseover', SL_bring_DOWN); | |
SL_addEvent(SL_to_, 'click', SL_DIV); | |
SL_addEvent(SL_to_, 'mouseout', SL_DIV_OFF); | |
SL_addEvent(SL_to_list, 'mouseover', SL_DIV); | |
SL_addEvent(SL_to_list, 'mouseout', SL_DIV_OFF); | |
SL_addEvent(SL_af, 'click', SL_af_); | |
SL_addEvent(SL_sq, 'click', SL_sq_); | |
SL_addEvent(SL_ar, 'click', SL_ar_); | |
SL_addEvent(SL_hy, 'click', SL_hy_); | |
SL_addEvent(SL_az, 'click', SL_az_); | |
SL_addEvent(SL_eu, 'click', SL_eu_); | |
SL_addEvent(SL_bn, 'click', SL_bn_); | |
SL_addEvent(SL_be, 'click', SL_be_); | |
SL_addEvent(SL_bg, 'click', SL_bg_); | |
SL_addEvent(SL_ca, 'click', SL_ca_); | |
SL_addEvent(SL_zh_CN, 'click', SL_zh_CN_); | |
SL_addEvent(SL_zh_TW, 'click', SL_zh_TW_); | |
SL_addEvent(SL_hr, 'click', SL_hr_); | |
SL_addEvent(SL_cs, 'click', SL_cs_); | |
SL_addEvent(SL_da, 'click', SL_da_); | |
SL_addEvent(SL_nl, 'click', SL_nl_); | |
SL_addEvent(SL_en, 'click', SL_en_); | |
SL_addEvent(SL_eo, 'click', SL_eo_); | |
SL_addEvent(SL_et, 'click', SL_et_); | |
SL_addEvent(SL_tl, 'click', SL_tl_); | |
SL_addEvent(SL_fi, 'click', SL_fi_); | |
SL_addEvent(SL_fr, 'click', SL_fr_); | |
SL_addEvent(SL_gl, 'click', SL_gl_); | |
SL_addEvent(SL_ka, 'click', SL_ka_); | |
SL_addEvent(SL_de, 'click', SL_de_); | |
SL_addEvent(SL_el, 'click', SL_el_); | |
SL_addEvent(SL_gu, 'click', SL_gu_); | |
SL_addEvent(SL_ht, 'click', SL_ht_); | |
SL_addEvent(SL_iw, 'click', SL_iw_); | |
SL_addEvent(SL_hi, 'click', SL_hi_); | |
SL_addEvent(SL_hu, 'click', SL_hu_); | |
SL_addEvent(SL_is, 'click', SL_is_); | |
SL_addEvent(SL_id, 'click', SL_id_); | |
SL_addEvent(SL_ga, 'click', SL_ga_); | |
SL_addEvent(SL_it, 'click', SL_it_); | |
SL_addEvent(SL_ja, 'click', SL_ja_); | |
SL_addEvent(SL_kn, 'click', SL_kn_); | |
SL_addEvent(SL_ko, 'click', SL_ko_); | |
SL_addEvent(SL_lo, 'click', SL_lo_); | |
SL_addEvent(SL_la, 'click', SL_la_); | |
SL_addEvent(SL_lv, 'click', SL_lv_); | |
SL_addEvent(SL_lt, 'click', SL_lt_); | |
SL_addEvent(SL_mk, 'click', SL_mk_); | |
SL_addEvent(SL_ms, 'click', SL_ms_); | |
SL_addEvent(SL_mt, 'click', SL_mt_); | |
SL_addEvent(SL_no, 'click', SL_no_); | |
SL_addEvent(SL_fa, 'click', SL_fa_); | |
SL_addEvent(SL_pl, 'click', SL_pl_); | |
SL_addEvent(SL_pt, 'click', SL_pt_); | |
SL_addEvent(SL_ro, 'click', SL_ro_); | |
SL_addEvent(SL_ru, 'click', SL_ru_); | |
SL_addEvent(SL_sr, 'click', SL_sr_); | |
SL_addEvent(SL_sk, 'click', SL_sk_); | |
SL_addEvent(SL_sl, 'click', SL_sl_); | |
SL_addEvent(SL_es, 'click', SL_es_); | |
SL_addEvent(SL_sw, 'click', SL_sw_); | |
SL_addEvent(SL_sv, 'click', SL_sv_); | |
SL_addEvent(SL_ta, 'click', SL_ta_); | |
SL_addEvent(SL_te, 'click', SL_te_); | |
SL_addEvent(SL_th, 'click', SL_th_); | |
SL_addEvent(SL_tr, 'click', SL_tr_); | |
SL_addEvent(SL_uk, 'click', SL_uk_); | |
SL_addEvent(SL_ur, 'click', SL_ur_); | |
SL_addEvent(SL_vi, 'click', SL_vi_); | |
SL_addEvent(SL_cy, 'click', SL_cy_); | |
SL_addEvent(SL_yi, 'click', SL_yi_); | |
SL_addEvent(SL_bbl_donate, 'click', SL_Donate); | |
SL_addEvent(SL_TTS_voice, 'click', SL_Voice); | |
SL_addEvent(SL_copy, 'click', SL_CopyToClipBoard); | |
SL_addEvent(SL_bbl_font, 'click', SL_Font); | |
SL_addEvent(SL_pin, 'click', SL_pinme); | |
document.onscroll=SL_FLOATER; | |
SL_addBalloonColor(); | |
SL_removeBalloonColor(); | |
setTimeout(function() { | |
document.getElementById("SL_button").style.display="none"; | |
}, 10); | |
} | |
} | |
var OBJ=document.getElementById('SL_shadow_translation_result'); | |
var OBJ2=document.getElementById('SL_shadow_translation_result2'); | |
var OBJ3=document.getElementById('SL_bbl_font'); | |
if(SL_SID_FONT!="") SL_FontSize=SL_SID_FONT; | |
if(SL_FontSize!=OBJ.style.fontSize){ | |
if(SL_FontSize=="15px"){ | |
OBJ.style.fontSize="15px"; | |
OBJ.style.lineHeight="17px"; | |
OBJ2.style.fontSize="15px"; | |
OBJ2.style.lineHeight="17px"; | |
}else{ | |
OBJ.style.fontSize="11px"; | |
OBJ.style.lineHeight="13px"; | |
OBJ2.style.fontSize="11px"; | |
OBJ2.style.lineHeight="13px"; | |
} | |
SL_FontSize=OBJ.style.fontSize; | |
}else{ | |
if(SL_FontSize=="15px" && OBJ3.className=="SL_font_off") OBJ3.className="SL_font_on"; | |
if(SL_FontSize=="11px" && OBJ3.className=="SL_font_off") OBJ3.className="SL_font_off"; | |
} | |
setTimeout(function() { | |
SLdivField2.style.display="none"; | |
}, 300); | |
} | |
/* | |
function SL_LTR_(){ | |
var SL_LTR = document.getElementById('SL_lng_to').value; | |
if(SL_LTR=="ar" || SL_LTR=="iw" || SL_LTR=="fa" || SL_LTR=="ur" || SL_LTR=="yi"){ | |
document.getElementById('SL_shadow_translation_result').style.direction="rtl"; | |
document.getElementById('SL_shadow_translation_result').style.textAlign="right"; | |
} | |
} | |
*/ | |
function SL_SYN(ob){ | |
document.getElementById('SL_tocurlng').innerHTML=ob.options[ob.selectedIndex].text; | |
SL_retranslate(); | |
setTimeout('SL_Links("SL_to_list","none")',900); | |
} | |
function SL_af_(){ var ob=document.getElementById('SL_lng_to');ob.value='af'; SL_SYN(ob); } | |
function SL_sq_(){ var ob=document.getElementById('SL_lng_to');ob.value='sq'; SL_SYN(ob); } | |
function SL_ar_(){ var ob=document.getElementById('SL_lng_to');ob.value='ar'; SL_SYN(ob); } | |
function SL_hy_(){ var ob=document.getElementById('SL_lng_to');ob.value='hy'; SL_SYN(ob); } | |
function SL_az_(){ var ob=document.getElementById('SL_lng_to');ob.value='az'; SL_SYN(ob); } | |
function SL_eu_(){ var ob=document.getElementById('SL_lng_to');ob.value='eu'; SL_SYN(ob); } | |
function SL_bn_(){ var ob=document.getElementById('SL_lng_to');ob.value='bn'; SL_SYN(ob); } | |
function SL_be_(){ var ob=document.getElementById('SL_lng_to');ob.value='be'; SL_SYN(ob); } | |
function SL_bg_(){ var ob=document.getElementById('SL_lng_to');ob.value='bg'; SL_SYN(ob); } | |
function SL_ca_(){ var ob=document.getElementById('SL_lng_to');ob.value='ca'; SL_SYN(ob); } | |
function SL_zh_CN_(){ var ob=document.getElementById('SL_lng_to');ob.value='zh-CN'; SL_SYN(ob); } | |
function SL_zh_TW_(){ var ob=document.getElementById('SL_lng_to');ob.value='zh-TW'; SL_SYN(ob); } | |
function SL_hr_(){ var ob=document.getElementById('SL_lng_to');ob.value='hr'; SL_SYN(ob); } | |
function SL_cs_(){ var ob=document.getElementById('SL_lng_to');ob.value='cs'; SL_SYN(ob); } | |
function SL_da_(){ var ob=document.getElementById('SL_lng_to');ob.value='da'; SL_SYN(ob); } | |
function SL_nl_(){ var ob=document.getElementById('SL_lng_to');ob.value='nl'; SL_SYN(ob); } | |
function SL_en_(){ var ob=document.getElementById('SL_lng_to');ob.value='en'; SL_SYN(ob); } | |
function SL_eo_(){ var ob=document.getElementById('SL_lng_to');ob.value='eo'; SL_SYN(ob); } | |
function SL_et_(){ var ob=document.getElementById('SL_lng_to');ob.value='et'; SL_SYN(ob); } | |
function SL_tl_(){ var ob=document.getElementById('SL_lng_to');ob.value='tl'; SL_SYN(ob); } | |
function SL_fi_(){ var ob=document.getElementById('SL_lng_to');ob.value='fi'; SL_SYN(ob); } | |
function SL_fr_(){ var ob=document.getElementById('SL_lng_to');ob.value='fr'; SL_SYN(ob); } | |
function SL_gl_(){ var ob=document.getElementById('SL_lng_to');ob.value='gl'; SL_SYN(ob); } | |
function SL_ka_(){ var ob=document.getElementById('SL_lng_to');ob.value='ka'; SL_SYN(ob); } | |
function SL_de_(){ var ob=document.getElementById('SL_lng_to');ob.value='de'; SL_SYN(ob); } | |
function SL_el_(){ var ob=document.getElementById('SL_lng_to');ob.value='el'; SL_SYN(ob); } | |
function SL_gu_(){ var ob=document.getElementById('SL_lng_to');ob.value='gu'; SL_SYN(ob); } | |
function SL_ht_(){ var ob=document.getElementById('SL_lng_to');ob.value='ht'; SL_SYN(ob); } | |
function SL_iw_(){ var ob=document.getElementById('SL_lng_to');ob.value='iw'; SL_SYN(ob); } | |
function SL_hi_(){ var ob=document.getElementById('SL_lng_to');ob.value='hi'; SL_SYN(ob); } | |
function SL_hu_(){ var ob=document.getElementById('SL_lng_to');ob.value='hu'; SL_SYN(ob); } | |
function SL_is_(){ var ob=document.getElementById('SL_lng_to');ob.value='is'; SL_SYN(ob); } | |
function SL_id_(){ var ob=document.getElementById('SL_lng_to');ob.value='id'; SL_SYN(ob); } | |
function SL_ga_(){ var ob=document.getElementById('SL_lng_to');ob.value='ga'; SL_SYN(ob); } | |
function SL_it_(){ var ob=document.getElementById('SL_lng_to');ob.value='it'; SL_SYN(ob); } | |
function SL_ja_(){ var ob=document.getElementById('SL_lng_to');ob.value='ja'; SL_SYN(ob); } | |
function SL_kn_(){ var ob=document.getElementById('SL_lng_to');ob.value='kn'; SL_SYN(ob); } | |
function SL_ko_(){ var ob=document.getElementById('SL_lng_to');ob.value='ko'; SL_SYN(ob); } | |
function SL_lo_(){ var ob=document.getElementById('SL_lng_to');ob.value='lo'; SL_SYN(ob); } | |
function SL_la_(){ var ob=document.getElementById('SL_lng_to');ob.value='la'; SL_SYN(ob); } | |
function SL_lv_(){ var ob=document.getElementById('SL_lng_to');ob.value='lv'; SL_SYN(ob); } | |
function SL_lt_(){ var ob=document.getElementById('SL_lng_to');ob.value='lt'; SL_SYN(ob); } | |
function SL_mk_(){ var ob=document.getElementById('SL_lng_to');ob.value='mk'; SL_SYN(ob); } | |
function SL_ms_(){ var ob=document.getElementById('SL_lng_to');ob.value='ms'; SL_SYN(ob); } | |
function SL_mt_(){ var ob=document.getElementById('SL_lng_to');ob.value='mt'; SL_SYN(ob); } | |
function SL_no_(){ var ob=document.getElementById('SL_lng_to');ob.value='no'; SL_SYN(ob); } | |
function SL_fa_(){ var ob=document.getElementById('SL_lng_to');ob.value='fa'; SL_SYN(ob); } | |
function SL_pl_(){ var ob=document.getElementById('SL_lng_to');ob.value='pl'; SL_SYN(ob); } | |
function SL_pt_(){ var ob=document.getElementById('SL_lng_to');ob.value='pt'; SL_SYN(ob); } | |
function SL_ro_(){ var ob=document.getElementById('SL_lng_to');ob.value='ro'; SL_SYN(ob); } | |
function SL_ru_(){ var ob=document.getElementById('SL_lng_to');ob.value='ru'; SL_SYN(ob); } | |
function SL_sr_(){ var ob=document.getElementById('SL_lng_to');ob.value='sr'; SL_SYN(ob); } | |
function SL_sk_(){ var ob=document.getElementById('SL_lng_to');ob.value='sk'; SL_SYN(ob); } | |
function SL_sl_(){ var ob=document.getElementById('SL_lng_to');ob.value='sl'; SL_SYN(ob); } | |
function SL_es_(){ var ob=document.getElementById('SL_lng_to');ob.value='es'; SL_SYN(ob); } | |
function SL_sw_(){ var ob=document.getElementById('SL_lng_to');ob.value='sw'; SL_SYN(ob); } | |
function SL_sv_(){ var ob=document.getElementById('SL_lng_to');ob.value='sv'; SL_SYN(ob); } | |
function SL_ta_(){ var ob=document.getElementById('SL_lng_to');ob.value='ta'; SL_SYN(ob); } | |
function SL_te_(){ var ob=document.getElementById('SL_lng_to');ob.value='te'; SL_SYN(ob); } | |
function SL_th_(){ var ob=document.getElementById('SL_lng_to');ob.value='th'; SL_SYN(ob); } | |
function SL_tr_(){ var ob=document.getElementById('SL_lng_to');ob.value='tr'; SL_SYN(ob); } | |
function SL_uk_(){ var ob=document.getElementById('SL_lng_to');ob.value='uk'; SL_SYN(ob); } | |
function SL_ur_(){ var ob=document.getElementById('SL_lng_to');ob.value='ur'; SL_SYN(ob); } | |
function SL_vi_(){ var ob=document.getElementById('SL_lng_to');ob.value='vi'; SL_SYN(ob); } | |
function SL_cy_(){ var ob=document.getElementById('SL_lng_to');ob.value='cy'; SL_SYN(ob); } | |
function SL_yi_(){ var ob=document.getElementById('SL_lng_to');ob.value='yi'; SL_SYN(ob); } | |
function SL_DIV(){ | |
SL_Links('SL_to_list','block'); | |
} | |
function SL_DIV_OFF(){ | |
SL_Links('SL_to_list','none'); | |
} | |
function SL_LanguageBuilder2(lng){ | |
var TEMPlng1=SL_ListOfAvailableLanguages.split(","); | |
var TEMPlng2; | |
var COLLECTOR=""; | |
var ACTIVE; | |
for(var i=0; i<TEMPlng1.length; i++){ | |
TEMPlng2=TEMPlng1[i].split(":"); | |
if(TEMPlng2[0] == "zh-CN")TEMPlng2[0]="zh_CN"; | |
if(TEMPlng2[0] == "zh-TW")TEMPlng2[0]="zh_TW"; | |
COLLECTOR=COLLECTOR+"<div id=\"SL_"+TEMPlng2[0]+"\" class='SL_limenu'>"+TEMPlng2[1]+"</div>"; | |
} | |
return COLLECTOR; | |
} | |
function SL_ALIGN(COORD){ | |
var theMainOBJ=document.getElementById('SL_shadow_translator'); | |
var RESP=0; | |
if(COORD=="x"){ | |
RESP=SL_BALLON_W/2; | |
var theX = (SL_GLOBAL_X1+SL_GLOBAL_X2)/2; | |
RESP = Math.ceil(theX - RESP); | |
if(RESP<0) RESP=5; | |
if(RESP>document.body.clientWidth-SL_BALLON_W-5) RESP=document.body.clientWidth-SL_BALLON_W-5; | |
if(document.body.scrollLeft>0)RESP=RESP+document.body.scrollLeft; | |
}else{ | |
var MIN = SL_GLOBAL_Y1; | |
var MAX = SL_GLOBAL_Y2; | |
if(MIN>SL_GLOBAL_Y2){MIN=SL_GLOBAL_Y2;MAX=SL_GLOBAL_Y1;} | |
if((MIN - document.body.scrollTop) > SL_BALLON_H) RESP=MIN-SL_BALLON_H-5; | |
else RESP=MAX+5; | |
if(RESP<0) RESP=5; | |
/* | |
var AVR = MAX-MIN; | |
if(AVR>=document.body.clientHeight-100){ | |
SL_VirtualPIN=1; | |
RESP=-1; | |
}else{ | |
SL_VirtualPIN=0; | |
} | |
*/ | |
} | |
return RESP; | |
} | |
function SL_bring_UP(){ | |
if(window.event.which!=3){ | |
var theMainOBJ=document.getElementById('SL_shadow_translator'); | |
var theOBJ=document.getElementById('SL_shadow_translation_result'); | |
var theOBJ2=document.getElementById('SL_shadow_translation_result2'); | |
theOBJ2.style.display='block'; | |
theOBJ2.style.marginTop=theMainOBJ.offsetTop+30+"px"; | |
theOBJ2.style.marginLeft=theMainOBJ.offsetLeft+1+"px"; | |
theOBJ.style.visibility="hidden"; | |
theOBJ2.innerHTML=SL_temp_result; | |
} | |
} | |
function SL_bring_DOWN(){ | |
var theOBJ=document.getElementById('SL_shadow_translation_result'); | |
var theOBJ2=document.getElementById('SL_shadow_translation_result2'); | |
theOBJ2.style.display='none'; | |
theOBJ.style.visibility="visible"; | |
} | |
function SL_retranslate(){ | |
var theSLtext=window.getSelection().toString(); | |
if(theSLtext=="") theSLtext=SL_TEMP_TEXT; | |
theSLtext=theSLtext.replace(/\n/ig,"@"); | |
SL_BALLOON_TRANSLATION(theSLtext,window.event,1); | |
} | |
function SL_CloseBalloon() { | |
var SLdivField=document.getElementById("SL_shadow_translator"); | |
if(document.getElementById('SL_shadow_translation_result2').style.display=="none"){ | |
SL_Xdelta = window.event.pageX - SLdivField.offsetLeft; | |
SL_Ydelta = window.event.pageY - SLdivField.offsetTop; | |
SL_addEvent(SLdivField, 'mouseover', SL_addBalloonColor); | |
SL_addEvent(SLdivField, 'mouseout', SL_removeBalloonColor); | |
if(SLdivField.style.backgroundColor==""){ | |
SLdivField.style.display='none'; | |
}else{ | |
var evt = window.event; | |
SL_MoveX=evt.pageX+"px"; | |
SL_MoveY=evt.pageY+"px"; | |
document.onmousemove = SL_GetTransCurPosition; | |
} | |
} | |
// SL_GLOBAL_X1 = window.event.pageX; | |
// SL_GLOBAL_Y1 = window.event.pageY; | |
} | |
function SL_addBalloonColor() { | |
var SLdivField=document.getElementById("SL_shadow_translator"); | |
SLdivField.style.backgroundColor="#FEFEFE"; | |
SLdivField.style.boxShadow="5px 5px 55px #000"; | |
} | |
function SL_removeBalloonColor() { | |
var SLdivField=document.getElementById("SL_shadow_translator"); | |
SLdivField.style.backgroundColor=""; | |
SLdivField.style.boxShadow="5px 5px 15px #BAB9B5"; | |
} | |
function SL_addEvent( obj, type, fn ) { | |
if ( obj.attachEvent ) { | |
obj['e'+type+fn] = fn; | |
obj[type+fn] = function(){obj['e'+type+fn]( window.event );} | |
obj.attachEvent( 'on'+type, obj[type+fn] ); | |
} else obj.addEventListener(type, fn, false); | |
} | |
function SL_GetTransCurPosition(e) { | |
var posx = 0; | |
var posy = 0; | |
if (!e) var e = window.event; | |
if (e.pageX || e.pageY) { | |
posx = e.pageX; | |
posy = e.pageY; | |
} | |
else if (e.clientX || e.clientY) { | |
posx = e.clientX + document.body.scrollLeft | |
+ document.documentElement.scrollLeft; | |
posy = e.clientY + document.body.scrollTop | |
+ document.documentElement.scrollTop; | |
} | |
var SLdivField=document.getElementById("SL_shadow_translator"); | |
if(SL_SID_PIN=="false"){ | |
var DELTA = 0; | |
if (document.body.scrollHeight > document.body.clientHeight) DELTA = 25; | |
if(posx-SL_Xdelta>1 && posx-SL_Xdelta<window.innerWidth-SL_BALLON_W-DELTA) SL_MoveX=posx-SL_Xdelta+"px"; | |
// if(posy-SL_Ydelta>1 && posy-SL_Ydelta<window.innerHeight-SL_BALLON_H) SL_MoveY=posy-SL_Ydelta+"px"; | |
SL_MoveY=posy-SL_Ydelta+"px"; | |
SLdivField.style.left=SL_MoveX; | |
SLdivField.style.top=SL_MoveY; | |
}else{ | |
SL_MoveX=posx-SL_Xdelta+"px"; | |
SL_MoveY=posy-SL_Ydelta+"px"; | |
SLdivField.style.left=SL_MoveX; | |
SLdivField.style.top=SL_MoveY; | |
} | |
} | |
function QuickBubbleInit(e){ | |
if(SL_ENABLE == "true"){ | |
var theSLtext=""; | |
if(e.shiftKey || e.ctrlKey || e.altKey){ | |
var SL_AUTOKEY=e.altKey; | |
switch(SL_HK){ | |
case "Shift": SL_AUTOKEY=e.shiftKey; break; | |
case "Ctrl": SL_AUTOKEY=e.ctrlKey; break; | |
case "Alt": SL_AUTOKEY=e.altKey; break; | |
} | |
theSLtext=window.getSelection().toString(); | |
if(theSLtext!=""){ | |
if(SL_OnOff_HK=="true" && SL_AUTOKEY){ | |
SL_ShowBalloon(); | |
} | |
} | |
} else{ | |
theSLtext=window.getSelection().toString(); | |
if(theSLtext!=""){ | |
if(SL_OnOff_BTN=="false" && SL_OnOff_HK=="true" && SL_HK=="None"){ | |
SL_ShowBalloon(); | |
} else SL_ShowButton(); | |
} | |
} | |
} | |
setTimeout('document.getElementById("SL_tocurlng").innerHTML=document.getElementById("SL_lng_to").options[document.getElementById("SL_lng_to").selectedIndex].text',500); | |
} | |
//---------------BALLOON | |
function SL_LanguageBuilder(lng){ | |
var TEMPlng1=SL_ListOfAvailableLanguages.split(","); | |
var TEMPlng2; | |
var COLLECTOR=""; | |
var ACTIVE; | |
for(var i=0; i<TEMPlng1.length; i++){ | |
TEMPlng2=TEMPlng1[i].split(":"); | |
ACTIVE=""; | |
if(TEMPlng2[0]==lng) ACTIVE=" selected "; | |
COLLECTOR=COLLECTOR+"<option "+ACTIVE+" value='"+TEMPlng2[0]+"'>"+TEMPlng2[1]+"</option>"; | |
} | |
return COLLECTOR; | |
} | |
function SL_BIG_TRANSLATOR(s){ | |
// if(myWindow)myWindow.close(); | |
s=s.substring(0,SL_PLANSHET_LIMIT); | |
s=escape(s); | |
s=s.replace(/%A0/g,"\n"); | |
s=unescape(s); | |
if(s!=""){ | |
if(SL_TS==SL_TSold){ | |
var mySourceLang = SL_langSrc; | |
if(SL_NODETECT_bbl=="true") mySourceLang = SL_FROMlng; | |
var myTargetLang = SL_langDst; | |
if(SL_SID_TEMP_TARGET!="")myTargetLang = SL_SID_TEMP_TARGET; | |
}else{ | |
mySourceLang=SL_langSrc; | |
myTargetLang=SL_langDst; | |
} | |
SL_TRANSFER_SRC=mySourceLang; | |
SL_TRANSFER_DST=myTargetLang; | |
SL_TRANSFER_DET=SL_NODETECT_bbl; | |
var CGI= SL_TRANSFER_SRC+":"+SL_TRANSFER_DST+":"+SL_TRANSFER_DET; | |
// alert(CGI); | |
var location = chrome.extension.getURL('translator.html')+"?txt="+s+"&lng="+ CGI; | |
var winWidth = 480 ; | |
var winHeight = 645 ; | |
var posLeft = ( screen.width - winWidth ) / 2 ; | |
var posTop = ( screen.height - winHeight ) / 2 ; | |
var myWindow = window.open(location,'ImTranslator','width=' + winWidth + ',height=' + winHeight +',top=' + posTop + ',left=' + posLeft + ',resizable=no,scrollbars=no,toolbar=no,titlebar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no'); | |
} | |
} | |
function DODetection(myTransText) { | |
var AUTO = SL_langSrc; | |
if(SL_NODETECT_bbl=="true") AUTO="auto"; | |
if(AUTO=="auto"){ | |
if(myTransText!=""){ | |
var baseUrl = 'http://' + 'translate.google.com/translate_a/t?client=drive&sl=auto&tl=en&multires=1&otf=2&ssel=0&tsel=0¬lr=0&sc=1&text='+encodeURIComponent(truncStrByWord(myTransText,100)); | |
var ajaxRequest; | |
try{ | |
ajaxRequest = new XMLHttpRequest(); | |
} catch (e){ | |
try{ | |
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); | |
} catch (e) { | |
try{ | |
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); | |
} catch (e){ | |
alert("Your browser broke"); | |
return false; | |
} | |
} | |
} | |
ajaxRequest.onreadystatechange = function(){ | |
if(ajaxRequest.readyState == 4){ | |
var resp = ajaxRequest.responseText; | |
var GDImTranslator_lang=decodeURIComponent(resp); | |
var GDImTranslator_lang1=GDImTranslator_lang.split('"src":"'); | |
var GDImTranslator_lang2=GDImTranslator_lang1[1].split('"'); | |
resp=GDImTranslator_lang2[0]; | |
var DetLang = resp; | |
var templang; | |
var thetemp; | |
if(SL_TS!=SL_TSold){ | |
var OLDs=SL_langSrc; | |
var OLDt=SL_langDst; | |
document.getElementById('SL_lng_to').value=OLDt; | |
}else{ | |
var OLDs=SL_langSrc; | |
SL_langSrc=OLDs; | |
var OLDt=document.getElementById('SL_lng_to').value; | |
SL_langDst=OLDt; | |
} | |
if(resp=="zh-CN"){ | |
DOSLDetection(myTransText); | |
setTimeout(function() { | |
DetLang = SL_DETECT; | |
if(thetemp=="auto" || resp!=thetemp){ | |
var LANGS = SL_ListOfAvailableLanguages.split(","); | |
for (var i=0;i<LANGS.length;i++){ | |
templang=LANGS[i].split(":"); | |
if(SL_DETECT == templang[0]){ resp = templang[1]; SL_FROMlng = templang[0];} | |
} | |
document.getElementById('SL_lng_from').innerHTML=resp+ARROWS; | |
if(OLDs=="auto" || SL_FROMlng!=OLDt){ | |
document.getElementById('SL_lng_to').value=OLDt; | |
} else { | |
if(SL_FROMlng==OLDt){ | |
document.getElementById('SL_lng_to').value=OLDs; | |
SL_langSrc=OLDt; | |
SL_langDst=OLDs; | |
} | |
} | |
} | |
return false; | |
}, 150); | |
} | |
if(thetemp=="auto" || resp!=thetemp){ | |
DetLang = resp; | |
var LANGS = SL_ListOfAvailableLanguages.split(","); | |
for (var i=0;i<LANGS.length;i++){ | |
templang=LANGS[i].split(":"); | |
if(resp == templang[0]){ resp = templang[1]; SL_FROMlng = templang[0];} | |
} | |
document.getElementById('SL_lng_from').innerHTML=resp+ARROWS; | |
if(OLDs=="auto" || SL_FROMlng!=OLDt){ | |
document.getElementById('SL_lng_to').value=OLDt; | |
} else { | |
if(SL_FROMlng==OLDt){ | |
document.getElementById('SL_lng_to').value=OLDs; | |
SL_langSrc=OLDt; | |
SL_langDst=OLDs; | |
} | |
} | |
} | |
} | |
} | |
ajaxRequest.open("POST", baseUrl, true); | |
ajaxRequest.send(null); | |
} | |
} | |
} | |
function SL_getLNG(name,st) { | |
var LANGS = SL_ListOfAvailableLanguages.split(","); | |
var resp1="en"; | |
var resp2="es"; | |
for (var i=0;i<LANGS.length;i++){ | |
var templang=LANGS[i].split(":"); | |
if(name == templang[0]){ resp1 = templang[1]; resp2 = templang[0];} | |
} | |
if(st==1) return resp2; // Code | |
else return resp1; //Full name | |
} | |
function DOSLDetection(myTransText) { | |
var baseUrl = "http://imtranslator.net/detect-g.asp?fl=zh&text="+escape(myTransText); | |
var ajaxRequest; | |
try{ | |
ajaxRequest = new XMLHttpRequest(); | |
} catch (e){ | |
try{ | |
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); | |
} catch (e) { | |
try{ | |
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); | |
} catch (e){ | |
alert("Your browser broke"); | |
return false; | |
} | |
} | |
} | |
ajaxRequest.onreadystatechange = function(){ | |
if(ajaxRequest.readyState == 4){ | |
var resp = ajaxRequest.responseText; | |
if(resp=="zh") resp="zh-CN"; | |
if(resp=="zt") resp="zh-TW"; | |
SL_DETECT = resp; | |
} | |
} | |
ajaxRequest.open("POST", baseUrl, true); | |
ajaxRequest.send(null); | |
} | |
function truncStrByWord(str, length){ | |
if(str!="undefined"){ | |
if(str.length>25){ | |
length=length-25; | |
var thestr=str; | |
if (str.length > length) { | |
str = str.substring (0, length); | |
str = str.replace(new RegExp("/(.{1,"+length+"})\b.*/"), "$1") // VK - cuts str to max length without splitting words. | |
var str2 = thestr.substring(length, (length+25)); | |
var tempstr=str2.split(" "); | |
var tmp=""; | |
for (var i=0; i<tempstr.length-1; i++){ | |
tmp = tmp+tempstr[i]+" "; | |
} | |
str=str+tmp; | |
} | |
} else str = str+" "; | |
} | |
return str; | |
} | |
function SL_BALLOON_TRANSLATION(myTransText,evt,st) { | |
var mySourceLang = SL_langSrc; | |
var myTargetLang = SL_langDst; | |
var AUTO = SL_langSrc; | |
if(SL_NODETECT_bbl=="true")AUTO = "auto"; | |
if(AUTO=="auto"){ | |
mySourceLang = SL_langSrc; | |
if(SL_NODETECT_bbl=="true") mySourceLang = SL_FROMlng; | |
myTargetLang = SL_langDst; | |
if(st==1){ | |
myTargetLang=document.getElementById("SL_lng_to").value; | |
SL_SID_TO=myTargetLang; | |
SL_SID_TEMP_TARGET=myTargetLang; | |
} else{ SL_SID_TO="";} | |
}else{ | |
var LANGS = SL_ListOfAvailableLanguages.split(","); | |
for (var i=0;i<LANGS.length;i++){ | |
var templang=LANGS[i].split(":"); | |
if(SL_langSrc == templang[0]) {var resp = templang[1]+ARROWS; SL_FROMlng = templang[0];} | |
} | |
if(st==1){ | |
myTargetLang=document.getElementById("SL_lng_to").value; | |
SL_SID_TO=myTargetLang; | |
SL_SID_TEMP_TARGET=myTargetLang; | |
} else{ | |
document.getElementById('SL_lng_from').innerHTML=resp; | |
if(SL_SID_TEMP_TARGET!=""){ document.getElementById('SL_lng_to').value=SL_SID_TEMP_TARGET;} | |
else document.getElementById('SL_lng_to').value=SL_langDst; | |
myTargetLang=document.getElementById('SL_lng_to').value; | |
} | |
} | |
if(SL_TS!=SL_TSold) {SL_TSold=SL_TS; myTargetLang = SL_langDst; SL_SID_TEMP_TARGET=myTargetLang; document.getElementById('SL_lng_to').value=SL_langDst;} | |
if(SL_SID_TEMP_TARGET!="") myTargetLang=SL_SID_TEMP_TARGET; | |
myTransText=myTransText.replace(/#/g,""); | |
myTransText=myTransText.replace(/%/g,""); | |
if(myTransText!=""){ | |
//alert(mySourceLang+"|"+myTargetLang); | |
var baseUrl = "http://translate.google.com/"; | |
var SL_Params = "hl=en&langpair="+mySourceLang+"|"+myTargetLang+"&q="+encodeURIComponent(myTransText)+"&tbb=1&ie=UTF-8&oe=UTF-8"; | |
var ajaxRequest; | |
try{ | |
ajaxRequest = new XMLHttpRequest(); | |
} catch (e){ | |
try{ | |
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); | |
} catch (e) { | |
try{ | |
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); | |
} catch (e){ | |
alert("Your browser broke"); | |
return false; | |
} | |
} | |
} | |
ajaxRequest.onreadystatechange = function(){ | |
if(ajaxRequest.readyState == 4){ | |
var resp = ajaxRequest.responseText; | |
if(resp.indexOf('<span id=result_box class="long_text">')>-1) var ImtranslatorGoogleResult1=resp.split('<span id=result_box class="long_text">'); | |
else var ImtranslatorGoogleResult1=resp.split('<span id=result_box class="short_text">'); | |
var ImtranslatorGoogleResult2=ImtranslatorGoogleResult1[1].split('</span></div>'); | |
var ImtranslatorGoogleResult3=ImtranslatorGoogleResult2[0].replace(/<br>/ig,'@'); | |
ImtranslatorGoogleResult3=ImtranslatorGoogleResult3.replace(/'/ig,"'"); | |
ImtranslatorGoogleResult3=ImtranslatorGoogleResult3.replace(/"/ig,"'"); | |
ImtranslatorGoogleResult3=ImtranslatorGoogleResult3.replace(/&/ig,"&"); | |
ImtranslatorGoogleResult3=ImtranslatorGoogleResult3.replace(/(<([^>]+)>)/ig,""); | |
var ImtranslatorGoogleResult4=ImtranslatorGoogleResult3.replace(/@/ig,"<br>"); | |
document.getElementById('SL_shadow_translation_result').innerHTML=ImtranslatorGoogleResult4; | |
if(ImtranslatorGoogleResult4 != ""){ | |
if (SL_TH_2==1){ | |
var SLnow = new Date(); | |
SLnow=SLnow.toString(); | |
var TMPtime=SLnow.split(" "); | |
var CurDT=TMPtime[1]+" "+TMPtime[2]+" "+TMPtime[3]+", "+TMPtime[4]; | |
chrome.runtime.sendMessage({greeting: myTransText + "~~" + ImtranslatorGoogleResult4 + "~~" + mySourceLang + "|" + myTargetLang + "~~"+ document.location+"~~"+CurDT+"~~2^^"}, function(response) { | |
console.log(response.farewell); | |
}); | |
} | |
} | |
document.getElementById('SL_shadow_translation_result').style.direction="ltr"; | |
document.getElementById('SL_shadow_translation_result').style.textAlign="left"; | |
var SL_LTR = document.getElementById('SL_lng_to').value; | |
if(SL_LTR=="ar" || SL_LTR=="iw" || SL_LTR=="fa" || SL_LTR=="ur" || SL_LTR=="yi"){ | |
document.getElementById('SL_shadow_translation_result').style.direction="rtl"; | |
document.getElementById('SL_shadow_translation_result').style.textAlign="right"; | |
} | |
document.getElementById('SL_shadow_translator').style.display='block'; | |
SL_temp_result=ImtranslatorGoogleResult4; | |
if(document.getElementById('SL_shadow_translator').offsetHeight>100)SL_BALLON_H=document.getElementById('SL_shadow_translator').offsetHeight; | |
if(st==0){ | |
var OBJ=document.getElementById('SL_pin'); | |
if(OBJ.className=="SL_pin_off"){ | |
var SLdivField=document.getElementById("SL_shadow_translator"); | |
var virtualX=SL_ALIGN('x'); | |
var virtualY=SL_ALIGN('y'); | |
SL_MoveX=virtualX+"px"; | |
SL_MoveY=virtualY+"px"; | |
SLdivField.style.display='block'; | |
SLdivField.style.top=SL_MoveY; | |
SLdivField.style.left=SL_MoveX; | |
} | |
var MIN = SL_GLOBAL_Y1; | |
var MAX = SL_GLOBAL_Y2; | |
if(MIN>SL_GLOBAL_Y2){MIN=SL_GLOBAL_Y2;MAX=SL_GLOBAL_Y1;} | |
var AVR = MAX-MIN; | |
if(AVR>=(window.innerHeight-275)){ | |
SL_VirtualPIN=1; | |
var OBJ=document.getElementById('SL_pin'); | |
OBJ.className="SL_pin_on"; | |
OBJ.title="Unpin pop-up bubble"; | |
SL_FLOATER (); | |
}else SL_VirtualPIN=0; | |
} | |
} | |
} | |
ajaxRequest.open("POST", baseUrl, true); | |
ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); | |
// ajaxRequest.setRequestHeader("Content-length", SL_Params.length); | |
// ajaxRequest.setRequestHeader("Connection", "close"); | |
ajaxRequest.send(SL_Params); | |
} | |
} | |
function SL_Donate (){ | |
window.open('https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=GD9D8CPW8HFA2', null, null, null, false, false); | |
} | |
function SL_Voice (){ | |
var SL_to = document.getElementById("SL_lng_to").value; | |
SL_to = SL_to.replace("-TW",""); | |
SL_to = SL_to.replace("-CN",""); | |
var TTStext=SL_temp_result.replace(/<br>/g, " "); | |
if(SL_to=="en" || SL_to=="es" || SL_to=="ru" || SL_to=="de" || SL_to=="pt" || SL_to=="fr" || SL_to=="it" || SL_to=="ko" || SL_to=="ja" || SL_to=="zh"){ | |
window.open("http://text-to-speech.imtranslator.net/?dir="+SL_to+"&text="+encodeURIComponent(TTStext)); | |
}else alert('This voice is not supported yet!'); | |
} | |
function SL_CopyToClipBoard(){ | |
var OBJ=document.getElementById('SL_shadow_translation_result'); | |
OBJ.contentEditable = true; | |
OBJ.unselectable = "off"; | |
OBJ.focus(); | |
document.execCommand('SelectAll'); | |
document.execCommand("Copy", false, null); | |
} | |
function SL_Font(){ | |
var OBJ=document.getElementById('SL_shadow_translation_result'); | |
var OBJ2=document.getElementById('SL_shadow_translation_result2'); | |
var OBJ3=document.getElementById('SL_bbl_font'); | |
if(SL_FontSize==OBJ.style.fontSize){ | |
if(OBJ3.className=="SL_font_off"){ | |
OBJ.style.fontSize="15px"; | |
OBJ.style.lineHeight="17px"; | |
OBJ2.style.fontSize="15px"; | |
OBJ2.style.lineHeight="17px"; | |
OBJ3.className="SL_font_on"; | |
SL_FontSize="15px"; | |
}else{ | |
OBJ.style.fontSize="11px"; | |
OBJ.style.lineHeight="13px"; | |
OBJ2.style.fontSize="11px"; | |
OBJ2.style.lineHeight="13px"; | |
OBJ3.className="SL_font_off"; | |
SL_FontSize="11px"; | |
} | |
SL_SID_FONT=SL_FontSize; | |
} | |
} | |
function SL_pinme(){ | |
var OBJ=document.getElementById('SL_pin'); | |
if(OBJ.className=="SL_pin_off"){ | |
OBJ.className="SL_pin_on"; | |
OBJ.title="Unpin pop-up bubble"; | |
SL_SID_PIN="true"; | |
SL_FLOATER (); | |
}else{ | |
OBJ.className="SL_pin_off"; | |
OBJ.title="Pin pop-up bubble"; | |
document.getElementById("SL_shadow_translator").style.display="none"; | |
if(SL_VirtualPIN==0) SL_SID_PIN="false"; | |
} | |
} | |
function SL_FLOATER (){ | |
var OBJ=document.getElementById('SL_pin'); | |
if(OBJ.className=="SL_pin_on"){ | |
var THEobj=document.getElementById("SL_shadow_translator"); | |
THEobj.style.top=SL_getScrollY()+(window.innerHeight/2-150)+"px"; | |
THEobj.style.left=(window.innerWidth-350-30)+"px"; | |
} | |
} | |
function SL_getScrollY(){ | |
var scrOfY = 0; | |
if( document.body && document.body.scrollTop ) { | |
scrOfY = document.body.scrollTop; | |
} else if( document.documentElement && document.documentElement.scrollTop ) { | |
scrOfY = document.documentElement.scrollTop; | |
} | |
return scrOfY; | |
} | |
function SL_GOOGLE_WPT(){ | |
if(document.getElementById("wtgbr")){ | |
document.getElementById("wtgbr").style.display='none'; | |
document.getElementById("gt-bbar").style.display='none'; | |
document.getElementById("clp-btn").style.display='none'; | |
document.getElementById("contentframe").style.marginTop='-100px'; | |
} | |
} | |
function HotKeysWindow(e){ | |
var s = window.getSelection().toString(); | |
s=s.substring(0,SL_PLANSHET_LIMIT); | |
s=escape(s); | |
s=s.replace(/%A0/g,"\n"); | |
s=unescape(s); | |
if(s!=""){ | |
var location = chrome.extension.getURL('translator.html')+"?text="+s; | |
var winWidth = 480 ; | |
var winHeight = 645 ; | |
var posLeft = ( screen.width - winWidth ) / 2 ; | |
var posTop = ( screen.height - winHeight ) / 2 ; | |
var myTWindow = window.open(location,'ImTranslator','width=' + winWidth + ',height=' + winHeight +',top=' + posTop + ',left=' + posLeft + ',resizable=no,scrollbars=no,toolbar=no,titlebar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment