MediaWiki:Common.js

/* Any JavaScript here will be loaded for all users on every page load. */ /* Code provided by G_Lander, thanks Z! */

"use strict";

document.querySelectorAll("b").forEach(function (el) { var iconRegex = /{(big)?icon\[\s*-?\d+\s*,\s*-?\d+\s*\]}/i;

if (iconRegex.test(el.innerText)) { try { var offset = 5; var size = 48; var defaultLink = "https://static.miraheze.org/cookieclickerwiki/9/9b/Cookie_Clicker_Icons.png"; var isBig = iconRegex.exec(el.innerText)[1] != undefined;

if (isBig) { offset += 3; size = 64; defaultLink = "https://static.miraheze.org/cookieclickerwiki/0/0f/Buildings_icon_compilation.png"; }

var arr = JSON.parse(el.innerText.substr(offset, el.innerText.length - offset - 1)); if (arr.length > 3 || arr.length < 2 || isNaN(arr[0]) || isNaN(arr[1])) return; el.innerText = ""; var iconEl = document.createElement("div"); iconEl.innerHTML = ""); el.style.margin = iconEl.style.margin = "inherit"; el.appendChild(iconEl); } catch (err) { console.error(err); return; } } });

/* This is an older version of the icon script. "use strict";

document.querySelectorAll("b").forEach(function (el) { if (el.innerText.startsWith("{icon[") && el.innerText.endsWith("]}")) {    try {      var arr = JSON.parse(el.innerText.substr(5, el.innerText.length - 6));      if (arr.length > 3 || arr.length < 2 || isNaN(arr[0]) || isNaN(arr[1])) return;      el.innerText = "";      var iconEl = document.createElement("div");      iconEl.innerHTML = "");      el.appendChild(iconEl);    } catch (err) {      return;    }  } });