Skip to content

Instantly share code, notes, and snippets.

@lizard-isana
Created May 25, 2012 01:15
Show Gist options
  • Save lizard-isana/2785236 to your computer and use it in GitHub Desktop.
Save lizard-isana/2785236 to your computer and use it in GitHub Desktop.
Bookmarklet: display the day number of the year
//1月1日からの経過日をブラウザの右下隅に表示するブックマークレット
javascript:(function(){
function fill(num){if(num<10){return "0"+num}else{return num}}
try{
document.body.removeChild(w);
}catch(e){
w=document.createElement('div');
var ws=w.style;
ws.position='fixed';
ws.zIndex='1000';
ws.bottom='0';
ws.right='0';
ws.padding='5px';
ws.width='200px';
ws.height='auto';
ws.color='red';
ws.textAlign='right';
document.body.appendChild(w);
setInterval(function(){
var d = new Date();
var d0 = new Date(Date.UTC(d.getFullYear()-1,11,31,0,0,0));
var doy =((d.getTime()-d.getTimezoneOffset() - d0.getTime())/(1000*60*60*24)).toFixed(8);
w.innerHTML=doy+'<br>'+d.getUTCFullYear() + "/"+Math.floor(doy)+"/" + fill(d.getUTCHours())+":" + fill(d.getMinutes())+":"+fill(d.getSeconds());
},100)
}
})()
//Compressed
/*
javascript:(function(){function fill(num){if(num<10){return"0"+num}else{return num}}try{document.body.removeChild(w);}catch(e){w=document.createElement('div');var ws=w.style;ws.position='fixed';ws.zIndex='1000';ws.bottom='0';ws.right='0';ws.padding='5px';ws.width='200px';ws.height='auto';ws.color='red';ws.textAlign='right';document.body.appendChild(w);setInterval(function(){var d=new Date();var d0=new Date(Date.UTC(d.getFullYear()-1,11,31,0,0,0));var doy=((d.getTime()-d.getTimezoneOffset()-d0.getTime())/(1000*60*60*24)).toFixed(8);w.innerHTML=doy+'<br>'+d.getUTCFullYear()+"/"+Math.floor(doy)+"/"+fill(d.getUTCHours())+":"+fill(d.getMinutes())+":"+fill(d.getSeconds());},100)}})()
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment