User:MonkeysHK/common.js

// $(function { //    var hypixelItems; //     window.hypixelItems = function { //         if (hypixelItems) return hypixelItems; //         $.get("https://api.hypixel.net/resources/skyblock/items", function(data) { //            hypixelItems = data; //            console.log("Success. Run again for data."); //        }); //     }; // });

// code snippet from https://stackoverflow.com/questions/46041831/copy-to-clipboard-with-break-line function copyToClipboard(text, notice) { notice = notice ? (notice + "\n\n") : ""; if (confirm(notice + "The following will be copied to your clipboard:\n\n" + text + "\n\nClick OK to confirm")) { var $temp = $(" "); var brRegex = //gi; $("body").append($temp); $temp.val(text.replace(brRegex, "\r\n")).select; document.execCommand("copy"); $temp.remove; if (BannerNotification) new BannerNotification($(" ", { html: " Copied to clipboard ", }).prop("outerHTML"), "confirm", null, 2000).show; } }

//############################################################## /** (Tool 3) Bingo Table Generator **/ (function {    var ALLOWED_PAGE = "User:MonkeysHK/sandbox5",        BUTTON = "#bingodata",        MONTHS = [        	"JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"        ],        COLORS_TO_TEMPLATE = [        	"Black", "Dark Blue", "Dark Green", "Dark Aqua", "Dark Red", "Dark Purple", "Gold", "Gray", "Dark Gray", "Blue", "Green", "Aqua", "Red", "Light Purple", "Yellow", "White"        ],        DIAGONALS = [ 0, 6, 12, 18, 24 ];        // to find diagonals:        // [0, 1, 2, 3, 4].map(function (n) { // 	return n * 5 + n       // });

if (ALLOWED_PAGE !== mw.config.get("wgPageName") || $(BUTTON).length < 1) return;

function errorHandler(err) { mw.notify("See the web console for details", {           title: "Uncaught Error",            type: "error"        }); console.error(err); }

function getBingoData { return fetch("https://api.hypixel.net/resources/skyblock/bingo") .then(function (response) {               return response.json;            }) .catch(errorHandler); }   function constructTable(goals) { function replfunc(match, pattern1, pattern2, pattern3) { return "" + pattern3; }   	function processStr(v) { var s = v[1] || ""; while (s.search(/§[0-9a-f]/) > -1) { s = s.replace(/§([0-9a-f])(.*?)(\s*§|\s*{{|$)/g, replfunc); }           return [v[0] || "", s.replace(//g, "$1")]; }   	function tablize(v) { return "|-\n| " + v[0] + " || " + v[1]; }   	var personal = [], community = []; goals.forEach(function (v, i) {   		(DIAGONALS.includes(i) ? community : personal).push([v.name, v.lore]);   	}); personal = personal.map(processStr).map(tablize); community = community.map(processStr).map(tablize); return "{| class=\"wikitable\"\n! Name !! Requirement\n|-\n! colspan=\"2\" | Personal Goals\n" + personal.join("\n") + "\n|-\n! colspan=\"2\" | Community Goals\n" + community.join("\n") + "\n|}"; }   function th(n) { var num = n % 100; if (num >= 11 && num <= 13) return num + "th"; else if (num % 10 === 1) return num + "st"; else if (num % 10 === 2) return num + "nd"; else if (num % 10 === 3) return num + "rd"; else return num + "th"; }   function getYear(n) { // note: 0 = DEC 2021 return 2021 + (Math.floor((n - 1) / 12) + 1); }   function getMonth(n) { // note: 0 = DEC 2021 return n % 12 == 0 ? 12 : n % 12; }   function mo(n) { // note: 0 = DEC 2021 return MONTHS[getMonth(n) - 1] + " " + getYear(n); }

$(BUTTON).show.click(function {        getBingoData.then(function (data) { var notice = "Note: This data is for:\n\n" + th(data.id + 1) + " bingo event (held in " + mo(data.id) + ")", id = "goals-" + getYear(data.id) + "-" + getMonth(data.id); copyToClipboard("Show/Hide \n\n" + constructTable(data.goals) + "\n ", notice); });   }); });