User:WOSlinker/hlist-private.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:WOSlinker/hlist-private. |
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\;|(?:\ \;| )(?:•|·)|\{\{nowrap[_ ]+begin\}\})[ ]*(\'?\'\')(?:[^\'\n]|[^\'\n]\')*(?:\{\{[ ]*(?:·|•|,|\*|!)(?:wrap|w|)[ ]*\}\}|\&bull\;|(?:\ \;| )(?:•|·))[ ]*\1/gi) >= 0 ) {
myContent = myContent.replace(/((?:[\n]|=|\{\{[ ]*(?:·|•|,|\*|!)(?:wrap|w|)[ ]*\}\}|\&bull\;|(?:\ \;| )(?:•|·)|\{\{nowrap[_ ]+begin\}\})[ ]*)(\'?\'\')((?:[^\'\n]|[^\'\n]\')*)((?:\{\{[ ]*(?:·|•|,|\*|!)(?:wrap|w|)[ ]*\}\}|\&bull\;|(?:\ \;| )(?:•|·)))[ ]*\2/gi, '$1$2$3$2$4');
}
while( myContent.search(/(?:[\n]|=|\{\{[ ]*(?:·|•|,|\*|!)(?:wrap|w|)[ ]*\}\}|\&bull\;|(?:\ \;| )(?:•|·)|\{\{nowrap[_ ]+begin\}\})[ ]*\'?\'\'(?:[^\'\n]|[^\'\n]\')*(?:\{\{[ ]*(?:·|•|,|\*|!)(?:wrap|w|)[ ]*\}\}|\&bull\;|(?:\ \;| )(?:•|·))/gi) >= 0 ) {
myContent = myContent.replace(/((?:[\n]|=|\{\{[ ]*(?:·|•|,|\*|!)(?:wrap|w|)[ ]*\}\}|\&bull\;|(?:\ \;| )(?:•|·)|\{\{nowrap[_ ]+begin\}\})[ ]*)(\'?\'\')((?:[^\'\n]|[^\'\n]\')*)((?:\{\{[ ]*(?:·|•|,|\*|!)(?:wrap|w|)[ ]*\}\}|\&bull\;|(?:\ \;| )(?:•|·)))/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(/\ \;\&bull\;[ ]*/g,'\n* ');
myContent = myContent.replace(/[ ]*\&bull\;[ ]*/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(/\'[ ]*-[ ]*\[/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\* \ \;/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(/\:\ \;/g,': ');
myContent = myContent.replace(/\ \;/g,' ');
myContent = myContent.replace(/\n\<\/div\>[ ]*\n/g,'\n');
// myContent = myContent.replace(/[ ]*\|\;[ ]*\n/g,'\n* ');
// myContent = myContent.replace(/[ ]*\|\;[ ]*/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]]';
};
}
)}