MediaWiki:Gadget-ThemeSelector.js

(function($){	var SELECTED_CACHE_KEY = 'hsw-themeselector-selected';	var stylesheetPrefix = "https://hypixel-skyblock.fandom.com/index.php?action=raw&ctype=text/css&title=";	var themes = [		{			id: 'default',			name: 'Default (Light/Dark)',		},		{			id: 'test',			name: "test",			stylesheet: stylesheetPrefix+"MediaWiki:Gadget-ThemeSelector.js/test.css",			image: "https://static.wikia.nocookie.net/hypixel-skyblock/images/0/0e/Community-header-background/revision/20210119204602"		},		{			id: 'test2',			name: "test2",			stylesheet: stylesheetPrefix+"MediaWiki:Gadget-ThemeSelector.js/test.css",			image: "https://static.wikia.nocookie.net/hypixel-skyblock/images/0/0e/Community-header-background/revision/20210119204602"		},	];	// TEMP ICON: CC0 - https://freesvg.org/cat-face-line-art-vector-image	var TOOLBAR_ICON = '<path fill-rule="evenodd" d="M17.6 2.3c-2 1.2-4.8 3.5-6.3 5.1-2.7 3-5.8 12.5-4.7 14.3.3.6 7.7 39.3 16.4 86l15.7 85.1-3.5 6.4c-9.8 17.4-21.7 49-27.1 71.7-5 21.4-7 37.2-7.7 62.4-1.5 53.1 9 98.5 34 147.3 49.2 95.7 147.8 164.5 262.8 183.5 44.7 7.4 99.5 6.5 143.4-2.4a388.1 388.1 0 0 0 140.6-59c26.2-18.1 58.3-48 75.7-70.6 29-37.4 50.6-82.1 60-124a297.3 297.3 0 0 0-22.8-198.5l-6.4-12.9 16.2-85.3c9.7-50.8 16-87 15.6-89.3-.8-6-5.2-12.2-10.5-14.9-9.5-4.9-9.5-4.8-81.5 28.4L561 66.3l-19.6-10a370.4 370.4 0 0 0-180-43 364 364 0 0 0-174 40.1l-19.1 9.5-68.1-31.4C26.7-2.5 25.8-2.8 17.6 2.3m369.7 52.3A338.5 338.5 0 0 1 540.6 102c12.6 7.4 17.3 8.9 23.2 7 2.6-.7 27.7-12 55.8-25 28.1-12.9 51.3-23.3 51.6-23 .2.2-5.3 30.7-12.3 67.8-7 37-12.8 69.5-12.8 72 0 3.2 2.6 9.6 8.9 22.2a249 249 0 0 1 28.3 108.4c2.9 74.7-26.4 146.2-82.9 202.1-58.3 57.9-136.3 90.7-225.2 94.9a359.1 359.1 0 0 1-181.9-42.7 328.3 328.3 0 0 1-91.4-75.9c-24.3-30-43.7-68-52.8-103.5-6.4-25.2-7.3-32.9-7.2-65.2 0-26 .4-32.4 2.7-44.9a251 251 0 0 1 25.8-75.5 197 197 0 0 0 9.5-20.3c1-3.5-1.2-16.9-11.9-74.5-7-38.5-12.9-70.1-12.7-70.1L107.9 80c28.8 13.3 54.5 24.9 57.1 25.6 5.7 1.8 11.5.3 20.8-5.2A468 468 0 0 1 230 78.6a350.2 350.2 0 0 1 157.3-24M231 224.2a66.7 66.7 0 0 0-56.6 58.8 45 45 0 0 0 .5 19.4 67.7 67.7 0 0 0 66.3 55.6 68.2 68.2 0 0 0 66.2-53.7c5-20.2-3-46.2-19.2-61.9a69.8 69.8 0 0 0-57.2-18.2m242.4.1a66.3 66.3 0 0 0-53.3 37 67.5 67.5 0 0 0 64.2 97.2 67.6 67.6 0 0 0 61.8-52.6 67.5 67.5 0 0 0-72.7-81.6m-211.9 23a47.6 47.6 0 0 1 27.4 50.2c-5 29.2-32 47.5-59.4 40.2a48.3 48.3 0 1 1 32-90.5m230-2.9a47.3 47.3 0 0 1 32.6 27.2c3.5 7.2 3.8 9 3.8 19.4 0 9.1-.7 13-2.9 18.5a53.5 53.5 0 0 1-24.2 25.4c-7.4 3.7-8.9 4-20.1 4-15 0-22.5-2.7-32.3-11.4a48.2 48.2 0 0 1 22-83.3c9-2 12.8-2 21.1.2M313 403.6c-18.3 1.7-20.4 5.5-12.8 24 8 19.4 20 39 35.4 58.2l10.1 12.5-3.3 2.7c-20.2 16.2-40.3 24-62.3 24a60 60 0 0 1-55-29 86 86 0 0 1-11.7-30.5c-3.4-15.3-9.6-19.7-17.1-12.1-3.5 3.4-3.6 4-2.8 10a130 130 0 0 0 11.8 36.6 87.2 87.2 0 0 0 36 35.6 99.4 99.4 0 0 0 83-1c8.7-4 22.7-12.6 30.4-19l4.8-3.9 6.7 5.6c21.2 17.7 43.8 26.8 66.4 27 44 .1 71.4-24.8 80.8-73.6 2.5-12.9 2-16-2.8-18.9-4.7-2.8-6.7-2.6-10.5.6-2.6 2.3-3.6 5.2-6 17-7.6 37.8-27 55.5-61 55.5-13 0-22-2.2-34.4-8.7a146 146 0 0 1-25.1-17.5c-.3-.2 1.9-3 4.8-6.2 21.3-23 45.9-68.4 43-79.6-1-4.6-5.7-6.3-21.3-8a805.7 805.7 0 0 0-87-1.3m74.8 19.4c5.6.7 10.4 1.5 10.7 1.8a203.4 203.4 0 0 1-32.7 53.2l-6.4 7-6.4-7.6a271.6 271.6 0 0 1-34.2-54.9c0-1.2 58.5-.7 69 .5"/> '; var CONTENT_ID = 'hsw-themeselector-dropdown'; function main { // Not sure why this sometimes doesn't show up on page load; attempting to delay add a bit to try and make it more consitent setTimeout(initDropdownHtml, 600); // we still want to trigger any selected stylesheets right away though updateStylesheets; }	function initDropdownHtml { $('.'+CONTENT_ID).remove; var $dropdown = $(" ").addClass("wds-button wds-is-secondary wds-dropdown "+CONTENT_ID); var $toggle = $("").addClass("wds-dropdown__toggle").attr("title", "Wiki Theme Selector").html(TOOLBAR_ICON).appendTo($dropdown); $(" ").addClass("wds-dropdown__content wds-is-right-aligned").appendTo($dropdown); // Insert dropdown to nav $(".wiki-tools > .wds-button:last-of-type").after($dropdown); update; }	function update { updateStylesheets; renderThemesList; }	function updateStylesheets { clearStylesheets; var id = getSelectedId; if(id) { const href = themes.find(function(t){ return t.id == id }).stylesheet; addStylesheetToHead(href); }	}	function renderThemesList { var selectedId = getSelectedId; var $content = $("."+CONTENT_ID+" .wds-dropdown__content"); $content.html(""); // Add header $(' Wiki Theme Selector ').appendTo($content); // Add list var $list = $("").addClass("hsw-theme-list").appendTo($content); themes.forEach(function(theme, i){			var $li = $("").html(renderThemeBox(theme)).addClass(theme.id+(theme.id == selectedId ? ' selected' : '')).appendTo($list).on('click', function{ selectThemeId(theme.id); update; });		});	}	function renderThemeBox(theme) { return [ "", " "+theme.name+" ", " "		].join(""); }	function getSelectedId { var id = localStorage.getItem(SELECTED_CACHE_KEY); if(!id || !themes.find(function(t){ return t.id == id })){ id = 'default'; } return id; }	function selectThemeId(id) { saveSelectedId(id == 'default' ? null : id); }	function saveSelectedId(id) { if(id) { localStorage.setItem(SELECTED_CACHE_KEY, id); } else { localStorage.removeItem(SELECTED_CACHE_KEY); }	}	var STYLESHEET_CLASS = "hsw-themeselector-stylesheet"; function addStylesheetToHead(href) { $("head").append(""); }	function clearStylesheets { $("link."+STYLESHEET_CLASS).remove; }	main; })(jQuery);