User:Shahar/common.js

/* Counts all your edits and saves them to a page ( http://en.wikipedia.org/wiki/User:Kanegasi/editcounter ) */ if (mw.config.get('wgTitle') === mw.config.get('wgUserName') && mw.config.get('wgNamespaceNumber') === 2) { /* begin options */

/* end options */

mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Kanegasi/editcounter.js&action=raw&ctype=text/javascript'); }

/////////////////////////////////////////////////////////////////////////////// //                          ChallengeSchedule Class                         // ///////////////////////////////////////////////////////////////////////////////

// Maintains auto-updating Challenge schedule elements

// Object constructor var ChallengeSchedule = function {

// Get the current and last-fetched timestamps var lblFetched = document.getElementById("battleFetched"); if (!lblFetched) return; // No schedule var now       = new Date; var fetched   = parseFetched(now, lblFetched.innerHTML);

// Initialize instance fields this.slots = [ this.parse(document.getElementById("challenge1_rotation1"), fetched), this.parse(document.getElementById("challenge1_rotation2"), fetched), this.parse(document.getElementById("challenge1_rotation3"), fetched), this.parse(document.getElementById("challenge1_rotation4"), fetched), this.parse(document.getElementById("challenge1_rotation5"), fetched), this.parse(document.getElementById("challenge1_rotation6"), fetched), this.parse(document.getElementById("challenge2_rotation1"), fetched), this.parse(document.getElementById("challenge2_rotation2"), fetched), this.parse(document.getElementById("challenge2_rotation3"), fetched), this.parse(document.getElementById("challenge2_rotation4"), fetched), this.parse(document.getElementById("challenge2_rotation5"), fetched), this.parse(document.getElementById("challenge2_rotation6"), fetched) ];

// Update initial display this.onTick(now); lblFetched.innerHTML = formatDateTime(fetched);

// Schedule periodic updates var that = this; this.timer = setInterval(function { that.onTick(new Date); }, 1000); };

// Periodic update handler ChallengeSchedule.prototype.onTick = function(now) {

// Cycle through slots for (var x = 0; x < this.slots.length; x++) { var slot = this.slots[x]; if (slot.prev) continue; // Skip this slot

// Determine when this slot should stop updating slot.prev = now >= slot.end;

// Update the element slot.element.innerHTML = now >= slot.end ? " " + formatDateTime(slot.start) + " - " + formatDateTime(slot.end) + " " : now >= slot.start ? "Now - " + formatDateTime(slot.end) : formatDateTime(slot.start) + " - " + formatDateTime(slot.end) ;   }

// De-schedule the timer if (this.slots[this.slots.length - 1].prev) clearInterval(this.timer); };

// Parse a single Challenge rotation slot ChallengeSchedule.prototype.parse = function(element, fetched) { var text = element.innerHTML; return { element: element, start:  parseSchedule(fetched, text.substring( 0, 12)), end:    parseSchedule(fetched, text.substring(15, 27)), prev:   false }; }

new ChallengeSchedule;