Jump to content

User:MusikAnimal/scriptManager.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by MusikAnimal (talk | contribs) at 06:17, 17 November 2014. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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(skin === "vector") {
		$html = $("<div class='portal' role='navigation' id='p-enable_scripts' aria-labelledby='p-enable_scripts-label'></div>");
		$html.append("<h3 id='p-enable_scripts-label'>Enable scripts</h3>");
		$html.append("<div class='body'><ul></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) {
		$.getScript(e.data.src);
		$(e.target).parent().remove();
	};
 
 	if(scriptsToManage) {
		$.each(scriptsToManage, function(script, src) {
		  var scriptName = script.replace(/ /g,"_");
		  $html.find("ul").append("<li><a href='javascript:' id='t-enablescript-"+scriptName+"'>"+script+"</a></li>");
		  $("#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>");
 	}
 	$(skin === "vector" ? "#mw-panel" : "#column-one").prepend($html);
}());