User:Shoyrukon/common.js

(function (window, $) {    'use strict';     var counter,        count;     function f(d) {        d = new Date(d);            // get day of week            // 0 - Sunday, 1 - Monday, etc.        var day = d.getUTCDay,            diff = new Date;        // subtract weekday from monthday        diff.setDate(d.getDate - day);        // hours, mins, secs, millisecs        diff.setUTCHours(5, 0, 0, 0);        // 7 hours = 25200 secs        //.valueOf converts to unix time        return 25200 - ((Math.floor(Math.abs(d.valueOf - diff.valueOf) / 1000)) % (25200));    }    function timer {        // implicit convert to unix time        count--;        if (count % 10 === 0) {            count = f(new Date);        }        // 7 hours - 10 mins = 24600 secs        if (count >= 24600) {            window.clearInterval(counter);            // @todo find a way to make the time for this variable // so we can set it once and not iterate through this every minute counter = window.setInterval(reset, 60000); $('#wb-countdown').text("Active"); $('#wb-timer').css("background", "#5f5"); $('#wb-active').text("Wilderness Warbands is currently"); return; }       $('#wb-timer').css("background", "#ff5"); $('#wb-active').text("The next warband begins in"); var hours = Math.floor(count / (3600)), mins = Math.floor((count % (3600)) / 60), seconds = count % 60; $('#wb-countdown').html(           hours + ":" +                (mins.toString.length === 1 ? "0" : "") + mins + ":" +                   (seconds.toString.length === 1 ? "0" : "") + seconds       ); }   function reset { window.clearInterval(counter); count = f(new Date); counter = window.setInterval(timer, 1000); }   $(reset); }(this, jQuery));