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','#','Chembox replace','t-chembox-replace');
			$(portletlink).click(function(e) {
				e.preventDefault();
				chemboxReplace();
			});
		});
	}
	
	function chemboxReplace() {
		var myContent = document.getElementById('wpTextbox1').value[0];
		var text = document.getElementById('wpTextbox1').value[0];
		
		// {{Chembox Identifiers}}
		// {{Chembox Properties}}
		// {{Chembox Structure}}
		// {{Chembox Thermochemistry}}
		// {{Chembox Explosive}}
		// {{Chembox Pharmacology}}
		// {{Chembox Hazards}}
		// {{Chembox Related}}
		document.getElementById('wpTextbox1').value = document.getElementById('wpTextbox1').value.replace(/\{\{\s*Chembox Identifiers/i, "{{Infobox chemical/identifiers");
		document.getElementById('wpTextbox1').value = document.getElementById('wpTextbox1').value.replace(/\{\{\s*Chembox Properties/i, "{{Infobox chemical/properties");
		document.getElementById('wpTextbox1').value = document.getElementById('wpTextbox1').value.replace(/\{\{\s*Chembox Structure/i, "{{Infobox chemical/structure");
		document.getElementById('wpTextbox1').value = document.getElementById('wpTextbox1').value.replace(/\{\{\s*Chembox Thermochemistry/i, "{{Infobox chemical/thermochemistry");
		document.getElementById('wpTextbox1').value = document.getElementById('wpTextbox1').value.replace(/\{\{\s*Chembox Explosive/i, "{{Infobox chemical/explosive");
		document.getElementById('wpTextbox1').value = document.getElementById('wpTextbox1').value.replace(/\{\{\s*Chembox Pharmacology/i, "{{Infobox chemical/pharmacology");
		document.getElementById('wpTextbox1').value = document.getElementById('wpTextbox1').value.replace(/\{\{\s*Chembox Hazards/i, "{{Infobox chemical/hazards");
		document.getElementById('wpTextbox1').value = document.getElementById('wpTextbox1').value.replace(/\{\{\s*Chembox Related/i, "{{Infobox chemical/related");
		document.getElementById('wpTextbox1').value = document.getElementById('wpTextbox1').value.replace(/\{\{\s*Chembox/i, "{{Infobox chemical");
		
		//document.getElementById('wpTextbox1').value;
    	document.getElementById('wpSummary').value  = "converting to use [[Template:Infobox chemical]]";
    	// document.getElementById('wpTextbox1').value = text;
	}
});