User:WOSlinker/userbox.js

function userbox_queryString(p) { var re = RegExp('[&?]' + p + '=([^&]*)'); var matches; if (matches = re.exec(document.location)) { try { return decodeURI(matches[1]); } catch (e) { } }   return null; } //Add a 'special edit' tab if(mw.config.get('wgNamespaceNumber') != -1 && mw.config.get('wgArticleId') != 0) { $( function userboxEditButton {       mw.util.addPortletLink('p-cactions', mw.util.getUrl(null,{action:'edit',userbox:true}), 'userbox', 'p-userbox', 'Userbox edit this page');   } )} if(mw.config.get('wgAction') == 'edit' && userbox_queryString('userbox') == 'true') { $(function userbox {       var infofc = ;        var infos  = ;        var ulevel = ;        var borderc = ;        var idbits = ;        var float1 = ;        var float2 = ;        var idc    = ;        var idfc   = ;        var ids    = ;        var infoc  = ;        var infoop = ;        var idtext = ;        var infotext = ;        var idx1 = 0;        var idx2 = 0;        var myContent2 =         var uc     = ;        var uc1    = ;        var uc2    = ;        var ucall   = '';        var myHead = Right(document.getElementById('firstHeading').innerHTML,2);        var myContent = document.getElementById('wpTextbox1').value;        var myContentUpper = myContent.toUpperCase;

//Find cats idx1 = myContent.indexOf("includeonly"); if( idx1 > 0 ) { idx2 = myContent.indexOf("/includeonly",idx1); uc = myContent.substring(idx1+10,idx2); idx1 = uc.indexOf("\[\[Category\:"); if( idx1 > 0 ) { idx2 = uc.indexOf("\]\]",idx1); uc1 = uc.substring(idx1+11,idx2); uc = uc.substring(idx2-1,uc.length); idx1 = uc1.indexOf("\|"); if( idx1 > 0 ) { uc1 = uc1.substring(0,idx1) }; };              idx1 = uc.indexOf("\[\[Category\:"); if( idx1 > 0 ) { idx2 = uc.indexOf("\]\]",idx1); uc2 = uc.substring(idx1+11,idx2); idx1 = uc2.indexOf("\|"); if( idx1 > 0 ) { uc2 = uc2.substring(0,idx1) }; };           };            if ( uc1 == '' ) { uc = myContent; idx1 = myContent.indexOf("noinclude"); if ( idx1 > 0 ) { uc = myContent.substring(0,idx1) }; idx1 = uc.indexOf("\[\[Category\:"); if( idx1 > 0 ) { idx2 = uc.indexOf("\]\]",idx1); uc1 = uc.substring(idx1+11,idx2); uc = uc.substring(idx2-1,uc.length); idx1 = uc1.indexOf("\|"); if( idx1 > 0 ) { uc1 = uc1.substring(0,idx1) }; };              idx1 = uc.indexOf("\[\[Category\:"); if( idx1 > 0 ) { idx2 = uc.indexOf("\]\]",idx1); uc2 = uc.substring(idx1+11,idx2); idx1 = uc2.indexOf("\|"); if( idx1 > 0 ) { uc2 = uc2.substring(0,idx1) }; };           };            if ( uc1 != '' ) { ucall = '\| usercategory  = \'+uc1+'\<\/includeonly\>\n' } ; if ( uc2 != '' ) { ucall = ucall + '\| usercategory2 = \'+uc2+'\<\/includeonly\>\n' } ; if ( ucall != '' ) { ucall = ucall + '\| nocat = \{\{\{nocat\|\}\}\}\n' } ;

//Find id text idx1 = myContent.indexOf("'''")+3; idx2 = myContent.indexOf("'''",idx1); idtext = myContent.substring(idx1,idx2);

