Skip to content

Instantly share code, notes, and snippets.

@sokcuri
Last active July 27, 2017 23:49
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sokcuri/7520d4d51cf197ccba899fb1045317a2 to your computer and use it in GitHub Desktop.
Save sokcuri/7520d4d51cf197ccba899fb1045317a2 to your computer and use it in GitHub Desktop.
Calculate and Show ServerTime (Tested Chrome)
function e(){if(typeof clocks!='undefined')return;var sokcuri="Sokcuri ServerTime";var url="https://gist.github.com/";var div=document.createElement('div');div.id="clocks";div.style.position='fixed';div.style.width='100%';div.style.top='0';div.style.height='150';div.style.pointerEvents='none';div.style.backgroundColor='rgba(200, 200, 200, 0.4)';div.innerHTML='서버시간을 얻어오는 중..';div.style.zIndex='99999';div.style.fontSize='40px';if(document.getElementsByTagName('body').length){document.body.appendChild(div);}else{document.head.outerHTML+=div.outerHTML;} function leadingZeros(n,digits){var zero='';n=n.toString();if(n.length<digits){for(i=0;i<digits-n.length;i++)zero+='0';} return zero+n;} var sec;var curr;var curr_sys;var cont=true;var nget=0;function getsrvTime(){delay=0;if(nget>=200) {clocks.innerHTML="서버시간을 얻어오는데 실패했습니다";return 0;} if(window.XMLHttpRequest){var req=new XMLHttpRequest();req.open('HEAD',window.location.href.toString()+'?&_='+new Date().getTime(),true);req.setRequestHeader("Content-Type","text/html");req.onreadystatechange=(e)=>{if(!cont)return;var st=req.getResponseHeader("Date");var today=new Date(st);if(typeof sec!='undefined'&&today.getSeconds()!=sec){curr_sys=Date.now();curr=today;console.info('fixed clock');cont=false;} sec=today.getSeconds();};req.send('');if(cont)setTimeout(getsrvTime,20);nget++;}};function setClockTxt(){var xdate=new Date(Date.parse(curr)+Date.now()-curr_sys);if(typeof curr!='undefined')clocks.innerHTML="<h1 style='font-size: 40px !important;'>"+leadingZeros(xdate.getHours(),2)+":"+leadingZeros(xdate.getMinutes(),2)+":"+leadingZeros(xdate.getSeconds(),2)+"."+leadingZeros(xdate.getMilliseconds(),3)+"</h1>";var interval=setTimeout(setClockTxt,10);} getsrvTime();setClockTxt();} e();
@sokcuri
Copy link
Author

sokcuri commented Aug 19, 2016

크롬 전용입니다. Raw를 클릭하고 내용을 복사한 다음 주소창에 javascript: 를 입력하고 붙여넣기하세요

@Guaseon
Copy link

Guaseon commented Aug 19, 2016

파이어폭스에서도 잘 되는데, 주소창에서 실행하는건 안되구 콘솔에서 해야댐

@sokcuri
Copy link
Author

sokcuri commented Aug 19, 2016

n0itanir // (수정) https://plus.google.com/+%EC%B5%9C%EB%AA%85%EC%88%9C/posts/TmMKedUzggo 파이어폭스에서는 보안상 이유때문에 주소창 복붙 스크립트가 안된다고 함...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment