User:ToxiBoi/WikidotCompatibility.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
This user script seems to have a documentation page at User:ToxiBoi/WikidotCompatibility. |
// <nowiki>
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 "{{$2}}<!-- This is a Wikidot template call(!)-->";
},
},
{
"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": "<s>$1</s>",
}
];
if (mw.util.getParamValue( 'action' ) == 'edit' || mw.util.getParamValue( 'action' ) == 'submit') {
mw.util.$content.append('<h2 id="toxiboi">ToxiBoi\'s Wikidot Importer</h2><button id="Wikidot" onclick="SetupWikidot()" class="mw-ui-button mw-ui-destructive">Open Wikidot UI</button>');
}
function SetupWikidot(){
var elem = document.getElementById('Wikidot');
if (elem !== null) {
elem.parentNode.removeChild(elem);
}
mw.util.$content.append('<textarea id="sourcetext" class="mw-editfont-monospace" placeholder="Wikidot wikitext goes here..." style="margin: 0px; height: 196px; width: 637px; max-width: 100%; min-width: 100%;"></textarea><br><button id="translate" onclick="Translate()" class="mw-ui-button mw-ui-progressive">Import Wikidot Data</button>');
}
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!
}
// </nowiki>