User:WOSlinker/hlist.js

function hlist_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 'hlist edit' tab if(mw.config.get('wgNamespaceNumber') == 10 && mw.config.get('wgArticleId') != 0) { $( function hlistEditButton {       mw.util.addPortletLink('p-cactions', mw.util.getUrl(null,{action:'edit',hlist:true}), 'hlist', 'p-hlist', 'hlist edit');   } )} if(mw.config.get('wgAction') == 'edit' && hlist_queryString('hlist') == 'true') { $(function qscale {       var myContent = document.getElementById('wpTextbox1').value;        myContent = myContent.replace(/\<\!--\(reduces gap between wrapped lines\)--\>/g,'');

//Fix italics and bold when only set at start & end of line while( myContent.search(/(?:[\n]|=|\{\{[ ]*(?:·|•|,|\*|!)(?:wrap|w|)[ ]*\}\}|\&bull\;|(?:\&nbsp\;| )(?:•|·)|\{\{nowrap[_ ]+begin\}\})[ ]*(\'?\'\')(?:[^\'\n]|[^\'\n]\')*(?:\{\{[ ]*(?:·|•|,|\*|!)(?:wrap|w|)[ ]*\}\}|\&bull\;|(?:\&nbsp\;| )(?:•|·))[ ]*\1/gi) >= 0 ) { myContent = myContent.replace(/((?:[\n]|=|\{\{[ ]*(?:·|•|,|\*|!)(?:wrap|w|)[ ]*\}\}|\&bull\;|(?:\&nbsp\;| )(?:•|·)|\{\{nowrap[_ ]+begin\}\})[ ]*)(\'?\'\')((?:[^\'\n]|[^\'\n]\')*)((?:\{\{[ ]*(?:·|•|,|\*|!)(?:wrap|w|)[ ]*\}\}|\&bull\;|(?:\&nbsp\;| )(?:•|·)))[ ]*\2/gi, '$1$2$3$2$4'); } while( myContent.search(/(?:[\n]|=|\{\{[ ]*(?:·|•|,|\*|!)(?:wrap|w|)[ ]*\}\}|\&bull\;|(?:\&nbsp\;| )(?:•|·)|\{\{nowrap[_ ]+begin\}\})[ ]*\'?\'\'(?:[^\'\n]|[^\'\n]\')*(?:\{\{[ ]*(?:·|•|,|\*|!)(?:wrap|w|)[ ]*\}\}|\&bull\;|(?:\&nbsp\;| )(?:•|·))/gi) >= 0 ) { myContent = myContent.replace(/((?:[\n]|=|\{\{[ ]*(?:·|•|,|\*|!)(?:wrap|w|)[ ]*\}\}|\&bull\;|(?:\&nbsp\;| )(?:•|·)|\{\{nowrap[_ ]+begin\}\})[ ]*)(\'?\'\')((?:[^\'\n]|[^\'\n]\')*)((?:\{\{[ ]*(?:·|•|,|\*|!)(?:wrap|w|)[ ]*\}\}|\&bull\;|(?:\&nbsp\;| )(?:•|·)))/gi, '$1$2$3$2$4$2'); }

myContent = myContent.replace(/\&nbsp\;-/g,' -');

myContent = myContent.replace(/\{\{[_ ]*[Nn]owrap begin[_ ]*\}\}\n?/g,'\n* ');

myContent = myContent.replace(/\{\{[_ ]*[Nn]owrap\|[_ ]*/g,'* '); myContent = myContent.replace(/\{\{[_ ]*•[_ ]*\}\}\}\}[ ]*/g,''); myContent = myContent.replace(/\{\{[_ ]*·[_ ]*\}\}\}\}[ ]*/g,'');

myContent = myContent.replace(/\{\{[_ ]*•wrap[_ ]*\}\}[ ]*\n/g,'\n* '); myContent = myContent.replace(/\{\{[_ ]*•wrap[_ ]*\}\}[ ]*/g,'\n* '); myContent = myContent.replace(/\{\{[_ ]*•w[_ ]*\}\}[ ]*\n/g,'\n* '); myContent = myContent.replace(/\{\{[_ ]*•w[_ ]*\}\}[ ]*/g,'\n* ');

myContent = myContent.replace(/\{\{[_ ]*·wrap[_ ]*\}\}[ ]*\n/g,'\n* '); myContent = myContent.replace(/\{\{[_ ]*·wrap[_ ]*\}\}\'\'[ ]*/g,'\n* \'\''); myContent = myContent.replace(/\{\{[_ ]*·wrap[_ ]*\}\}[ ]*/g,'\n* '); myContent = myContent.replace(/\{\{[_ ]*·w[_ ]*\}\}[ ]*\n/g,'\n* '); myContent = myContent.replace(/\{\{[_ ]*·w[_ ]*\}\}\'\'[ ]*/g,'\n* \'\''); myContent = myContent.replace(/\{\{[_ ]*·w[_ ]*\}\}[ ]*/g,'\n* '); myContent = myContent.replace(/\{\{[_ ]*·[_ ]*\}\}[ ]*\n/g,'\n* '); myContent = myContent.replace(/\{\{[_ ]*·[_ ]*\}\}[ ]*/g,'\n* '); myContent = myContent.replace(/\{\{[_ ]*,[_ ]*\}\}[ ]*\n/g,'\n* '); myContent = myContent.replace(/\{\{[_ ]*,[_ ]*\}\}[ ]*/g,'\n* ');

myContent = myContent.replace(/\{\{[_ ]*•[_ ]*\}\}[ ]*\n/g,'\n* '); myContent = myContent.replace(/\{\{[_ ]*•[_ ]*\}\}[ ]*/g,'\n* ');

myContent = myContent.replace(/\{\{[_ ]*\*[_ ]*\}\}[ ]*\n/g,'\n* '); myContent = myContent.replace(/\{\{[_ ]*\*[_ ]*\}\}[ ]*/g,'\n* ');

myContent = myContent.replace(/[ ]*\&bull\;[ ]*/g,'\n* ');

myContent = myContent.replace(/\{\{[_ ]*![_ ]*\}\}[ ]*\n/g,'\n* '); myContent = myContent.replace(/\{\{[_ ]*![_ ]*\}\}\}\}[ ]*/g,''); myContent = myContent.replace(/\{\{[_ ]*![_ ]*\}\}[ ]*/g,'\n* '); myContent = myContent.replace(/\{\{[_ ]*!w[_ ]*\}\}[ ]*\n/g,'\n* '); myContent = myContent.replace(/\{\{[_ ]*!w[_ ]*\}\}[ ]*/g,'\n* ');

