Skip to content

Instantly share code, notes, and snippets.

@thatshaman
Created January 26, 2017 19:08
Show Gist options
  • Save thatshaman/00e07909d83c6b54c82470d66fda5df7 to your computer and use it in GitHub Desktop.
Save thatshaman/00e07909d83c6b54c82470d66fda5df7 to your computer and use it in GitHub Desktop.
Mini Guild Wars 2 World Boss Timer
<!DOCTYPE html>
<html>
<head>
<title>Mini Guild Wars 2 World Boss Timer</title>
<style>
body {
font-family: "Lucida Console", Monaco, monospace;
font-size: 10pt;
}
#output {
display: table;
}
#output .row {
display: table-row;
}
#output .cell {
display: table-cell;
padding: 4px;
border: solid 1px #cccccc;
}
#output .remaining {
color: #30a0ea;
}
#output .timestamp {
text-align: right;
color: #aa2b2b;
}
</style>
<script>
// Bosstimer Class
function BossTimer() {
var self = this;
// List of events (UTC)
self.events = {
"Taidha Covington": { repeat: { start: [0, 00], interval: 3 } },
"Frozen Maw": { repeat: { start: [0, 15], interval: 2 } },
"Megadestroyer": { repeat: { start: [0, 15], interval: 3 } },
"Fire Elemental": { repeat: { start: [0, 45], interval: 2 } },
"The Shatterer": { repeat: { start: [1, 00], interval: 3 } },
"Jungle Wurm": { repeat: { start: [1, 15], interval: 2 } },
"Modniir Ulgoth": { repeat: { start: [1, 30], interval: 3 } },
"Shadow Behemoth": { repeat: { start: [1, 45], interval: 2 } },
"Fire Elemental": { repeat: { start: [2, 45], interval: 2 } },
"Tequatl": { fixed: [[0, 00], [3, 00], [7, 00], [16, 00], [19, 00]] },
"Claw of Jormag": { fixed: [[2, 30], [5, 30], [8, 30], [11, 30], [14, 30], [17, 30], [20, 30], [23, 30]] },
"Evolved Jungle Wurm": { fixed: [[4, 00], [8, 00], [12, 30], [17, 00], [20, 00]] },
"Karka Queen": { fixed: [[2, 00], [10, 30], [15, 00], [18, 00], [23, 00]] },
"Golem Mark II": { fixed: [[2, 00], [8, 00], [11, 00], [14, 00], [17, 00], [20, 00], [23, 00]] },
}
// Generate schedule
self.schedule = [];
Object.keys(self.events).forEach(function (key, index) {
// Events that repeats every X hours
if (self.events[key].repeat !== undefined) {
var event = self.events[key].repeat.start;
while (event[0] < 24) {
self.schedule.push([(event[0] * 60) + event[1], key]);
event[0] += self.events[key].repeat.interval;
}
}
// Fixed events
if (self.events[key].fixed !== undefined) {
for (i = 0; i < self.events[key].fixed.length; i++) self.schedule.push([(self.events[key].fixed[i][0]) * 60 + self.events[key].fixed[i][1], key]);
}
});
// Sort and return current events
self.getSchedule = function (offset) {
var now = new Date();
var retval = [];
for (i = 0; i < self.schedule.length; i++) {
var entry = {
key: self.schedule[i][1],
remaining: self.schedule[i][0] - ((now.getUTCHours() * 60) + now.getUTCMinutes()),
stamp: new Date(Date.UTC(now.getFullYear(), now.getMonth(), now.getDate(), Math.floor(self.schedule[i][0] / 60), (self.schedule[i][0] - (Math.floor(self.schedule[i][0] / 60) * 60)) % 60, 0))
};
if (entry.remaining < offset) {
entry.remaining += 1440;
entry.stamp.setDate(entry.stamp.getDate() + 1);
}
retval.push(entry);
}
return retval.sort(function (a, b) { return a.remaining - b.remaining });
};
};
</script>
</head>
<body>
<div id="output"></div>
<script>
// Example script
var bossTimer = new BossTimer();
function formatRemaining(remaining) {
if (remaining < 0) remaining = 0;
var h = Math.floor(remaining / 60);
var m = remaining - (h * 60);
return (("0" + h).slice(-2) + ":" + ("0" + m).slice(-2));
}
function update() {
var current = bossTimer.getSchedule(-15);
var htmlOutput = "";
for (i = 0; i < current.length; i++) {
htmlOutput += "<div class='row'><div class='cell remaining'>[" + formatRemaining(current[i].remaining) + "]</div><div class='cell timestamp'>" + current[i].stamp.toLocaleTimeString() + "</div><div class='cell'>" + current[i].key + "</div></div>";
}
document.getElementById("output").innerHTML = htmlOutput;
setTimeout(update, 10000);
}
update();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment