User:Essjay/createsorter.js

/* */ // ======================================== // BEGIN Special:CreateWiki request sorter // ======================================== function sortCreateList { if(!document.getElementById('createwiki')) return var sel = document.getElementById('createwiki').req_id; var ln = sel.length; var req = new Array(sel.length); for(var i=0; i < ln; i++) { req[i] = sel.options[i].innerHTML + '@@@' + sel.options[i].value; req[i] = req[i].substring(0,1).toLowerCase + req[i].substring(1); } sel.innerHTML = ''; req.sort; var v = ''; var h = ''; for(var i=0; i < ln; i++) { v = req[i].substring(req[i].indexOf('@@@') + 3); h = req[i].substring(0, req[i].indexOf('@@@')); appendoption(v, h + ' (' + v + ')'); } } addOnloadHook(sortCreateList);

function appendoption(value,inner) { var sel = document.getElementById('createwiki').req_id; var newopt = document.createElement('option'); newopt.value = value; newopt.text = inner; try { sel.add(newopt, null); } catch(ex) { sel.add(newopt); } } // ======================================== // END Special:CreateWiki request sorter // ======================================== /* */