myContent = myContent.replace(/\&nbsp\;•[ ]*/g,'\n* ');

// myContent = myContent.replace(/[ ]*\&bull\;[ ]*\n/g,'\n* '); // myContent = myContent.replace(/[ ]*\&bull\;[ ]*/g,'\n* ');

myContent = myContent.replace(/(\|[ ]*list\d*[ ]*=[ ]*)\/g,'$1'); myContent = myContent.replace(/\n\<\/div\>[ ]*\n/g,'\n');

myContent = myContent.replace(/(\|[ ]*list\d*[ ]*=)[ ]*\[/g,'$1\n* \['); myContent = myContent.replace(/(\|[ ]*list\d*[ ]*=)[ ]*\'/g,'$1\n* \''); myContent = myContent.replace(/(\|[ ]*list\d*[ ]*=)[ ]*\"/g,'$1\n* \"'); // myContent = myContent.replace(/(\|[ ]*list\d*[ ]*=)[ ]*\{/g,'$1\n* \{');

myContent = myContent.replace(/\}\} \{\{nowrap\|[ ]*/g,''); myContent = myContent.replace(/\* \{\{nowrap\|/g,'* ');

myContent = myContent.replace(/\&nbsp\;· /g,'\n* '); myContent = myContent.replace(/ · /g,'\n* '); myContent = myContent.replace(/[ ]*•[ ]*\}\}[ ]*/g,'\n* ');

myContent = myContent.replace(/\][ ]*,[ ]*\[/g,']\n* ['); myContent = myContent.replace(/[ ]*•[ ]*/g,'\n* ');

myContent = myContent.replace(/\n\* \*[ ]*/g,'\n* '); myContent = myContent.replace(/\n\* [ ]*/g,'\n* '); myContent = myContent.replace(/\n\* \&nbsp\;/g,'\n* '); myContent = myContent.replace(/\n\* \}\} \* /g,'\n* '); myContent = myContent.replace(/\n\*[ ]*\}\}[ ]*\n\* /g,'\n'); myContent = myContent.replace(/\n\*[ ]*\n/g,'\n* ');

