< 사용자:Hsl0 | 연구소imported>Hsl0님의 2021년 7월 12일 (월) 17:47 판
mw.loader.using('ext.gadget.Tasker').then(function() {
registerRenderer(function createTimer() {
$('.timer').each(function() {
var timer = this;
var timestamp = $(this).data('timestamp');
var now = Math.floor(Date.now() / 1000);
var left = $(this).data('left');
var diff = now - timestamp;
registerTrigger(function() {
var hour, min, sec, interval;
var href = $(timer).find('a')[0];
if(href) href = href.href;
if(diff < left) {
left = new Date((left - diff) * 1000);
hour = left.getUTCHours();
min = left.getUTCMinutes();
sec = left.getUTCSeconds();
interval = setInterval(function() {
var str = '';
if(hour + min + sec) {
if(sec > 0) sec--;
else if(min > 0) {
min--;
sec = 59;
} else if(hour > 0) {
hour--;
min = 59;
sec = 59;
}
if(hour > 0) str += hour + ':';
str += (min < 10)? '0' + min + ':' : min + ':';
str += (sec < 10)? '0' + sec : sec;
timer.innerText = str;
} else {
timer.innerText = '00:00';
if(href) location.replace(href);
clearInterval(interval);
}
}, 1000);
} else if(href) location.replace(href);
});
});
});
});