var $=function(id) { return document.getElementById(id); };
function IsJsonString(str) { try { JSON.parse(str); } catch(e) { return false; } return true; }
//var t,d=false;
//function selectText(e,x) {
function selectText() {
//clearTimeout(t);
//if(e.which==1) {
// switch(x) {
// case 1:
// d=true;
// t=setTimeout(function() { selectText(e,0); },200);
// break;
// case 2:
// if(d) {
if(document.selection) {
var range=document.body.createTextRange();
range.moveToElementText($('code'));
range.select();
} else if(window.getSelection) {
var range=document.createRange();
range.selectNode($('code'));
window.getSelection().addRange(range);
}
// }
// break;
// default:
// d=false;
// }
//}
}
var zT;
function zindex(id) {
clearTimeout(zT);
if(id=="chat") {
if($('text')) $('text').style.zIndex=9;
$(id).style.zIndex=10;
} else {
zT=setTimeout(function() {
if($('chat')) $('chat').style.zIndex=9;
$(id).style.zIndex=10;
},500);
}
}
var nShow;
function showNotification(nt,nc) {
var nc1=nc.substring(nc.indexOf("<b>")+3,nc.indexOf("</b>"));
var nc2=nc.substring(nc.indexOf("</b>")+12,nc.indexOf("<br>"));
nc2=nc2.replace(/<(a\s+.*?|\/a)>/g,'');
if(window.Notification && Notification.permission!=="denied") {
Notification.requestPermission(function(status) {
nShow=new Notification('Twily.info ('+nt+')', {
body: nc1+' '+nc2,
icon: '/favicon.ico'
});
});
nShow.close();
}
}
var n=0,fI,fT=false,fL=false;
window.addEventListener('message',function(event) {
data=event.data;
if(IsJsonString(data)) data=JSON.parse(data);
var title=document.title;
var link=document.createElement('link');
link.id="favicon";
link.type="image/x-icon";
link.rel="shortcut icon";
if(data[0]=="notify") {
if(!fL) {
fL=true;
fI=setInterval(function() {
fT=!fT;
if(fT) link.href="/favicon_red.ico";
else link.href="/favicon.ico";
document.getElementsByTagName('head')[0].removeChild($('favicon'));
document.getElementsByTagName('head')[0].appendChild(link);
},500);
}
if(title.substr(0,1)!="(") {
n=1;
} else {
n+=parseInt(data[1]);
title=title.substr(title.indexOf(" ")+1);
}
document.title="("+n+") "+title;
showNotification(n,data[2]);
} else {
clearInterval(fI);
fT=false;
fL=false;
link.href="/favicon.ico";
document.getElementsByTagName('head')[0].removeChild($('favicon'));
document.getElementsByTagName('head')[0].appendChild(link);
n=0;
if(title.substr(0,1)=="(") document.title=title.substr(title.indexOf(" ")+1);
}
});
window.addEventListener('scroll',function() {
if($('text')) {
var eT,wY;
eT=$('text').offsetTop;
eB=$('text').offsetTop+$('text').offsetHeight;
wY=window.pageYOffset;
wH=window.innerHeight;
if(wY>eT) {
$('top_arrow').style.display="block";
} else {
$('top_arrow').style.display="none";
}
if((wY+wH)<eB) {
$('bot_arrow').style.display="block";
} else {
$('bot_arrow').style.display="none";
}
}
});
var rzC;
function loadCmt(x,f) {
clearInterval(rzC);
//$(x).contentWindow.postMessage(f,'*');
rzC=setInterval(function() {
//$(x).style.height=0;
$(x).style.height=$(x).contentWindow.document.body.scrollHeight+"px";
},100);
}
function init() {
win_resize();
if(window.location.hash) {
setTimeout(function() {
var view=window.location.hash.substr(1);
if($(view)) {
$(view).scrollIntoView();
//alert(window.location.hash);
}
},100);
}
}
function win_resize() {
var winWidth=window.innerWidth;
var winHeight=window.innerHeight;
//alert(winWidth);
if(typeof smallscreen!=='undefined') {
if(winWidth<770) {
if(!smallscreen) {
var style=document.createElement('style');
style.type="text/css";
var styhtm="/* smallscreen css */";
styhtm+=".file, .dir { min-width: 64px; width: 64px; }";
styhtm+=".statsf { display: block; }";
styhtm+=".statsf2 { display: none; }";
styhtm+="#chat, #backdrop { width: 200px; }";
//styhtm+="#container { padding: 64px 8px; }";
styhtm+=".embed { width: calc(100% - 200px) !important; margin-left: 200px; padding: 64px 8px !important; }";
styhtm+="#dirbtn2 { display: none; }";
styhtm+="#dirbtn { display: block; }";
style.innerHTML=styhtm;
document.getElementsByTagName('head')[0].appendChild(style);
smallscreen=true;
if($('comment')) {
if($('comment').contentWindow) {
if(typeof $('comment').contentWindow.set_size==='function') {
$('comment').contentWindow.set_size('small');
}
}
}
}
} else {
if(smallscreen) {
var styles=document.getElementsByTagName('style');
for(var i=0;i<styles.length;i++) {
if(styles[i].innerHTML.indexOf('/* smallscreen css */')!=-1) {
styles[i].parentNode.removeChild(styles[i]);
break;
}
}
smallscreen=false;
if($('comment')) {
if($('comment').contentWindow) {
if(typeof $('comment').contentWindow.set_size==='function') {
$('comment').contentWindow.set_size('big');
}
}
}
}
}
}
}
var wrT;
window.onresize=function() {
clearTimeout(wrT);
wrT=setTimeout(function() { win_resize(); },100);
}
window.onscroll=function() {
currentScroll=window.scrollY;
}
function bodytouch() {
if(autoscrollOn) {
if(scrollSpeed<0) {
toggleScroll('Up');
} else if(scrollSpeed>0) {
toggleScroll('Down');
}
}
}
var aST;
var autoscrollOn=false;
var scrollSpeed=1.0;
var currentScroll=0;
function autoscroll() {
clearTimeout(aST);
if(autoscrollOn) {
currentScroll+=scrollSpeed;
window.scrollTo(0,currentScroll);
if(scrollSpeed<0) {
if(currentScroll+window.innerHeight<=0) {
toggleScroll('Up');
scrollSpeed=-1.0;
}
} else if(scrollSpeed>0) {
if(currentScroll+window.innerHeight>=$('container').scrollHeight) {
toggleScroll('Down');
scrollSpeed=1.0;
}
}
aST=setTimeout(function() { autoscroll(); },1000/60);
}
}
function toggleScroll(x="") {
var btnsel="";
var btnoth="";
var directionRunning=false;
currentScroll=window.scrollY;
if(x=="Up") {
//
btnsel="btnScrollU";
btnoth="btnScrollD";
$(btnoth).value="Down";
if(autoscrollOn && scrollSpeed<0) directionRunning=true;
if(scrollSpeed>0) scrollSpeed=0-scrollSpeed;
//scrollSpeed=-1.0;
} else if(x=="Down") {
//
btnsel="btnScrollD";
btnoth="btnScrollU";
$(btnoth).value="Up";
if(autoscrollOn && scrollSpeed>0) directionRunning=true;
if(scrollSpeed<0) scrollSpeed=Math.abs(scrollSpeed);
//scrollSpeed=1.0;
}
if(directionRunning) {
$(btnsel).value=x;
$('scrollSpeed').style.display="none";
autoscrollOn=false;
} else {
$(btnsel).value="Stop";
$('scrollSpeed').innerHTML=scrollSpeed;
$('scrollSpeed').style.display="inline-block";
autoscrollOn=true;
autoscroll();
}
}
var scrollSpeedInc=[0.2,0.4,0.8,1.6,2.4];
var scrollSpeedIdx=0;
var lastchangeSpeedX=0;
var sSIT;
function changeSpeed(x) {
var step=0.5;
if(autoscrollOn) {
//step=scrollSpeedInc[scrollSpeedIdx];
//console.log('x: '+x+' , step: '+step);
//if(lastchangeSpeedX==x) {
// if(scrollSpeedIdx<scrollSpeedInc.length-1) scrollSpeedIdx++;
// clearTimeout(sSIT);
// sSIT=setTimeout(function() {
// scrollSpeedIdx=0;
// },250);
//}
//
//lastchangeSpeedX=x;
step=1.0;
if(x==1) { // increaseA (+)
if(scrollSpeed>0) { // down active
if(scrollSpeed<1.0) step=0.1;
scrollSpeed=Math.round((scrollSpeed+step)*100)/100;
} else if(scrollSpeed<0) { // up active
if(scrollSpeed>-1.0) step=0.1;
scrollSpeed=Math.round((scrollSpeed-step)*100)/100;
}
} else if(x==-1) { // decrease (-)
if(scrollSpeed>0) { // down active
if(scrollSpeed<=1.0) step=0.1;
if((Math.round((scrollSpeed-step)*100)/100)>0) {
scrollSpeed=Math.round((scrollSpeed-step)*100)/100;
}
} else if(scrollSpeed<0) { // up active
if(scrollSpeed>=-1.0) step=0.1;
if((Math.round((scrollSpeed+step)*100)/100)<0) {
scrollSpeed=Math.round((scrollSpeed+step)*100)/100;
}
}
}
$('scrollSpeed').innerHTML=scrollSpeed;
}
}
function showBar() {
if($('control')) {
$('control').style.opacity="1";
}
}
function hideBar() {
if($('control')) {
$('control').style.opacity="0";
}
}
Top