Jump to content

User:Alarbus/hlist.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') == 10 && mw.config.get('wgArticleId') != 0) { 
    addOnloadHook( function hlistEditButton() {
        mw.util.addPortletLink('p-cactions', 
                       mw.config.get('wgScript') + '?title=' + encodeURIComponent(mw.config.get('wgPageName')) + '&action=edit&hlist=true',
                       'hlist',
                       'p-hlist',
                       'hlist edit');
    }
)}
 
if(mw.config.get('wgAction') == 'edit' && hlist_queryString('hlist') == 'true') {
    addOnloadHook(function qscale() {
        var myContent = document.getElementById('wpTextbox1').value;
        myContent = myContent.replace(/\<\!--\(reduces gap between wrapped lines\)--\>/g,'');

        myContent = myContent.replace(/\{\{nowrap begin\}\}\n/g,'\n* ');
        myContent = myContent.replace(/\{\{nowrap begin\}\}/g,'\n* ');
        myContent = myContent.replace(/\{\{Nowrap begin\}\}\n/g,'\n* ');
        myContent = myContent.replace(/\{\{Nowrap begin\}\}/g,'\n* ');

        myContent = myContent.replace(/\{\{nowrap\|[ ]*/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(/\&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(/[ ]*\&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,'* ');

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

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

        myContent = myContent.replace(/\] - [ ]*\[/g,']\n* [');
        myContent = myContent.replace(/\] – [ ]*\[/g,']\n* [');
        myContent = myContent.replace(/\] &ndash; [ ]*\[/g,']\n* [');
        myContent = myContent.replace(/\{\{pbrk\}\}/g,'<br />');
        myContent = myContent.replace(/\|name\=/g,'|title=');

        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(/\|[ ]*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); }
else {
idx1 = 0;
idx2 = 0;
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); }


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