rAthus icon

JavaScript timer live countdown to timestamp

rAthus | PRO | 05/17/23 09:56:37 AM UTC (Edited) | 0 ⭐ | 970 👁️ | Never ⏰ | []
JavaScript |

1.15 KB

|

None

|

0 👍

/

0 👎

// example : <span timer="578556600"></span>
 
function updateTimer($this) {
    var ts_timer = $this.attr('timer')*1;
    var ts_now = Math.round(Date.now()/1000);
    var s_total = Math.max(ts_timer-ts_now,0);
    var h = Math.floor(s_total/3600);
    var m = Math.floor((s_total-h*3600)/60);
    var s = s_total-h*3600-m*60;
    $this.html((h?h+':':'')+((h||m)?(h?('0'+m).slice(-2):m)+':':'')+((h||m)?('0'+s).slice(-2):s));
    if (!s_total) {
        var uid = $this.attr('uid')
        clearInterval(intervalTimer[uid]);
        if ((typeof(wheelState)=='undefined' || !wheelState) && !jQuery('#popup-akn-card-drawn').is(':visible') && !jQuery('#popup-akn-ad').is(':visible') && !jQuery('#popup-akn-recaptcha').is(':visible') && !jQuery('#popup-akn-auto-roll').is(':visible')) {
            jQuery('#updating-notice').stop(true).fadeTo(250,1);
            setTimeout(function() {
                location.reload();
            },1500);
        }
    }
}
var intervalTimer = {};
jQuery('[timer]').each(function() {
    var $this = jQuery(this);
    var uid = btoa(Math.random().toString()).substring(10,15);
    $this.attr('uid',uid);
    updateTimer($this);
    intervalTimer[uid] = setInterval(function() {
        updateTimer($this);
    },1000);
});
 

Comments