ElEditors, Interface administrators, Administrators
70,975
edits
No edit summary |
No edit summary |
||
Line 3: | Line 3: | ||
if (!timer) return; | if (!timer) return; | ||
var bosses = { | |||
boss1: { | |||
EU: { | |||
href: '/w/Titan\'s Grotto', | |||
img: '/wiki/images/8/84/13-5Button.png' | |||
}, | |||
NA: { | |||
href: '/w/The Great Steel Wall', | |||
img: '/wiki/images/2/22/20-4Button.png' | |||
} | |||
}, | |||
boss2: { | |||
href: '/w/Plegas\'s Labyrinth', | href: '/w/Plegas\'s Labyrinth', | ||
img: '/wiki/images/1/17/17-3Button.png' | img: '/wiki/images/1/17/17-3Button.png' | ||
} | } | ||
} | } | ||
Line 74: | Line 27: | ||
} | } | ||
var | var boss1_hours = []; | ||
var i = 1; | var i = 1; | ||
while (i < 24) { | while (i < 24) { | ||
boss1_hours.push(i); | |||
i += i % 2 === 0 ? 3 : 1; | i += i % 2 === 0 ? 3 : 1; | ||
} | } | ||
var status = { | var status = { | ||
NA: { | NA: { | ||
boss1: true, | |||
boss2: true | |||
}, | }, | ||
EU: { | EU: { | ||
boss1: true, | |||
boss2: true | |||
} | } | ||
} | } | ||
Line 110: | Line 61: | ||
hourNow = date1.getHours(); | hourNow = date1.getHours(); | ||
var current = []; | var current = []; | ||
if ( | if (boss1_hours.includes(hourNow) && status[server].boss2) { | ||
status[server]. | status[server].boss1 = true; | ||
status[server]. | status[server].boss2 = false; | ||
current[server] = ' | current[server] = 'boss1'; | ||
} else if (! | } else if (!boss1_hours.includes(hourNow) && status[server].boss1) { | ||
status[server]. | status[server].boss1 = false; | ||
status[server]. | status[server].boss2 = true; | ||
current[server] = ' | current[server] = 'boss2'; | ||
} | } | ||
var currBoss = current[server]; | |||
var currBossData = bosses[currBoss].href ? bosses[currBoss] : bosses[currBoss][server]; | |||
var timer_img = $('.boss-timer-' + server + ' .boss-timer-image img'); | var timer_img = $('.boss-timer-' + server + ' .boss-timer-image img'); | ||
timer_img.attr('srcset', | timer_img.attr('srcset', currBossData.img).attr('src', currBossData.img); | ||
$('.boss-timer-' + server + ' .boss-timer-image a').attr('href', | $('.boss-timer-' + server + ' .boss-timer-image a').attr('href', currBossData.href); | ||
$('.boss-timer-' + server + ' .boss-timer-text').text( | var localizationID = currBoss + 'localization-' + server; | ||
var localization = $(currBossData[localizationID]).text(); | |||
if (!localization) { | |||
localization = $(currBossData[localizationID.replace(server, 'NA')]).text(); | |||
} | |||
$('.boss-timer-' + server + ' .boss-timer-text').text(localization); | |||
} | } | ||
updateDungeon(); | updateDungeon(); | ||
Line 159: | Line 117: | ||
$('.boss-timer img').css('display', 'inline-block'); | $('.boss-timer img').css('display', 'inline-block'); | ||
function isApple() { | if (isApple()) $('.boss-timer').hide(); | ||
}); | |||
function isApple() { | |||
return [ | |||
'iPad Simulator', | |||
'iPhone Simulator', | |||
'iPod Simulator', | |||
'iPad', | |||
'iPhone', | |||
'iPod' | |||
].includes(navigator.platform) | |||
// iPad on iOS 13 detection | |||
|| (navigator.userAgent.includes("Mac")) | |||
} | |||
function msToTime(s) { | |||
s = parseInt(s); | |||
// Pad to 2 or 3 digits, default is 2 | |||
function pad(n, z) { | |||
z = z || 2; | |||
return ('00' + n).slice(-z); | |||
} | } | ||
var ms = s % 1000; | |||
s = (s - ms) / 1000; | |||
var secs = s % 60; | |||
s = (s - secs) / 60; | |||
var mins = s % 60; | |||
var hrs = (s - mins) / 60; | |||
return pad(hrs) + ':' + pad(mins) + ':' + pad(secs) | |||
} | |||
Date.prototype.addHours = function (h) { | |||
this.setTime(this.getTime() + (h * 60 * 60 * 1000)); | |||
return this; | |||
} | |||
Date.prototype.addMinutes = function (m) { | |||
this.setTime(this.getTime() + (m * 60 * 1000)); | |||
return this; | |||
} | |||
Date.prototype.addTime = function (ms) { | |||
this.setTime(this.getTime() + ms); | |||
return this; | |||
} | |||
function closestHigher(number, candidates) { | |||
var bestCandidate = Infinity; | |||
var higherCandidates = candidates.filter(function (candidate) { return candidate > number }); | |||
higherCandidates.forEach(function (candidate) { | |||
if (candidate < bestCandidate) bestCandidate = candidate; | |||
}); | |||
return bestCandidate; | |||
} | |||
}); | var getTimezoneOffset = (timeZone, date = new Date()) => { | ||
var tz = date.toLocaleString("en", { timeZone, timeStyle: "long" }).split(" ").slice(-1)[0]; | |||
var dateString = date.toString(); | |||
var offset = Date.parse(`${dateString} UTC`) - Date.parse(`${dateString} ${tz}`); | |||
return offset; | |||
} |