User:MonkeysHK/common.js

var thisdate = new Date, thisyear = thisdate.getFullYear;

function assignDefault (obj, defaults) { window[obj] = window[obj] || {}; var foo = Object.assign(defaults, window[obj]); window[obj] = foo; } function getDef (name, toResolve, url) { return $.Deferred(function (def) {       if (toResolve) {            def.resolve(window[name]);        } else {            $.ajax({ cache: true, dataType: "script", url: url + "?action=raw&ctype=text/javascript" }).done(function { def.resolve(window[name]); });       }    }); } function during(date0, date1) { return date0.getFullYear === date1.getFullYear && date0.getMonth === date1.getMonth && date0.getDate === date1.getDate; } function duringAny(date0, dates) { return dates.some(function (d) {       return during(date0, d);    }); } function waitTill(func, mode) { var thisyeardates, nextyeardates, thisyearmonths, nextyearmonths; if (typeof func === "function") { if (mode === "month") { thisyearmonths = func(thisyear); nextyearmonths = func(nextyear); }		else { thisyeardates = func(thisyear); nextyeardates = func(nextyear); }	}	else { // should be an array if (mode === "month") thisyearmonths = nextyearmonths = func; else thisyeardates = nextyeardates = func; }   var promise = $.Deferred; if (duringAny(thisdate, thisyeardates)) { console.log("[FestiveEvents] Starting celebration!"); promise.resolve(true); } else if (!thisyeardates.length) { promise.resolve(false); } else { var till = Math.min.apply(this, thisyeardates.map(function (v, i) { return ((thisdate < v) && v || nextyeardates[i]) - thisdate; }));       if (till < 86400000) { // Celebration in less than 1 day setTimeout(function {                console.log("[FestiveEvents] Starting celebration!");                promise.resolve(true);            }, till); } else console.log("[FestiveEvents] " + till + "ms till celebration."); promise.resolve(false); }   return promise; }

function getFireworkDates(year) { var cny_lookup = { 2021: "12 Feb 2021", 2022: "1 Feb 2022", 2023: "22 Jan 2023", 2024: "10 Feb 2024", 2025: "29 Jan 2025", 2026: "17 Feb 2026", 2027: "6 Feb 2027", 2028: "26 Jan 2028", 2029: "13 Feb 2029", 2030: "3 Feb 2030", 2031: "23 Jan 2031", 2032: "11 Feb 2032", };   return window.fireworkShow.celebrateOnSpecificDates.map(function (d) {        return new Date(d + " " + year);    }).concat(window.fireworkShow.celebrateOnNewYear && [        new Date("1 January " + year), // new year (Gregorian calendar)        new Date(cny_lookup[year]), // new year (Chinese calendar)    ] || []); }

assignDefault("snowStorm", { autoStart: false }); assignDefault("fireworkShow", { autoStart: false }); $.when(   getDef("snowStorm", window.snowStorm && window.snowStorm.flakes, "https://dev.fandom.com/wiki/MediaWiki:SnowStorm.js"),    getDef("fireworkShow", window.fireworkShow && window.fireworkShow.Loaded, "https://hypixel-skyblock.fandom.com/wiki/User:MonkeysHK/common.js/0.js") ).then(function  {	if (!window.fireworkShow.autoStart) {		waitTill(getFireworkDates).then(function (toCelebrate) { window.fireworkShow.start; });	}	if (!window.snowStorm.autoStart) {	} });