User:ToxiBoi/WikidotCompatibility.js

// var RegObj = [ { //KEEP THIS AT TOP "regex": //g, "hotkey": "{"+"{code|$1}}", },	{		"regex": /\[\[include (:|)(.*)\]\]/g, "hotkey": function{ alert("WARNING: Your text has one Wikidot template. This may cause malformed formatting. Make sure to use the Show Preview button."); return ""; },	},	{		"regex": /\*\*(.*)\*\*/g, "hotkey": "$1", },	{		"regex": /\/\/(.*)\/\//g, "hotkey": "$1", },	{		"regex": /(\++) (.*)/g, "hotkey": function(str, reg){ var str2 = (str.match(/\+/g) || []).length; // count number of +'s			var end = ""; var i;			for (i = 0; i < str2; i++) { end += "="; }			end += " Heading "; for (i = 0; i < str2; i++) { end += "="; }			return end; },	},	{		"regex": /> (.*)/g, "hotkey": "{"+"{blockquote|$1}}", },	{		"regex": /(?!<!)--(.*)--(?!>)/g, "hotkey": " $1 ", } ]; if (mw.util.getParamValue( 'action' ) == 'edit' || mw.util.getParamValue( 'action' ) == 'submit') { mw.util.$content.append(' ToxiBoi\'s Wikidot Importer Open Wikidot UI '); } function SetupWikidot{ var elem = document.getElementById('Wikidot'); if (elem !== null) { elem.parentNode.removeChild(elem); }   mw.util.$content.append(' Import Wikidot Data '); } function Translate{ var elem = document.getElementById('translate'); var source2 = document.getElementById('sourcetext'); var source = source2.value; var end = source; var att = document.createAttribute("disabled"); document.getElementById('sourcetext').setAttributeNode(att); elem.innerHTML = "Converting..."; RegObj.forEach(function(value,index,array){		end = end.replace(value.regex,value.hotkey);		console.log(value);		console.log(end);	}); elem.innerHTML = "Moving to Edit Box..."; document.getElementsByTagName("textarea")[0].value = end; elem.innerHTML = "Done! Removing..."; source2.parentNode.removeChild(source2); elem.parentNode.removeChild(elem); /*var elemTitle = document.getElementById('toxiboi'); elemTitle.parentNode.removeChild(elemTitle);*/ SetupWikidot;//restart the loop! } //