myContent = myContent.replace(/\{\{nowrap end\}\}[ ]*/g,''); myContent = myContent.replace(/\{\{Nowrap end\}\}[ ]*/g,'');

// myContent = myContent.replace(/\:\&nbsp\;/g,': '); // myContent = myContent.replace(/\&nbsp\;/g,'');

myContent = myContent.replace(/\* \*[ ]*/g,'* ');

if(document.getElementById('wpTextbox1').value != myContent) {

myContent = myContent.replace(/\|\{\{PAGENAME\}\}\]\]/g,']]');

var idx1 = 0; var idx2 = 0; var listclass = "listclass";

if ( myContent.indexOf("avbox Musical artist",idx1)+myContent.indexOf("avbox musical artist",idx1) > 0 ) { if ( myContent.indexOf("| above",idx1)+myContent.indexOf("|above",idx1) > 0 ) { listclass = "bodyclass"; } }

idx1 = myContent.search(/\|[ ]*title[ ]*=/) if( idx1 > 0 ) { idx2 = myContent.indexOf("\n",idx1); } if( idx2 > 0 ) { myContent = myContent.substring(0,idx2+1)+"\|"+listclass+" = hlist"+myContent.substring(idx2,myContent.length); }

idx1 = 0; idx2 = 0; idx1 = myContent.search(/\|[ ]*capital[ ]*=/) if( idx1 > 0 ) { idx2 = myContent.indexOf("\n",idx1); } if( idx2 > 0 ) { myContent = myContent.substring(0,idx2+1)+"\|"+listclass+" = hlist"+myContent.substring(idx2,myContent.length); }

idx1 = 0; idx2 = 0; idx1 = myContent.search(/\|[ ]*template_name[ ]*=/) if( idx1 > 0 ) { idx2 = myContent.indexOf("\n",idx1); } if( idx2 > 0 ) { myContent = myContent.substring(0,idx2+1)+"\| "+listclass+" = hlist"+myContent.substring(idx2,myContent.length); }

idx1 = 0; idx2 = 0; idx1 = myContent.search(/\|[ ]*raw_name[ ]*=/) if( idx1 > 0 ) { idx2 = myContent.indexOf("\n",idx1); } if( idx2 > 0 ) { myContent = myContent.substring(0,idx2+1)+"\| "+listclass+" = hlist"+myContent.substring(idx2,myContent.length); }

// Error checks myContent = myContent.replace(/([\r\n](?:[^\'\r\n]|[^\'\r\n]\')*\'\'(?:[^\'\r\n]|[^\'\r\n]\')*)([\r\n])/gi, '$1$2'); myContent = myContent.replace(/([\r\n](?:[^\'\r\n]|[^\'\r\n]\')*\'\'\'(?:[^\'\r\n]|[^\'\r\n]\')*)([\r\n])/gi, '$1$2'); if( myContent.search(//gi) >= 0 ) { myContent = "\n" + myContent; }

document.getElementById('wpTextbox1').value=myContent; document.getElementById('wpSummary').value='use listclass = hlist in navbox as per WP:HLIST'; };   } )}