User:Bawolff/sandbox/cat2tag.js

//A hide-away category to tagging trick. removes tags on load. Finds Categories, appends them as tags at bottom on save (or any submit) //problems with this: this is really something that should be done server side. (and in the end, this might be done server side, or we might not even do this) //note: this script, like all my edits is in the public domain.

//Todo: make this work with WikiEd, test, make robust. At this point, this script is just to show such a thing could work. /*extern wgAction addOnloadHook wgNamespaceNumber*/ if ((wgAction === "edit") && (wgNamespaceNumber === 0)) { var tag = {}; tag.cat = /\[\cC]ategory:([^\+)\]\]/g;

tag.makeTags = function { var editbox = document.getElementById("wpTextbox1").value; var categories = editbox.match(tag.cat); editbox += "\n"; editbox += ' '; for (var i = 0; i < categories.length;i++) { editbox += " "; editbox += categories[i].replace(tag.cat, "$1"); editbox += " "; }       editbox += " "; document.getElementById("wpTextbox1").value = editbox; return true; //make sure it submits }

tag.hideTags = function { //if you assign doc.getElementById(testarea) to a var, it doesn't seem to work document.getElementById("wpTextbox1").value = document.getElementById("wpTextbox1").value.replace(/\n\<\!--Start\stechnocrati\sTags\.\sDo\snot\smodify\son\sor\sbelow\sthis\sline\!--\>\s?\[\d\D]+\<\/div\>\s?$/, ""); }

//Attach the unhide to save button tag.attach = function { var editform = document.getElementById("editform"); if (!editform) throw new Error("No edit box! Problem with script, please tell someone.");

if (editform.addEventListener) { editform.addEventListener("submit", tag.makeTags, true); }       else if (editform.attachEvent) { editform.attachEvent("onsubmit", tag.makeTags); }       else { editform.onsubmit = tag.makeTags; }   }

addOnloadHook(tag.hideTags); addOnloadHook(tag.attach);

}