User:Shahar/common.js: Difference between revisions
From Inkipedia, the Splatoon wiki
m (-) Tag: Reverted |
m (-) Tag: Reverted |
||
Line 55: | Line 55: | ||
return; // No schedule data | return; // No schedule data | ||
var lblFetched = document.getElementById(" | var lblFetched = document.getElementById("challengeFetched"); | ||
if (!lblFetched) | if (!lblFetched) | ||
return; | return; |
Revision as of 15:54, 7 December 2023
/* 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'); } $(function() { 'use strict'; function removeColors(ev) { var els = document.querySelectorAll("#bodyContent span"); var i, el; for (i = 0; i < els.length; i++) { el = els[i]; if (el.style.color) { el.style.color = null; } } } var els = document.querySelectorAll(".ColorRemover"); var i, el, btn; for (i = 0; i < els.length; i++) { el = els[i]; btn = document.createElement("button"); btn.type = "button"; btn.textContent = "Remove Colors"; btn.addEventListener("click", removeColors); el.appendChild(btn); } }); window.addEventListener("load", function() { /////////////////////////////////////////////////////////////////////////////// // ChallengeSchedule Class // /////////////////////////////////////////////////////////////////////////////// // Maintains auto-updating Challenge schedule elements // Object constructor var ChallengeSchedule = function() { "use strict"; this.timesEl = [ document.getElementById("challengeTime1"), document.getElementById("challengeTime2"), ]; if (!this.timesEl[0]) return; // No schedule data var lblFetched = document.getElementById("challengeFetched"); if (!lblFetched) return; var now = new Date(); var fetched = parseFetched(now, lblFetched.innerHTML); /** * @param {string} str */ function parse(str) { if (!str.endsWith(" UTC")) return null; var dates = str.split("-", 2); if (dates.length != 2) return null; return ({ start: parseSchedule(fetched, dates[0].trim()), end: parseSchedule(fetched, dates[1].slice(0, -4).trim()), }); } this.data = []; for (var i = 0; i < this.timesEl.length; i++) { var timeEl = this.timesEl[i]; var orderEl = timeEl.getElementsByClassName("challengeOrder"); if (!orderEl.length) continue; var current = { orderEl: orderEl[0], slots: [/*{ el: new HTMLElement(), start: new Date(), end: new Date(), },*/], }; var slotsEl = timeEl.getElementsByClassName("challengeTimeSlot"); for (var j = 0; j < slotsEl.length; j++) { var slotEl = slotsEl[j]; var slot = parse(slotEl.innerText); if (!slot) continue; current.slots.push({ el: slotEl, start: slot.start, end: slot.end, }); } if (current.slots.length > 0) this.data.push(current); } if (!this.data.length) return; var _this = this; this.timer = setInterval(function() { _this.onTick(new Date()); }, 1000); this.onTick(new Date()); }; // Periodic update handler /** * @param now {Date} */ ChallengeSchedule.prototype.onTick = function(now) { "use strict"; var upcomingOrNext = 1; var hasFuture = false; for (var i = 0; i < this.data.length; i++) { var current = this.data[i]; for (var j = 0; j < current.slots.length; j++) { var slot = current.slots[j]; var startStr = now >= slot.start && now < slot.end ? "Now" : formatDateTime(slot.start); var endStr = formatDateTime(slot.end); slot.el.innerText = startStr + " - " + endStr; if (now >= slot.end) { slot.el.style.textDecoration = "line-through"; slot.el.style.fontWeight = "normal"; } else if (now >= slot.start) { slot.el.style.textDecoration = "underline"; } } var start = current.slots[0].start; var end = current.slots[current.slots.length - 1].end; if (now >= end) { upcomingOrNext = 0; current.orderEl.innerText = "Past"; } else if (now >= start) { upcomingOrNext = 0; hasFuture = true; current.orderEl.innerText = "Current"; } else if (upcomingOrNext <= 1) { hasFuture = true; current.orderEl.innerText = "Upcoming"; } else { hasFuture = true; current.orderEl.innerText = "Next"; } upcomingOrNext++; } if (!hasFuture) { clearInterval(this.timer); } }; window.challengeSchedule = new ChallengeSchedule(); });