var $=function(id) { return document.getElementById(id); };
function IsJsonString(str) { try { JSON.parse(str); } catch(e) { return false; } return true; }
String.prototype.replaceAt=function(index,replacement) { return this.substr(0,index)+replacement+this.substr(index+replacement.length); }
function rndMinMax(min,max) { // min and max included
return Math.floor(Math.random()*(max-min+1)+min);
}
function b64Enc(str,s=1) {
var str=btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g,function(match,p1) {
return String.fromCharCode(parseInt(p1,16));
}));
if(s==0) str=str.replace(/\=/g,'');
return str;
}
function b64Dec(str) {
try {
return decodeURIComponent(Array.prototype.map.call(atob(str),function(c) {
return '%'+('00'+c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
} catch(e) {
return str;
}
}
//var remote="http://"+window.location.hostname+"/";
var myAjax;
var connectionout=0;
var ddDel=0;
var ddLatency=0;
async function ajaxThis(x,y,z,cb,l="") {
ddDel = new Date().getTime();
var xhr;
if(window.XMLHttpRequest) xhr=new XMLHttpRequest();
else xhr=new ActiveXObject("Microsoft.XMLHTTP");
xhr.onreadystatechange=function() {
if(xhr.readyState==4 && xhr.status==200) {
//alert(xhr.responseText);
//conlog('ajax res --> '+xhr.responseText);
//return xhr.responseText;
//console.log(xhr.responseText);
if(typeof cb==='function') {
cb(xhr.responseText);
}
//if(typeof getConStatus!=='undefined') {
// var pX=getConStatus('main');
// if(pX!=1) {
// var ddTes = new Date().getTime();
// ddLatency = ddTes - ddDel;
// setConStatus(1,'main');
// }
//}
connectionout=0;
} else {
if(connectionout>1) {
//var parentMsg=["newpagenote","You have lost connection with Analiestar chat for "+connectionout+" seconds!"];
//parent.postMessage(JSON.stringify(parentMsg),'*');
//nextpushnote=Date.now()+5000; // 5 sec notification timer
//if(typeof getConStatus!=='undefined') {
// var pX=getConStatus('main');
// if(pX!=3) {
// var ddTes = new Date().getTime();
// ddLatency = ddTes - ddDel;
// setConStatus(3,'main');
// }
//}
}
connectionout++;
}
}
//conlog('ajax out --> '+x);
//xhr.open("POST",l+"/ajax.php",true);
xhr.open("POST","./ajax.php",true);
//xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xhr.setRequestHeader("Content-Type","application/json");
//xhr.send("setting="+x+"&value="+y+"&key="+z);
xhr.send(JSON.stringify({setting: x, value: y, key: z}));
}
function ucfirst(str) {
return str.charAt(0).toUpperCase()+str.slice(1);
}
var afsT;
function animateFadeStatus(id,x) {
clearTimeout(afsT);
if(x>0) {
x--;
if($(id)) {
$(id).style.opacity=x/100;
}
afsT=setTimeout(function() { animateFadeStatus(id,x); },1000/30);
}
}
var wFPS=30;
var deg=0;
var deg2=0;
var rad=Math.PI/180;
var aWT;
var aWinit=false;
function animateWallpapers() {
clearTimeout(aWT);
if(!aWinit) {
if(deg2>180) deg2=0; // reset for rotateY
else deg2=180; // start flipped for even
aWinit=true;
}
var scaX=(Math.sin(deg * rad) * .25) + .25;
var scaY=(Math.cos(deg * rad) * .25) + .25;
//var scaY=.5-scaX;
var scaR=(Math.cos((((deg2-90) * 2)) * rad) * 1) + 1;
deg++;
deg2+=1*(scaR)+.5;
//deg2++;
while(deg>=360) deg-=360;
while(deg2>=360) deg2-=360;
//console.log("scaX: "+scaX+", scaY: "+scaY);
$('cal_photo').style.transform="rotateY("+(deg2)+"deg) scale("+(1+(scaR*5))+")";
//$('cal_photo').style.transform="rotateY("+(deg2)+"deg) scale("+(1+(scaR*.5))+")";
//$('cal_photo').style.transform="scale("+(1+(Math.abs(scaR)*.5))+")";
//$('cal_photo').style.transform="rotateY("+deg2+"deg) rotateX("+(deg2)+"deg)";
$('bg').style.transform="scaleX("+(1+scaX)+") scaleY("+(1+scaY)+")";
if(btn2on) {
aWT=setTimeout(function() { animateWallpapers(); }, 1000/wFPS);
} else {
aWinit=false;
}
}
function setTheme() {
var noteclass="";
if(!btnwrapon) noteclass="nowrap ";
if(btn1on) {
if(btn2on) {
noteclass+="note_color_light_blur";
} else {
noteclass+="note_grey_light";
}
document.body.style.background="#ffe1b4";
} else {
if(btn2on) {
noteclass+="note_color_blur";
} else {
noteclass+="note_grey";
}
document.body.style.background=""; // reset
}
$('notes').className=noteclass;
}
var wpInit=false;
function setWallpaper() {
var noteclass="";
if(!btnwrapon) noteclass="nowrap ";
if(btn2on && imgCal!="" && imgBG!="") {
$('cal_photo').style.background="url('"+preloadCal.src+"') no-repeat center center transparent";
$('cal_photo').style.backgroundSize="cover";
$('cal_photo').setAttribute('data-src',preloadCal.src);
$('bg').style.background="url('"+preloadBG.src+"') no-repeat center center transparent";
$('bg').style.backgroundSize="cover";
$('cal_photo').style.pointerEvents="";
$('cal_photo').style.display="block";
if(btn1on) {
noteclass+="note_color_light_blur";
} else {
noteclass+="note_color_blur";
}
$('calc_wrap').parentNode.className="padshadow calc_color";
} else {
$('cal_photo').style.background="";
$('bg').style.background="";
$('cal_photo').style.pointerEvents="none";
$('cal_photo').style.display="none";
if(btn1on) {
noteclass+="note_grey_light";
} else {
noteclass+="note_grey";
}
$('calc_wrap').parentNode.className="padshadow calc_grey";
}
$('notes').className=noteclass;
if(!wpInit) {
$('cal_photo').addEventListener('click',function(e) {
window.open($('cal_photo').getAttribute('data-src'), '_blank');
});
wpInit=true;
}
}
var imgBG="";
var imgCal="";
//var vidCal="";
//var savedVol=50;
var preloadBG=null;
var preloadCal=null;
function loadwp() {
ajaxThis("newwall",'','',function(data) {
//console.log(data);
console.log("loadwp newwall");
if(IsJsonString(data)) {
var obj=JSON.parse(data);
// populate imgBG and imgCal, then setWall?
imgBG=obj['img1'];
imgCal=obj['img2'];
//vidCal=obj['vid1'];
var imgPath="./_userdata/wallpapers/";
//var imgPath="../s/stuff/pony-clop/";
if(preloadBG==null) {
preloadBG=new Image();
}
preloadBG.onload=function() {
console.log("BG image preloaded stored in memory");
}
preloadBG.src=imgPath+imgBG;
if(preloadCal==null) {
preloadCal=new Image();
}
preloadCal.onload=function() {
console.log("Cal imag preloaded stored in memory");
}
preloadCal.src=imgPath+imgCal;
setWallpaper();
//if(vidCal!="") {
// $('video_frame').innerHTML="<video id=\"vid1\" loop controls onvolumechange=\"saveVol();\"><source src=\"https://twily.info/s/stuff/PMV/"+vidCal+"\" type=\"video/mp4\" /></video>";
// $('vid1').volume=savedVol/100;
//}
} else {
console.log("error: broken json strig in newwall");
}
});
}
var noteFocus=false;
function focusTxt(x) {
if(btn2on) {
var noteclass="";
if(!btnwrapon) noteclass="nowrap ";
if(x==1) {
if(btn1on) {
noteclass+="note_color_light";
} else {
noteclass+="note_color";
}
noteFocus=true;
} else {
if(btn1on) {
noteclass+="note_color_light_blur";
} else {
noteclass+="note_color_blur";
}
noteFocus=false;
}
$('notes').className=noteclass;
} else {
if(x==1) {
noteFocus=true;
} else {
noteFocus=false;
}
}
}
var objcomp={
wplockmod: -2,
dblogmod: -2
};
var synctimestore=-1;
function synctime() {
ajaxThis('synctime','','',function(data) {
//console.log("synctime data="+data);
if(data!="failure") {
if(IsJsonString(data)) {
var obj=JSON.parse(data);
//servertime=parseInt(data);
tmpservertime=obj['ts']; // synctime
synctimestore=tmpservertime;
var updateWallpaperTrig=false;
var updateNotesTrig=false;
if(obj['wplocktime']<0 || obj['ts']>obj['wplocktime']) { // or unlock time~
// update wallpaper
updateWallpaperTrig=true;
} else if(objcomp['wplockmod']!=-2) {
if(objcomp['wplockmod']!=obj['wplockmod']) {
// update wallpaper
updateWallpaperTrig=true;
}
}
if(objcomp['dblogmod']!=-2) {
if(objcomp['dblogmod']!=obj['dblogmod']) {
// update scannotes
updateNotesTrig=true;
}
}
objcomp['wplockmod']=obj['wplockmod'];
objcomp['dblogmod']=obj['dblogmod'];
// for live update sync on every tick
if(updateNotesTrig) {
console.log("updateNotesTrig");
if(typeof selTime==='object') { // in main
scannotes(selTime.year,(selTime.month+1));
}
}
if(updateWallpaperTrig) {
console.log("updateWallpaperTrig");
loadwp();
}
}
} else {
console.log("error: couldn't sync time server");
}
});
}
document.addEventListener('keydown',function(event) { // calculator input listener
if(!noteFocus) {
//console.log('Key pressed:', event.key);
//console.log('Physical key code:', event.code);
var calcTrig=false;
switch(event.key) {
case "0":
press_btn0();
calcTrig=true;
break;
case "1":
press_btn1();
calcTrig=true;
break;
case "2":
press_btn2();
calcTrig=true;
break;
case "3":
press_btn3();
calcTrig=true;
break;
case "4":
press_btn4();
calcTrig=true;
break;
case "5":
press_btn5();
calcTrig=true;
break;
case "6":
press_btn6();
calcTrig=true;
break;
case "7":
press_btn7();
calcTrig=true;
break;
case "8":
press_btn8();
calcTrig=true;
break;
case "9":
press_btn9();
calcTrig=true;
break;
case "/":
press_btnDiv();
calcTrig=true;
break;
case "*":
press_btnMul();
calcTrig=true;
break;
case "-":
press_btnSub();
calcTrig=true;
break;
case "+":
press_btnAdd();
calcTrig=true;
break;
case "%":
press_btnPer();
calcTrig=true;
break;
case "(":
case ")":
press_btnPar();
calcTrig=true;
break;
case ".":
case ",":
press_btnDot();
calcTrig=true;
break;
case "Enter":
press_btnEqual();
calcTrig=true;
break;
case "Backspace":
press_btnBackspace();
calcTrig=true;
break;
case "Delete":
press_btnAC();
calcTrig=true;
break;
default:
}
if(calcTrig) {
event.preventDefault();
}
}
});
function savenote(val) {
let name=$('selDate').getAttribute('data-date');
//console.log("saving notes: "+name);
let obj={
name: name,
synctime: synctimestore,
};
//ajaxThis('savenote',b64Enc(val),name,function(data) {
ajaxThis('savenote',b64Enc(val),b64Enc(JSON.stringify(obj)),function(data) {
//console.log("savenote data="+data);
let ds=data.split(":");
//synctimestore=parseInt(ds[1]);
if(ds[0]=="savednote" || ds[0]=="mergednote") {
clearTimeout(afsT);
$('notestatus').style.opacity=1;
animateFadeStatus('notestatus',100);
if(typeof selTime==='object') { // in main
scannotes(selTime.year,(selTime.month+1));
}
if(ds[0]=="mergednote") {
//loadnotes(selTime.year+"-"+selTime.month+" "+noteDay); // already does via scannotes
console.log('merged note');
} else {
console.log('overwrote note');
}
} else {
console.log("savenote data="+data);
}
});
}
function scannotes(year,month) {
//console.log("scannotes for '"+year+"-"+month+"'");
ajaxThis('scannote',month,year,function(data) {
//console.log("scannotes data="+data);
if(IsJsonString(data)) {
let list=JSON.parse(data);
synctimestore=list[0];
if(typeof selTime==='object') { // in clock
for(let i=0;i<selTime.tday;i++) { // all days this month
let elem="m_cal_day_"+selTime.month+"_"+(i+1);
if($(elem)) {
$(elem).style.background="";
}
}
}
for(let i=1;i<list.length;i++) {
let item=list[i].split("-");
let elem="m_cal_day_"+(parseInt(item[1])-1)+"_"+item[2];
if($(elem)) {
$(elem).style.background="rgba(255,0,150,.5)";
}
// selected note is updated remote, update local (via synctime)
if(item[1]==selTime.month && item[2]==noteDay) {
loadnotes(selTime.year+"-"+selTime.month+" "+noteDay);
}
}
}
});
}
function loadnotes(val) {
console.log("loading note: "+val);
ajaxThis('loadnote',val,'',function(data) {
//console.log("loadnotes data="+data);
$('notes').value=b64Dec(data);
});
}
function loadSettings() {
ajaxThis("loadsettings",'','',function(data) {
console.log("loadsettings data="+data);
if(IsJsonString(data)) {
var obj=JSON.parse(data);
if(obj.hasOwnProperty("lightmode")) {
if(obj['lightmode']==1) {
// set on at start (off default)
if(!btn1on) btntog1(0);
}
}
if(obj.hasOwnProperty("imagemode")) {
if(obj['imagemode']==1) {
// set on at start (off default)
if(!btn2on) btntog2(0);
}
}
if(obj.hasOwnProperty("wrapon")) {
if(obj['wrapon']==0) {
// set off at start (on default)
if(btnwrapon) btntogwrap(0);
}
}
}
});
}
function saveSetting(val="",key="") {
ajaxThis('savesetting',val,key,function(data) {
console.log("savesetting data="+data);
});
}
var btn1on=false;
function btntog1(s=1) {
btn1on=!btn1on;
if(btn1on) {
$('btnball1').className="btnball on";
} else {
$('btnball1').className="btnball";
}
setTheme();
if(s==1) {
saveSetting("lightmode",(btn1on)?"1":"0");
}
}
var btn2on=false;
function btntog2(s=1) {
btn2on=!btn2on;
if(btn2on) {
$('btnball2').className="btnball on";
} else {
$('btnball2').className="btnball";
}
setWallpaper();
animateWallpapers(); // disable animation here
if(s==1) {
saveSetting("imagemode",(btn2on)?"1":"0");
}
}
var btnwrapon=true;
function btntogwrap(s=1) {
btnwrapon=!btnwrapon;
var noteclass="";
if(btnwrapon) {
$('btnballwrap').className="btnball on";
if(btn2on) {
if(btn1on) {
noteclass="note_color_light_blur";
} else {
noteclass="note_color_blur";
}
}
} else {
$('btnballwrap').className="btnball";
noteclass="nowrap ";
if(btn2on) {
if(btn1on) {
noteclass+="note_color_light_blur";
} else {
noteclass+="note_color_blur";
}
}
}
$('notes').className=noteclass;
if(s==1) {
saveSetting("wrapon",(btnwrapon)?"1":"0");
}
}
var anaS=`%c
,/#(,
./%%%%(,
.*#%%%%#,
,/#%%%%%%*
./%%%%%%%%%%*
*%%%%%%%%%%%%/.
,#%%%%%%%%%%%%(.
./%%%%#*/%%%%%%/. /%(,*(
./#%%%%/. ./%%#/,,%%%%%%%%%%%/
*(%%##%%%%%%%%%%%%%%(,./%%%%%%#*.
*#%%#* ../%%%%#/. ./%%%%/.
.*(%%#*. ./%%%%#, *%%%%(,
.*#%%###%%%%%%#/, .*%%%%#, .*%%%%#, *
./#%%/.*(%%(*. *%%%%%%%%/.,#%%%%* *
.(%%%%%%%%%%/, ,*//*, ,
`
function printascii() { setTimeout(console.log.bind(console,anaS,'background: #2a1e27; color: #fbbb57;')); }
printascii();
Top