Jump to content

User:Zackmann08/insert-template.js

From Wikipedia, the free encyclopedia
This is the current revision of this page, as edited by Zackmann08 (talk | contribs) at 22:24, 7 September 2017. The present address (URL) is a permanent link to this version.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
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.
jQuery(document).ready(function($) {
	if(mw.config.get('wgNamespaceNumber') != -1) {
		mw.loader.using(['mediawiki.util']).done( function() {
			var portletlink = mw.util.addPortletLink('p-tb','#','Insert template','t-insert-template');
			$(portletlink).click(function(e) {
				e.preventDefault();
				insertTemplate();
			});
		});
	}
	
	function insertTemplate() {
		var myContent = document.getElementById('wpTextbox1').value;
		var mysummary = "Tagging page for conversion";
		
		var template = prompt("Please the template", "Sidebar");
		console.log(template);
		template_name = template.charAt(0).toUpperCase() + template.slice(1);
		console.log(template_name);
		console.log(['Sidebar', 'Infobox', 'Navbox', 'WPBannerMeta', 'Wpbannermeta'].includes(template_name));
		if(['Sidebar', 'Infobox', 'Navbox', 'WPBannerMeta', 'Wpbannermeta'].includes(template_name)){
			document.getElementById('wpTextbox1').value += `<noinclude>{{convert to use ${template_name}}}</noinclude>`
    		document.getElementById('wpSummary').value  = "Tagging page for conversion";
		} else{
			alert("Invalid template")
		}
	}
});