//Userbox-level bits if(myContentUpper.search(/#6EF7A7/)>0 && myContentUpper.search(/#C5FCDC/)>0 ) { ulevel = 'X'; }       if(myHead == '-N' && myContentUpper.search(/#6EF7A7/)>0                          && myContentUpper.search(/#C5FCDC/)>0 ) { ulevel = Right(myHead,1) }; if(myHead == '-0' && myContentUpper.search(/#B7B7B7/)>0                         && myContentUpper.search(/#E8E8E8/)>0 ) { ulevel = Right(myHead,1) }; if(myHead == '-1' && myContentUpper.search(/#C0C8FF/)>0                         && myContentUpper.search(/#F0F8FF/)>0 ) { ulevel = Right(myHead,1) }; if(myHead == '-2' && myContentUpper.search(/#77E0E8/)>0                         && myContentUpper.search(/#D0F8FF/)>0 ) { ulevel = Right(myHead,1) }; if(myHead == '-3' && myContentUpper.search(/#99B3FF/)>0                         && myContentUpper.search(/#E0E8FF/)>0 ) { ulevel = Right(myHead,1) }; if(myHead == '-3' && myContentUpper.search(/#00FF00/)>0                         && myContentUpper.search(/#90FF90/)>0 ) { ulevel = '3b' }; if(myHead == '-4' && myContentUpper.search(/#FFFF00/)>0                         && myContentUpper.search(/#FFFF99/)>0 ) { ulevel = Right(myHead,1) }; if(myHead == '-5' && myContentUpper.search(/#FF0000/)>0                         && myContentUpper.search(/#FF5555/)>0 ) { ulevel = Right(myHead,1) }; if(myHead == '-5' && myContentUpper.search(/#F99C99/)>0                         && myContentUpper.search(/#F9CBC9/)>0 ) { ulevel = '5b' }; if( ulevel != '' ) { if( ulevel == 'X' ) { ulevel = '' }; if ( borderc == '' ) { borderc = idc }; if (myContent.search(/font-size:7.5pt/)>0) {infos = '7.5'}; idx1 = myContent.indexOf("'''")+3; idx2 = myContent.indexOf("'''",idx1); idtext = myContent.substring(idx1,idx2); if ( ulevel != '' ) { idtext = idtext.substring(0,idtext.length-2) }; idx1 = myContent.indexOf("\ 0 ) { idx1 = myContent.indexOf("\>",idx1)+1; idx2 = myContent.indexOf("<",idx1); infotext = myContent.substring(idx1,idx2); } else { idx1 = myContent.indexOf("line-height",idx2); if( idx1 > 0 ) { idx1 = myContent.indexOf("\|",idx1)+1; idx2 = myContent.indexOf("\n",idx1); infotext = myContent.substring(idx1,idx2); if ( infotext.substring(0,1) == ' ' ) { infotext = infotext.substring(1,infotext.length); };              }            }            idx1 = myContent.indexOf("'''"); ids = myContent.substring(0,idx1); idx1 = ids.indexOf("font-size")+10; idx2 = ids.indexOf("pt",idx1); ids = ids.substring(idx1,idx2); if ( ids.substring(0,1) == ' ' ) { ids = ids.substring(1,ids.length); };           if( ids == '14' ) { ids = ''; } else { ids = '\| id-s    = ' + ids + '\n'; };           myContent2 = '\{\{userbox-level\n\| level    = '+ulevel+'\n\| id       = '+idtext+'\n'+ids+'\| info     = '+infotext+'\n'; if( infos != '' ) { myContent2 = myContent2 + '\| info-s  = ' + infos + '\n'; }; myContent2 = myContent2 + ucall + '\}\}\n\\n'; myContent2 = myContent2 + myContent; document.getElementById('wpTextbox1').value=myContent2; document.getElementById('wpSummary').value='use userbox-level'; return; }       idx1 = myContent.indexOf("solid"); idx2 = myContent.indexOf(" ",idx1+7); if ( borderc == '' ) { borderc = 'transparent' }; if( idx1 > 0 ) { borderc=myContent.substring(idx1+6,idx2) }; if (myContent.search(/\{\{\{id-fc\|black\}\}\}/)>0) {idfc = ''}; if (myContent.search(/\{\{\{5\|\{\{\{id-s\|14\}\}\}\}\}\}/)>0) {ids = ''}; idbits = '\| id-fc   = '+idfc+'\n\| id-s     = '+ids+'\n'; if( idtext.substring(0,8).toUpperCase == '[[IMAGE\:' ) { idbits =  };       if( idtext.substring(0,7).toUpperCase == '[[FILE\:' ) { idbits =  };        if (myContent.search(/\{\{\{float\|/)>0) {           float1 = '| float    = \n';           float2 = '| border-s = \n';        };       if( myContent.indexOf("\") > 0 ) { infoop = '\| info-op  = text-align:center;\n' } ;        var mypos = myContent.search(/div/);        if(mypos > 0 ) {            if (myContent.search(/\{\{\{info-fc\|black\}\}\}/)>0) {infofc = };            if (myContent.search(/\{\{\{info-fc\|white\}\}\}/)>0) {infofc = };            if (myContent.search(/\{\{\{info-s\|8\}\}\}/)>0) {infos = };            if (myContent.search(/\{\{\{info-size\|8\}\}\}/)>0) {infos = };            myContent = '\{\{userbox\n'+float1+'\| border-c = ' + borderc + '\n'+float2+'\| id       = '+idtext+'\n\| id-c     = #\n'+idbits+'\| info     = \n\| info-c   = #\n\| info-fc  = '+  infofc + '\n\| info-s   = ' + infos + '\n' + infoop + ucall + '\}\}\n\\n' + myContent;        }        if(document.getElementById('wpTextbox1').value != myContent) {            // myContent = myContent.replace(/\/g,'  ');            document.getElementById('wpTextbox1').value=myContent;            document.getElementById('wpSummary').value='use userbox';        }    } )}