12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253 |
- version = 'v3.1.8';
- function splitRGB(color) //îáðàáîòêà öâåòà
- {
- var matches = color.match(/^#?([\dabcdef]{2})([\dabcdef]{2})([\dabcdef]{2})$/i);
- if (!matches)
- return false;
- for (var i=1, rgb = new Array(3); i<=3; i++)
- rgb[i-1] = parseInt(matches[i],16);
- return rgb;
- }
- function rgb2hex(r,g,b)
- {
- if(r>255) r=255; //0_o áûäëîêîäèíã òàêîé áûäëîêîäèíã
- if(g>255) g=255;
- if(b>255) b=255;
- return '#'+Number(r).toString(16).toUpperCase().replace(/^(.)$/,'0$1') +
- Number(g).toString(16).toUpperCase().replace(/^(.)$/,'0$1') +
- Number(b).toString(16).toUpperCase().replace(/^(.)$/,'0$1');
- }
- function base64color(arr) //öâåò îáðàìëåíèÿ
- {
- var r=arr[0];
- var g=arr[1];
- var b=arr[2];
- if(r>63) r=63; //0_o áûäëîêîäèíã òàêîé áûäëîêîäèíã
- if(g>63) g=63;
- if(b>63) b=63;
- var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
- var enc1 = r >> 2;
- var enc2 = ((r & 3) << 4) | (g >> 4);
- var enc3 = ((g & 15) << 2) | (b >> 6);
- var enc4 = b & 63;
- return keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) + keyStr.charAt(enc4);
- }
- function setColors() {
- var fc = splitRGB(cfg.fontcolor);
- var bg = splitRGB(cfg.bgcolor);
- var Q=[Math.round((fc[0]+3*bg[0])/16),Math.round((fc[1]+3*bg[1])/16),Math.round((fc[2]+3*bg[2])/16)];
- var M=[Math.round((fc[0]+bg[0])/8),Math.round((fc[1]+bg[1])/8),Math.round((fc[2]+bg[2])/8)];
- var middlecolor=rgb2hex(M[0]*4,M[1]*4,M[2]*4);
- colorMiddleB64=base64color(M);
- colorQuarterB64=base64color(Q);;
- if (fc[0]+fc[0]+fc[0]>bg[0]+bg[1]+bg[2]) {
- linkcolor=rgb2hex(Math.round(3*(fc[0]+bg[0])/4),Math.round(3*(fc[1]+bg[1])/4),Math.round(3*(fc[2]+bg[2])/4));
- } else {
- linkcolor=rgb2hex(Math.round((fc[0]+bg[0])/4),Math.round((fc[1]+bg[1])/4),Math.round((fc[2]+bg[2])/4));
- }
- document.body.link=document.body.vLink=
- document.body.aLink=
- gdb('comm').style.color=
- gdb('footer').style.color=linkcolor;
- document.body.style.color=gdb('book').style.color=gdb('main').style.color=
- gdb('pageGoto').style.color=
- gdb('cross').style.backgroundColor=
- gdb('mcross').style.backgroundColor=gdb('clrdiv').style.color=
- gdb('clrdiv2').style.color=
- gdb('btnOk').style.color=
- cfg.fontcolor;
- document.body.style.backgroundColor='#000000';
- gdb('win').style.backgroundColor=gdb('comm').style.backgroundColor=
- gdb('cross').style.color=
- gdb('mcross').style.color=
- gdb('clrdiv').style.backgroundColor=gdb('clrdiv2').style.backgroundColor=
- cfg.bgcolor;
- var hr=document.getElementsByTagName('HR');
- gdb('colorSelect').children[2].style.borderColor=gdb('colorSelect').children[2].children[1].style.borderColor=
- gdb('colorSelect').children[2].children[2].style.borderColor=hr[0].style.color=hr[0].style.backgroundColor=
- gdb('comm').style.borderColor=middlecolor;
- hr=null;
- //
- handlerAdd(gdb('cross'),'mouseover',function() {gdb('cross').style.color=middlecolor;});
- handlerAdd(gdb('cross'),'mouseout',function() {gdb('cross').style.color=cfg.bgcolor;});
- handlerAdd(gdb('mcross'),'mouseover',function() {gdb('mcross').style.color=middlecolor;});
- handlerAdd(gdb('mcross'),'mouseout',function() {gdb('mcross').style.color=cfg.bgcolor;});
- }
- function handlerAdd(object, event, handler) {
- if (object.addEventListener)
- object.addEventListener(event, handler, false);
- else
- if (object.attachEvent)
- object.attachEvent('on' + event, handler);
- else
- object['on' + event] = handler;
- }
- function handlerRemove(object, event, handler) {
- if (object.removeEventListener)
- object.removeEventListener(event, handler, false);
- else
- if (object.detachEvent)
- object.detachEvent('on' + event, handler);
- }
- //íèæå: ëîâèì êëàâó
- function key(event) {
- if (!event) event = window.event;
- var thekey=event.keyCode ? event.keyCode + 32 : event.charCode;
- tM(event.shiftKey,event.ctrlKey,thekey, event);
- }
- var m_legend = {
- 40: {30: 'PgUp', 100: 'PgDown'},
- 60: {40: 'Up', 60: 'Menu', 100: 'Down'},
- 100: {30: 'PgUp', 100: 'PgDown'}
- };
- function processClick(w, h) {
- var e = '';
- if (typeof(event) == 'string') {
- e = event;
- } else {
- loops: {
- for (var perx in m_legend) {
- for (var pery in m_legend[perx]) {
- if (w < perx && h < pery) {
- e = m_legend[perx][pery];
- break loops;
- }
- }
- }
- }
- if (e != '')
- button = 1;
- }
- switch (e) {
- case 'Down' ://Down
- setTop(null, cfg.step);
- break;
- case 'Up' ://Up
- setTop(null, -cfg.step);
- break;
- case 'PgDown' ://PgDown
- setTop(null, phei - cfg.step);
- break;
- case 'PgUp' ://PgUp
- setTop(null, -(phei - cfg.step));
- break;
- case 'Menu' ://M
- menu();
- break;
- default :
- // Nothing
- break;
- }
- if (doRepeatClick && e != '' && e != 'Menu') {
- if (mTimer > 20)
- mTimer = mTimer*0.5;
- processClickTimeout=setTimeout('processClick('+w+','+h+')', mTimer);
- }
- }
- function mClick(event) {
- if (cfg.by_click) {
- var win = gdb('win');
- var w = event.clientX/win.offsetWidth*100;
- var h = event.clientY/win.offsetHeight*100;
- doRepeatClick = 1;
- mTimer = 1000;
- processClick(w, h);
- ie8SafePreventEvent(event);
- }
- }
- function mClickUp(event) {
- mTouchEnd(event);
- }
- function mTouchStart(event) {
- if (cfg.by_click) {
- if (event.touches.length == 1) {
- event.preventDefault();
- e = event.touches[0];
- var win = gdb('win');
- var w = e.clientX/win.offsetWidth*100;
- var h = e.clientY/win.offsetHeight*100;
- doRepeatClick = 1;
- mTimer = 1000;
- processClick(w, h);
- }
- }
- }
- function mTouchEnd(event) {
- doRepeatClick = 0;
- if (processClickTimeout != null)
- clearTimeout(processClickTimeout);
- }
- function openLink(event, obj, target) {
- if (target == null)
- target = '_blank';
- window.open(obj.href, target);
- ie8SafePreventEvent(event);
- return false;
- }
- function toggleFullScreen() {
- if ((document.fullScreenElement && document.fullScreenElement !== null) ||
- (!document.mozFullScreen && !document.webkitIsFullScreen)) {
- if (document.documentElement.requestFullScreen) {
- document.documentElement.requestFullScreen();
- } else if (document.documentElement.mozRequestFullScreen) {
- document.documentElement.mozRequestFullScreen();
- } else if (document.documentElement.webkitRequestFullScreen) {
- document.documentElement.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
- }
- } else {
- if (document.cancelFullScreen) {
- document.cancelFullScreen();
- } else if (document.mozCancelFullScreen) {
- document.mozCancelFullScreen();
- } else if (document.webkitCancelFullScreen) {
- document.webkitCancelFullScreen();
- }
- }
- }
- function ie8SafePreventEvent(e) {
- if (e.preventDefault) {
- e.preventDefault()
- } else
- if (e.stop)
- e.stop();
- e.returnValue = false;
- if (e.stopPropagation)
- e.stopPropagation();
- }
- //íèæå: ëîâèì íàæàòèÿ êëàâèø
- function tM(shift,ctrl,key, event) {
- var srcEl = event.srcElement? event.srcElement : event.target;
- //alert(srcEl.tagName);
- //alert(key);
- if (!ctrl && (srcEl.tagName == 'BODY' || srcEl.tagName == 'DIV'))
- switch (key)
- {
- case 72 ://Down
- if (shift)
- toggleScroll();
- else
- setTop(null, cfg.step);
- ie8SafePreventEvent(event);
- break;
- case 70 ://Up
- setTop(null, -cfg.step);
- ie8SafePreventEvent(event);
- break;
- case 66 ://PgDown
- case 45 ://Enter
- setTop(null, phei - cfg.step);
- ie8SafePreventEvent(event);
- break;
- case 64 ://Space
- shift ? setTop(null, -(phei - cfg.step)) : setTop(null, phei - cfg.step);
- ie8SafePreventEvent(event);
- break;
- case 65 ://PgUp
- case 40 ://BackSpace
- setTop(null, -(phei - cfg.step));
- ie8SafePreventEvent(event);
- break;
- case 67 ://End
- setTop(clih - phei);
- ie8SafePreventEvent(event);
- break;
- case 68 ://Home
- setTop(0);
- ie8SafePreventEvent(event);
- break;
- case 109: //M
- menu();
- ie8SafePreventEvent(event);
- break;
- case 97: //A
- shift ? incFont(-1) : incFont(1);
- ie8SafePreventEvent(event);
- break;
- case 115: //S
- gdb('id_scroll').checked = !gdb('id_scroll').checked;
- showScroll();
- ie8SafePreventEvent(event);
- break;
- case 116: //T
- gdb('id_by_click').checked = !gdb('id_by_click').checked;
- byClick();
- ie8SafePreventEvent(event);
- break;
- case 224://`
- case 102://F
- toggleFullScreen();
- ie8SafePreventEvent(event);
- break;
- case 122://Z
- toggleScroll();
- ie8SafePreventEvent(event);
- break;
- case 59://Escape
- if (sti) {
- toggleScroll();
- ie8SafePreventEvent(event);
- }
- break;
- case 71://Right
- if (shift) {
- gdb('id_sc_int').value = cfg.sc_int - 1;
- scrollInterval();
- } else {
- setTop(null, phei - cfg.step);
- ie8SafePreventEvent(event);
- }
- break;
- case 69://Left
- if (shift) {
- gdb('id_sc_int').value = cfg.sc_int + 1;
- scrollInterval();
- } else {
- setTop(null, -(phei - cfg.step));
- ie8SafePreventEvent(event);
- }
- break;
- case 114:
- reloadBook();
- break;
- default :
- // Nothing
- break;
- }
- return false;
- }
- //êîëåñî
- function wheel(event) {
- var delta = 0;
- if (!event)
- event = window.event;
- if (event.wheelDelta)
- delta = event.wheelDelta/120;
- else
- if (event.detail)
- delta = -event.detail/3;
- if (delta)
- handle(delta);
- return false;
- }
- function handle(delta) {
- if (delta < 0)
- setTop(null, cfg.step);
- else
- setTop(null, -cfg.step);
- }
- //íèæå: óïðîøàåìñ, â ôèíàëüíîé âåðñèè íàáî áû óáðàòü
- function gdb(id)
- {
- return document.getElementById(id);
- }
- function supports_html5_storage() {
- try {
- return 'localStorage' in window && window['localStorage'] !== null;
- } catch (e) {
- return false;
- }
- }
- function saveLocalValue(key, value, expires_days, no_escape) {
- if (value != null) {
- if (no_escape == null)
- localStorage[key] = escape(value);
- else
- localStorage[key] = value;
- if (expires_days == null)
- expires_days = 0;
- localStorage[key+'=timestamp'] = (new Date()) + ';' + expires_days;
- }
- else {
- localStorage.removeItem(key);
- localStorage.removeItem(key+'=timestamp');
- }
- }
- //êóêèñû è localStorage
- function saveValue(name, value, expires_days, no_escape) {
- var key = escape(name);
- if (is_storage) {
- try {
- saveLocalValue(key, value, expires_days, no_escape);
- } catch (e) {
- //alert('LocalStorage, îøèáêà: ' + e.message);
- var size = 0;
- //Ñ íà÷àëà - õîòü êàêîé-òî ìåõàíèçì î÷åðåäè
- for ( var i = 0; i < localStorage.length; i++ ) {
- var lkey = localStorage.key( i );
- var v = localStorage[lkey];
- //lkeys = lkeys + unescape(lkey) + ":" + (v != null ? v.length : 0) + "\n";
- if (v != null && v.length > 10000) {
- size += v.length;
- localStorage.removeItem(lkey);
- localStorage.removeItem(lkey+'=timestamp');
- i = 0;
- if (size > value.length)
- break;
- }
- }
- //×èñòêà ïðîòóõøèõ, ñ êîíöà
- for ( var i = localStorage.length; i >= 0 ; i-- ) {
- var lkey = unescape(localStorage.key( i ));
- loadValue(lkey);
- }
- try { saveLocalValue(key, value, expires_days, no_escape) } catch(e) {};
- //alert(size);
- //LocalStorage.clear();
- }
- if (document.cookie != '')
- document.cookie = '';
- } else {
- var exp = new Date();
- if (expires_days)
- exp.setHours(exp.getHours() + 24*expires_days);
- document.cookie = key + "=" + escape(value) +
- ((expires_days) ? "; expires=" + exp.toUTCString() : "") +
- "; path=/";
- }
- }
- function getCookie(name) {
- var setStr = null;
- var cookie = " " + document.cookie;
- var search = " " + name + "=";
- var offset = 0;
- var end = 0;
- if (cookie.length > 0) {
- offset = cookie.indexOf(search);
- if (offset != -1) {
- offset += search.length;
- end = cookie.indexOf(";", offset)
- if (end == -1)
- end = cookie.length;
- setStr = unescape(cookie.substring(offset, end));
- }
- }
- return(setStr);
- }
- function loadValue(name, no_escape) {
- var value = null;
- if (is_storage) {
- var key = escape(name);
- value = localStorage[key];
- var ts = localStorage[key+'=timestamp'];
- if (value != null && no_escape == null)
- value = unescape(value);
- if (ts != null) {
- ts = ts.split(";");
- var exp = new Date(ts[0]);
- exp.setHours(exp.getHours() + 24*ts[1]);
- if (exp < new Date()) {
- value = null;
- localStorage.removeItem(key);
- localStorage.removeItem(key+'=timestamp');
- }
- } else {
- localStorage.removeItem(key);
- localStorage.removeItem(key+'=timestamp');
- }
- }
- if (value == null)
- value = getCookie(escape(name));
- if (value == null)
- value = getCookie(name);
- return(value);
- }
- //ñ÷¸ò÷èê ñòðàíèö è ïðîöåíòîâ
- function tMh() {
- if (!sti || gdb('main').scrollTop%cfg.step == 0) {
- var top = Math.round(gdb('main').scrollTop/cfg.step)*cfg.step;
- gdb('main').scrollTop = top;
- pcount = Math.ceil( clih / (phei-cfg.step) );
- if (clih == phei)
- pcount = 1;
- var page = Math.floor((top - cfg.step) / (phei-cfg.step) + 2);
- percent = Math.round(top / (clih-phei) * 10000) / 100; //(top==0) ? 0 :
- if (clih == phei)
- percent = 100;
- gdb('pagePercent').innerHTML=' [ ' + percent.toFixed(2) + '%' + ' ] ';
- gdb('pageCount').children[1].innerHTML=page + '/' + pcount;
- gdb('pageGoto').value=page;
- if (stadc == null)
- stadc = setTimeout('addCook()', 300);
- };
- if (sttmh != null) {
- clearTimeout(sttmh);
- sttmh = null;
- }
- }
- //ïåðåõîä íà ñòðàíèöó
- function goTo() {
- var gpage=parseInt(gdb('pageGoto').value);
- setTop((((gpage-2)*(phei-cfg.step) + cfg.step)/cfg.step).toFixed(0)*cfg.step);
- }
- function pageGoto(gpag) {
- if (gpa) {
- var gpage=parseInt(gdb('pageGoto').value);
- gpage = gpag ? (gpage > 1 ? gpage-1 : 1) : (gpage<pcount ? gpage+1 : pcount);
- gdb('pageGoto').value=gpage;
- var t=setTimeout('pageGoto('+gpag+')',timer);
- if (timer>20)
- timer=timer/2;
- } else
- timer=300;
- }
- function pageMove(arrow) {
- handlerAdd(document,'mouseup',pageMoveClear);
- if (timer>20) timer=timer*0.9;
- setTop(null, (arrow ? cfg.step-phei : phei-cfg.step));
- pageMoveTimeout=setTimeout('pageMove('+arrow+')',timer);
- }
- function pageMoveShow(pS,nS) {
- pageMoveTemp = pageMoveTemp ? 0 : 1;
- gdb('pageCount').children[0].style.visibility=
- gdb('pageCount').children[2].style.visibility=
- pageMoveTemp ? 'visible' : 'hidden';
- }
- function pageMoveClear() {
- if (timer<300) {
- clearTimeout(pageMoveTimeout);
- handlerRemove(document,'mouseup',pageMoveClear);
- timer=300;
- }
- }
- //âðåìÿ
- function showTime()
- {
- var tmN=new Date();
- var dH=''+tmN.getHours();dH=dH.length<2?'0'+dH:dH;
- var dM=''+tmN.getMinutes();dM=dM.length<2?'0'+dM:dM;
- var tmp=dH+':'+dM;
- if (bookloaded)
- gdb('tm').innerHTML=tmp;
- else
- gdb('tm').innerHTML=version;
- var t=setTimeout('showTime()',60000);
- }
- function setSelectedFontItem() {
- if (colorFontTemp == 0) {
- gdb('fontItemBack').style.color = 'green';
- gdb('fontItemBack').style.textDecoration = 'underline';
- gdb('fontItemText').style.color = 'black';
- gdb('fontItemText').style.textDecoration = 'none';
- } else {
- gdb('fontItemText').style.color = 'green';
- gdb('fontItemText').style.textDecoration = 'underline';
- gdb('fontItemBack').style.color = 'black';
- gdb('fontItemBack').style.textDecoration = 'none';
- }
- }
- //ìåíþ âûáîðà íàñòðîåê øðèôòà
- function colorMenu() {
- handlerAdd(document,'mousemove', mouseMoved);
- colorFontTemp=0;
- setSelectedFontItem();
- colorFont=cfg.fontcolor;
- colorBg=cfg.bgcolor;
- colorSize=Math.round(cfg.step*0.8);
- gdb('fcolor').value=colorFont;
- gdb('bcolor').value=colorBg;
- gdb('fsize').value=colorSize;
- gdb('ffamily').value=cfg.fontfamily;
- if (gdb('ffamily').value != cfg.fontfamily)
- gdb('ffamily2').value=cfg.fontfamily;
- else
- gdb('ffamily2').value='';
- colorAddary=new Array(255,1,1);
- colorClrary=new Array(360);
- for(i=0;i<6;i++) {
- for(j=0;j<60;j++) {
- colorClrary[60*i+j]=new Array(3);
- for(k=0;k<3;k++) {
- colorClrary[60*i+j][k]=colorAddary[k];
- colorAddary[k]+=((Math.floor(65049010/Math.pow(3,i*3+k))%3)-1)*4;
- }
- }
- }
- gdb('colorSelect').style.display='block';
- }
- function mouseMoved(e) {
- var sy = e.pageX-parseInt(gdb('colorSelect').style.left)-454;
- var sx = e.pageY-parseInt(gdb('colorSelect').style.top)-300;
- //alert(sy+'lk'+sx);
- if (sy>-256&&sx>-256&&sx<256&&sy<256) {
- var quad=new Array(-180,360,180,0);
- var xa=Math.abs(sx);
- var ya=Math.abs(sy);
- var d=ya*45/xa;
- if (ya>xa)
- d=90-(xa*45/ya);
- var deg=Math.floor(Math.abs(quad[2*((sy<0)?0:1)+((sx<0)?0:1)]-d));
- var n=0;
- var c="000000";
- var r=Math.sqrt((xa*xa)+(ya*ya));
- if(sx!=0 || sy!=0) {
- for(i=0;i<3;i++) {
- r2=colorClrary[deg][i]*r/128;
- if (r>128)
- r2+=Math.floor(r-128)*2;
- if (r2>255)
- r2=255;
- n=256*n+Math.floor(r2);
- }
- c=(n.toString(16)).toUpperCase();
- while (c.length<6)
- c="0"+c;
- }
- gdb('clrdiv').style.backgroundColor=colorFontTemp ? colorBg : "#"+c;
- gdb('clrdiv').style.color=colorFontTemp ? "#"+c : colorFont;
- tempColor="#"+c;
- }
- return false;
- }
- function colorSet() {
- var clrdiv2=gdb('clrdiv2').style;
- if (colorFontTemp)
- clrdiv2.color=gdb('fcolor').value=colorFont=tempColor;
- else
- clrdiv2.backgroundColor=gdb('bcolor').value=colorBg=tempColor;
- }
- function colorChange(type, value) { //íàâåñòè ìàðàôåò
- var value=value.toUpperCase();
- if(type==2 || type==1) {
- if (value.charAt(0)!='#')
- value='#'+value;
- value=value.length==7 ? value :
- (value.length==4 ?
- value.substr(0,2)+value.substr(1,1)+value.substr(2,1)+value.substr(2,1)+value.substr(3,1)+value.substr(3,1) :
- (type==2 ? cfg.bgcolor : cfg.fontcolor)
- ); //ñäåëàòü ÷åëîâå÷åñêè
- if (type==2)
- gdb('bcolor').value = value;
- else
- gdb('fcolor').value = value;
- }
- var clrdiv2=gdb('clrdiv2').style;
- var clrdiv=gdb('clrdiv').style;
- if (type == 4)
- clrdiv2.fontFamily = value;
- if (type==3 && parseInt(value) > 4 && parseInt(value) < 201)
- clrdiv2.fontSize=clrdiv.fontSize=parseInt(value)+'px';
- if (type==2)
- clrdiv2.backgroundColor=clrdiv.backgroundColor=value;
- if (type==1)
- clrdiv2.color=clrdiv.color=value;
- return false;
- }
- function saveSettings() {
- saveValue('colorSetting', cfg.fontcolor+'|'+cfg.bgcolor+'|'+cfg.step+'|'+cfg.fontfamily+'|'+cfg.scroller+'|'+cfg.sp_size+'|'+cfg.sc_int+'|'+cfg.by_click, 36500);
- }
- function colorSubmit() {
- cfg.fontcolor=gdb('fcolor').value;
- cfg.bgcolor=gdb('bcolor').value;
- cfg.step=Math.round(parseInt(gdb('fsize').value)/0.8);
- cfg.fontfamily=gdb('ffamily2').value;
- if (!cfg.fontfamily)
- cfg.fontfamily = gdb('ffamily').value;
- gdb('main').style.font=Math.round(cfg.step*0.8)+"px/"+cfg.step+"px Trebuchet Ms";
- gdb('main').style.fontFamily=cfg.fontfamily;
- saveSettings();
- setColors();
- onRes();
- }
- function colorClose() {
- handlerRemove(document,'mousemove', mouseMoved);
- gdb('colorSelect').style.display='none';
- tempColor=null;
- colorFontTemp=null;
- colorFont=null;
- colorBg=null;
- colorSize=null;
- colorAddary=null;
- colorClrary=null;
- }
- function incFont(i) {
- foSize=Math.round(cfg.step*0.8);
- foSize += i;
- if (foSize < 5 || foSize > 200)
- return;
- cfg.step=Math.round(foSize/0.8);
- gdb('main').style.fontSize = foSize + 'px';
- gdb('main').style.lineHeight = cfg.step + 'px';
- saveSettings();
- onRes();
- }
- function mainScroll() {
- if (sttmh == null)
- sttmh = setTimeout('tMh()', 500);
- }
- //íèæå: â êóêèñû
- function addCook() {
- saveValue('bpr-book-' + tit, gdb('main').scrollTop + '|' + gdb('main').scrollHeight + '|' + gdb('main').innerHTML.length, 36500);
- if (stadc) {
- clearTimeout(stadc);
- stadc = null;
- }
- }
- //íèæå: ìåíþ
- function menu() {
- if (gdb('comm').style.display != 'block')
- gdb('comm').style.display="block";
- else {
- gdb('leg').style.display="none";
- gdb('comm').style.display="none";
- }
- }
- //íèæå: ëåãåíäà
- function legend(ca) {
- if (ca) {
- gdb('leg').style.display="block";
- gdb('leg').style.left=Math.round((widt-((widt/100)*60))/2) + 'px';
- gdb('leg').style.top=Math.round((hei-((hei/100)*60))/2) + 'px';
- } else {
- gdb('leg').style.display="none";
- }
- }
- function setScroll(u) {
- u = (u == null) ? true : u;
- gdb('id_scroll').checked = cfg.scroller;
- if (cfg.scroller)
- gdb('main').style.overflowY = 'auto';
- else
- gdb('main').style.overflowY = 'hidden';
- if (u)
- onRes();
- }
- function showScroll() {
- cfg.scroller = gdb('id_scroll').checked;
- setScroll();
- saveSettings();
- return true;
- }
- function setSPSize(u) {
- u = (u == null) ? true : u;
- gdb('id_sp_size').value = cfg.sp_size;
- gdb('footer').style.height = cfg.sp_size + 'px';
- gdb('fhr').style.bottom = cfg.sp_size + 'px';
- if (cfg.sp_size == 0)
- gdb('fhr').style.display = 'none';
- else
- gdb('fhr').style.display = 'block';
- if (cfg.sp_size > 2)
- gdb('footer').style.font=(cfg.sp_size - 3)+"px/"+(cfg.sp_size-1)+"px 'Trebuchet Ms', Sans-Serif";
- if (u)
- onRes();
- }
- function statusPanel() {
- var s = parseInt(gdb('id_sp_size').value);
- if (s >= 0 && s <= 200)
- cfg.sp_size = s;
- setSPSize();
- saveSettings();
- return false;
- }
- function setTop(v, i) {
- if (i != null)
- gdb('main').scrollTop += i;
- else
- gdb('main').scrollTop = v;
- tMh();
- p_top = gdb('main').scrollTop;
- }
- function scrollText() {
- setTop(null, 1);
- }
- function toggleScroll(u) {
- u = (u == null) ? true : u;
- //alert('ok');
- if (sti) {
- clearTimeout(sti);
- sti = null;
- if (u)
- tMh();
- } else
- sti = setInterval('scrollText()', cfg.sc_int);
- return false;
- }
- function setScrollInt(u) {
- u = (u == null) ? true : u;
- gdb('id_sc_int').value = cfg.sc_int;
- toggleScroll(u);
- toggleScroll(u);
- }
- function scrollInterval() {
- var s = parseInt(gdb('id_sc_int').value);
- if (s > 0 && s <= 999)
- cfg.sc_int = s;
- setScrollInt(false);
- saveSettings();
- return false;
- }
- function setByClick() {
- gdb('id_by_click').checked = cfg.by_click;
- }
- function byClick() {
- cfg.by_click = gdb('id_by_click').checked;
- setByClick();
- saveSettings();
- return true;
- }
- function reloadBook() {
- if (is_storage) {
- saveValue('bpr-link-' + tit, null);
- saveValue('bpr-cached-book-'+tit, null);
- }
- window.location.href = window.location.href;
- return false;
- }
- function blinkReloadButton() {
- blinkCount++;
- if (blinkCount%2 == 1)
- gdb('reload').style.color = cfg.bgcolor;
- else
- gdb('reload').style.color = linkcolor;
- if (blinkCount > 30) {
- gdb('reload').style.color = linkcolor;
- if (stblinkRB != null) {
- clearTimeout(stblinkRB);
- stblinkRB == null;
- }
- }
- }
- //íèæå: ëîâèì èçìåíåíèå ðàçìåðîâ îêíà
- //íèæå: ëîâèì ðàçìåðû ðàáî÷åé îáëàñòè
- function gerT() {
- var w, h, hh;
- w = Math.round(window.innerWidth ?
- window.innerWidth :
- (document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.offsetWidth));
- h = Math.round(window.innerHeight ?
- window.innerHeight :
- (document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.offsetHeight));
- hh = Math.floor((h - (cfg.sp_size + 8)) / cfg.step) * cfg.step;
- return {w:w, h:h, hh:hh};
- }
- function onRes(u) {
- var focused = document.activeElement;
- //alert(focused.tagName);
- if (focused == null || focused.tagName != 'INPUT') {
- var g = gerT();
- hei = g.h;
- phei = g.hh;
- widt = g.w;
- gdb('header').style.height = Math.round((hei - (cfg.sp_size + 3) - phei)/2)+'px';
- gdb('main').style.height=phei+'px';
- gdb('win').style.height=hei+'px';
- //alert(widt + '/' +gdb('tr').style.width +gdb('main').style.width+gdb('tr').style.width)
- clih = gdb('main').scrollHeight;
- gdb('colorSelect').style.top=Math.round((hei-600)/2)+'px';
- gdb('colorSelect').style.left=Math.round((widt-300)/2)+'px'; //754
- gdb('comm').style.left=Math.round((widt-264)/2) + 'px';
- gdb('comm').style.top=Math.round((hei-264)/2) + 'px';
- if (u || u == null) {
- if (pclih != clih && pclih > 0) {
- var n_top = Math.round(p_top/pclih*clih);
- setTop(n_top);
- } else
- tMh();
- pclih = clih;
- }
- ow = widt - (gdb('id_lp').clientWidth + gdb('id_rp').clientWidth) - 10;
- if (ow < 0)
- ow = 0;
- gdb('orig').style.width = ow + 'px';
- gdb('orig').style.left = gdb('id_lp').clientWidth + 'px';
- } else
- setTimeout('onRes()', 500);
- }
- //--------------------------------------------------------------------------------------------------
- //çàãðóçêà
- function loadBook(book) {
- gdb('main').innerHTML = book;
- //íèæå: äîáûâàåì òàéòë
- var book_author = loadValue('bpr-author-' + tit);
- book_author = (book_author == null ? '' : book_author);
- var book_title = loadValue('bpr-title-' + tit);
- book_title = (book_title == null ? '' : book_title);
- var doc_title = tit;
- if (book_author + book_title != '')
- doc_title = book_author + (book_author != '' ? ' - ' : '') + book_title;
- if (tit != '')
- document.title = doc_title;
- bookloaded = true;
- gdb('win').style.display = gdb('footer').style.display = 'block';
- onRes(false);
- setTimeout('handlerAdd(window,"resize",onRes)',1); //åù¸ îäíî ÷óäî îò îñëà !!ïðîâåðèòü
- gdb('orig_href').href = tit;
- gdb('orig_href').innerHTML = doc_title;
- showTime();
- pclih = gdb('main').scrollHeight;
- var s_top = 0;
- var lv = loadValue('bpr-book-' + tit);
- if (lv) {
- // Âîññòàíîâèì ïîçèöèþ â òåêñòå
- var cpos = lv.split('|');
- var ntl = gdb('main').innerHTML.length;
- if (cpos[0]) {
- if (cpos[1] > 0 && ntl > 0) {
- var tp = cpos[0]/cpos[1]*cpos[2];
- s_top = Math.round(tp/ntl*pclih);
- }
- else
- s_top = cpos[0]; // Ñòàðûé âàðèàíò
- }
- }
- setTop(s_top);
- onRes(false);
- gdb('loading').style.display='none';
- }
- function parseBook(book, cached, save_to_cache) {
- var meta_sign = '<<<bpr5A432688AB0467AA396E5A144830248Abpr>>>';
- var meta_idx = book.indexOf(meta_sign);
- if (meta_idx >= 0) {
- var meta_info = book.substr(0, meta_idx).split('|');
- var book_link = meta_info[0];
- var book_author = meta_info[1];
- var book_title = meta_info[2];
- if (book_link != null) {
- book = book.substr(meta_idx + meta_sign.length);
- if (is_storage) {
- if (book_link != 'no_file') {
- saveValue('bpr-link-' + tit, book_link, 10);
- }
- if (save_to_cache) {
- saveValue('bpr-cached-book-'+tit, book, 30, 1);
- }
- saveValue('bpr-author-' + tit, book_author, 10);
- saveValue('bpr-title-' + tit, book_title, 10);
- }
- }
- }
- loadBook(book);
- if (cached != null) {
- blinkCount = 0;
- stblinkRB = setInterval('blinkReloadButton()', 500);
- }
- }
- function getDefaultSettings() {
- var def = {};
- def.bgcolor='#ebe2c9';
- def.fontcolor='#000000';
- def.step = 26;
- def.fontfamily = 'Trebuchet Ms';
- def.scroller = true;
- def.sp_size = 22;
- def.sc_int = 50;
- def.by_click = true;
- return def;
- }
- function loadSettings() {
- if (location.hash == '#RestoreDefaults') {
- saveSettings();
- } else {
- var lv = loadValue('colorSetting');
- if (lv) {
- var colorSetting=lv.split('|');
- cfg.fontcolor=colorSetting[0];
- cfg.bgcolor=colorSetting[1];
- cfg.step=parseInt(colorSetting[2]);
- if (colorSetting[3])
- cfg.fontfamily=colorSetting[3];
- if (colorSetting[4] != null)
- cfg.scroller = colorSetting[4].toLowerCase() == 'true';
- if (colorSetting[5] != null)
- cfg.sp_size = parseInt(colorSetting[5]);
- if (colorSetting[6] != null)
- cfg.sc_int = parseInt(colorSetting[6]);
- if (colorSetting[7] != null)
- cfg.by_click = colorSetting[7].toLowerCase() == 'true';
- }
- }
- }
- function applySettings() {
- setScroll(false);
- setSPSize(false);
- setScrollInt(false);
- setByClick();
- gdb('main').style.font=Math.round(cfg.step*0.8)+"px/"+cfg.step+"px "+cfg.fontfamily;
- gdb('clrdiv2').style.fontSize=Math.round(cfg.step*0.8)+'px';
- setColors();
- }
- function parseQuery(qry) {
- var params = {};
- var a = qry.split('&');
- for (var i = 0; i < a.length; i++) {
- var b = a[i].split('=');
- params[decodeURIComponent(b[0])] = decodeURIComponent(b[1]);
- }
- return params;
- }
- function objectEquals(obj1, obj2) {
- for (var i in obj1) {
- if (obj1.hasOwnProperty(i)) {
- if (!obj2.hasOwnProperty(i)) return false;
- if (obj1[i] != obj2[i]) return false;
- }
- }
- for (var i in obj2) {
- if (obj2.hasOwnProperty(i)) {
- if (!obj1.hasOwnProperty(i)) return false;
- if (obj1[i] != obj2[i]) return false;
- }
- }
- return true;
- }
- function checkRedirect() {
- if (typeof doRedirect == 'string' && doRedirect != '') {
- var settings = JSON.stringify(cfg);
- window.location.href = doRedirect + '?sets=' + btoa(settings) + '&' + window.location.search.substr(1);
- return true;
- }
- var qry = location.search.substr(1);
- var params = parseQuery(qry);
- if ('sets' in params) {
- var settings = atob(params.sets);
- var newCfg = JSON.parse(settings);
- if (objectEquals(cfg, getDefaultSettings())) {
- cfg = newCfg;
- saveSettings();
- applySettings();
- }
- var qry = location.search.substr(1);
- var url = qry.split('url=')[1] || '';
- if (url != '')
- window.location.href = siteroot + '?url=' + url;
- else
- window.location.href = siteroot;
- return true;
- }
- return false;
- }
- function onLoa() {
- DOM = document.getElementById;
- Netscape4 = document.layer;
- Netscape6 = Mozilla = (navigator.appName == "Netscape") && DOM;
- Netscape7 = navigator.userAgent.indexOf("Netscape/7") >= 0;
- Opera5 = window.opera && DOM;
- Opera6 = Opera5 && window.print;
- Opera7 = Opera5 && navigator.userAgent.indexOf("Opera 7") >= 0;
- Opera8 = navigator.userAgent.indexOf("Opera/8") >= 0;
- Opera9 = navigator.userAgent.indexOf("Opera/9") >= 0;
- IE = document.all && !Opera5;
- Firefox = navigator.userAgent.indexOf("Firefox") >= 0;
- is_storage = supports_html5_storage();
- bookloaded = false;
- handlerAdd(document,'keydown', key); //ëîâèì íàæàòèå êíîïêè
- if (window.addEventListener)
- window.addEventListener('DOMMouseScroll', wheel, false);
- window.onmousewheel = document.onmousewheel = wheel;
- sti = null;
- sttmh = null;
- stadc = null;
- blinkCount = 0;
- stblinkRB = null;
- gdb('main').onscroll = mainScroll;
- pageMoveTemp=0; //èíäèêàòîð ñêðûòîñòè ñòðåëî÷åê
- cfg = getDefaultSettings();
- loadSettings();
- applySettings();
- link = '';
- flink = '';
- percent = 0.00;
- gpa = 1;
- timer=300;
- doRepeatClick = 0;
- processClickTimeout = null;
- pcount = 1;
- clih = 0;
- pclih = 0;
- p_top = 0;
- tit='';
- if (checkRedirect())
- return;
- try {
- var qry = location.search.substr(1);
- var url = qry.split('url=')[1] || '';
- var furl = siteroot + 'f.php?url=' + url;
- gdb('loading').style.display='block';
- if (url.length > 0) {
- if ('ontouchstart' in document.documentElement) {
- handlerAdd(gdb('win'),'touchstart', mTouchStart); //ëîâèì òà÷ïàä
- handlerAdd(gdb('win'),'touchend', mTouchEnd); //ëîâèì òà÷ïàä
- } else {
- handlerAdd(gdb('win'),'mousedown', mClick); //ëîâèì íàæàòèå ìûøè
- handlerAdd(gdb('win'),'mouseup', mClickUp); //ëîâèì íàæàòèå ìûøè
- }
- }
- if(url.length > 0) {
- tit = url;
- var cached = loadValue('bpr-link-' + tit);
- if (cached != null && is_storage) {
- furl = siteroot + cached;
- }
- var cached_book = loadValue('bpr-cached-book-'+tit, 1);
- if (cached_book != null) {
- parseBook(cached_book, 1, 0);
- } else {
- var request = new XMLHttpRequest();
- request.open('GET', furl, true);
- request.onreadystatechange = function() {
- if (request.readyState == 4) {
- if(request.status == 200) {
- parseBook(request.responseText, cached, 1);
- } else {
- if (cached != null)
- reloadBook();
- else {
- tit = 'http error';
- loadBook('Îøèáêà çàãðóçêè êíèãè: ' + request.status + ' ' + request.statusText);
- }
- }
- }
- };
- request.send(null);
- }
- } else {
- loadBook(gdb('dop').innerHTML + gdb('leg').innerHTML);
- bookloaded = false;
- setTop(0);
- gdb('top100').style.display = 'none';
- gdb('id_add').style.height = (cfg.step - gdb('main').scrollHeight%cfg.step) + 'px';
- gdb('book').focus();
- }
- } catch (e) {
- tit = '';
- loadBook('Îøèáêà çàãðóçêè êíèãè: ' + e.message);
- }
- showTime();
- }
|