Jump to content

User:MusikAnimal/scriptManager.js

From Wikipedia, the free encyclopedia
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
var scriptsToManage;
(function() {
	var $html;
	if (mw.config.get('skin') === "vector") {
		$html = $("<nav class='mw-portlet vector-menu vector-menu-portal portal' role='navigation' id='p-enable-scripts' aria-labelledby='p-enable-scripts-label'></nav>");
		$html.append("<label id='p-enable-scripts-label' class='vector-menu-heading'><span class='vector-menu-heading-label'>Enable scripts</span></label>");
		$html.append("<div class='vector-menu-content'><ul class='vector-menu-content-list'></ul></div>");
	} else if (mw.config.get('skin') === "vector-2022") {
		$html = $("<div class='vector-main-menu-group vector-menu mw-portlet' role='navigation' id='p-enable-scripts' aria-labelledby='p-enable-scripts-label'></div>");
		$html.append("<div id='p-enable-scripts-label' class='vector-menu-heading'><span class='vector-menu-heading-label'>Enable scripts</span></label>");
		$html.append("<div class='vector-menu-content'><ul class='vector-menu-content-list'></ul></div>");
	} else {
		$html = $("<div class='generated-sidebar portlet' id='p-enable_scripts' role='navigation'></div>");
		$html.append("<h3>Enable scripts</h3>");
		$html.append("<div class='pBody'><ul></ul></div>");
	}
 
	var loadScript = function(e) {
		mw.loader.load(e.data.src);
		$(e.target).parent().remove();
	};
 
 	if(scriptsToManage) {
		$.each(scriptsToManage, function(script, src) {
			var scriptName = mw.util.escapeIdForAttribute(script.replace(/[ \/]/g,"_")),
				containerSelector = '#column-one';
			$html.find("ul").append("<li><a href='javascript:' id='t-enablescript-"+scriptName+"'>"+script+"</a></li>");
			if (mw.config.get('skin') === 'vector') {
				containerSelector = '#mw-panel';
			} else if (mw.config.get('skin') === 'vector-2022') {
				containerSelector = '.vector-main-menu';
			}
			$(containerSelector).append($html);
			$("#t-enablescript-"+scriptName).click({
				script: script,
				src: src
			}, loadScript);
		});
 	} else {
 		$html.find("ul").append("<li><a href='//en.wikipedia.org/wiki/User:MusikAnimal/scriptManager'>No scripts registered!</a></li>");
 		$(mw.config.get('skin') === "vector" || mw.config.get('skin') === "vector-2022" ? "#mw-panel" : "#column-one").append($html);
 	}
}());