Jump to content

User:WOSlinker/hlist-private.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
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') != 0 && 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(/\{\{[_ ]*[Nn]owrap begin[_ ]*\}\}\n?/g,'\n* ');

        myContent = myContent.replace(/\{\{[_ ]*[Nn]owrap\|[_ ]*/g,'* ');
        myContent = myContent.replace(/[ ]*\{\{•\}\}\}\}[ ]*/g,'');
        myContent = myContent.replace(/[ ]*\{\{•w\}\}\}\}[ ]*/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(/\{\{[_ ]*,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* ');   //temporary
        myContent = myContent.replace(/\{\{[_ ]*·[_ ]*\}\}[ ]*/g,'\n* ');
        myContent = myContent.replace(/\{\{[_ ]*,[_ ]*\}\}[ ]*\n/g,'\n* ');
        myContent = myContent.replace(/\{\{[_ ]*,[_ ]*\}\}[ ]*/g,'\n* ');

        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(/\{\{[_ ]*•[_ ]*\}\}[ ]*\n/g,'\n* ');
        myContent = myContent.replace(/\{\{[_ ]*•[_ ]*\}\}[ ]*/g,'\n* ');

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

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

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

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

        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(/\'[ ]*-[ ]*\'/g,'\'\n* \'');

        // myContent = myContent.replace(/\<\!--\n--\>/g,'');

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

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

        myContent = myContent.replace(/(\|[ ]*list\d*[ ]*=[ ]*)\<div\>/g,'$1');
        myContent = myContent.replace(/(\|[ ]*list\d*[ ]*=[ ]*)\<div[ ]*class=\"nowraplinks\"\>[ ]*\n/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(/(\|[ ]*list\d*[ ]*=)[ ]*\*/g,'$1\n*');

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

if ( myContent.indexOf("Japan Railway Line",0) > 0 ) {
        myContent = myContent.replace(/\][ ]*[-–][ \n]*\[/g,']\n* [');
        myContent = myContent.replace(/\}[ ]*[-–][ \n]*\{/g,'}\n* {');
        myContent = myContent.replace(/(\|[ ]*body[ ]*=)[ ]*\n/,'$1\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\* \}\}[ ]*\n/g,'\n');
        myContent = myContent.replace(/\n\* \* /g,'\n* ');
        myContent = myContent.replace(/\n\* \}\} \* /g,'\n* ');
        myContent = myContent.replace(/\n\*[ ]*\n/g,'\n* ');

        myContent = myContent.replace(/\*[ ]*\'\'[ ]*/g,'* \'\'');
        myContent = myContent.replace(/[ ]*\'\'[ ]*\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(/\n\<\/div\>[ ]*\n/g,'\n');

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

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

        myContent = myContent.replace(/\n\n\n/g,'\n\n');
        myContent = myContent.replace(/\]\] \}\}\n\n/g,']]\n\n');   // temporary
        myContent = myContent.replace(/\]\]‡ \}\}\n\n/g,']]‡\n\n');   // temporary

        myContent = myContent.replace(/\n\*[ ]*\<\!--[ \n]*--\>[ ]*/g,'\n* ');

        myContent = myContent.replace(/\}\}\n\<noinclude/g,'}}<noinclude');

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

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

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); }

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

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