Widget:TimerJS
Материал из Guild Wars 2 wiki
<script>
function timeFormat(time) { var hours = parseInt(time / 3600, 10) % 24; var minutes = parseInt(time / 60, 10) % 60; var seconds = time % 60; return (hours < 10 ? "0" + hours : hours) + ":" + (minutes < 10 ? "0" + minutes : minutes) + ":" + (seconds < 10 ? "0" + seconds : seconds); } var interval = setInterval(function() { var now = new Date(); // leave date portion alone, but convert time portion to UTC now.setHours(now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds()); $("[id^=timer]").each(function(index) { var timerId = $(this).attr('id').substring(5); var target = new Date(); // leave date portion alone and set time portion to exact spawn time in UTC target.setHours(0, timerId * 15, 0, 0); var diff = target.getTime() - now.getTime(); var diffMinutes = diff/1000/60; // make sure everything except current event is in terms of the next 24 hours if (diffMinutes <= -15) { diffMinutes += 1440; diff += 86400000; } if (diffMinutes > 60) { $(this).html(); $(this).closest('tr').css('background-color', ); $(this).closest('tr').hide() } else if (diffMinutes <= 0) { $(this).html('Active'); $(this).closest('tr').css('background-color', 'yellow'); $(this).closest('tr').show() } else if (diffMinutes <= 15) { $(this).html(timeFormat(Math.floor(diff / 1000))); $(this).closest('tr').css('background-color', 'lightblue'); $(this).closest('tr').show() } else if (diffMinutes <= 60) { $(this).html(timeFormat(Math.floor(diff / 1000))); $(this).closest('tr').css('background-color', ); $(this).closest('tr').show() } }); }, 100);
</script>