Monday 12 April 2010

Star Wars: The Old Republic JavaScript countdown timer

This is a Javascript for counting down hours minutes seconds for the game Star Wars The Old Republic. The script automatically updates every second. To use add this script in head tag of html. Maybe you can modify to make countdown timer for other games.
<script>
var one_second = 1000;
var one_minute = 1000 * 60;
var one_hour = 1000 * 60 * 60;
var one_day = 1000 * 60 * 60 * 24;
var one_month = 1000 * 60 * 60 * 24 * 30;
var one_year = 1000 * 60 * 60 * 24 * 30 * 12;

function moo()
{
alert("wowowowow");
}

function updated()
{
displayage(2010, 11, 26, 'days', 0, 'rounddown')
setInterval("displayage(2010, 11, 26, 'days', 0, 'rounddown')",1000);
//setInterval("moo()",5000)
//displayage(2010, 11, 26, 'days', 0, 'rounddown');
//moo();
}



function displayage(yr, mon, day, unit, decimal, round) {
today = new Date();
var pastdate = new Date(yr, mon - 1, day);

var countunit = unit;
var decimals = decimal;
var rounding = round;

finalunit = (countunit == "days") ? one_day : (countunit == "months") ? one_month : one_year;
decimals = (decimals <= 0) ? 1 : decimals * 10;

if (rounding == "rounddown") {
var days = Math.floor((today.getTime() - pastdate.getTime()) / (finalunit) * decimals) / decimals;
days = Math.abs(days);
//document.write(num + " " + countunit)
var jjgjk = document.getElementById('iddays')
document.getElementById('iddays').textContent = days;


if(countunit == 'days')
{
var hours = Math.floor(((pastdate.getTime()-today.getTime())%(finalunit))/one_hour);
//document.write(" " + hours + " " + "hours ");
document.getElementById('idhours').textContent = hours;

var minutes = Math.floor(((pastdate.getTime()-today.getTime())%(one_hour))/one_minute);
//document.write(minutes + " " + "minutes ");
document.getElementById('idminutes').textContent = minutes;

var seconds = Math.floor(((pastdate.getTime()-today.getTime())%(one_minute))/one_second);
//document.write(seconds + " " + "seconds");
document.getElementById('idseconds').textContent = seconds;

}
}
}


</script>

Then in the html body add the following to call the javascript and present the data.

Time to release date: Star Wars The Old Republic 26/11/2010 or <span id="iddays">boo</span> days
<span id="idhours"></span> hours <span id="idminutes"></span> minutes <span id="idseconds"></span><br/>

<script>updated()</script>

No comments:

Post a Comment