User:Synoman Barris/common.js

From Wikibooks, open books for an open world
Jump to navigation Jump to search
Note: After saving, changes may not occur immediately. Click here to learn how to bypass your browser's cache.
  • Mozilla / Firefox / Safari: hold down Shift while clicking Reload, or press Ctrl-Shift-R (Cmd-Shift-R on Apple Mac);
  • Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5;
  • Konqueror: simply click the Reload button, or press F5;
  • Opera users may need to completely clear their cache in Tools→Preferences.
//UserInfo on all Userpages

mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:SMcCandlish/userinfo.js&action=raw&ctype=text/javascript');
//Remove Wikidata
mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:DannyS712/RemoveWikiData.js&action=raw&ctype=text/javascript');
//AutoUndoGlobal
mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:WhitePhosphorus/js/AutoUndoGlobal.js&action=raw&ctype=text/javascript');
//Accounts Created
//Run
mw.loader.load('//en.wikipedia.org/w/index.php?title=User:BrandonXLF/TestCode.js&action=raw&ctype=text/javascript');
mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:DannyS712/AccountsCreated.js&action=raw&ctype=text/javascript');
// Section Remover
mw.loader.load( "//en.wikipedia.org/w/index.php?title=User:DannyS712/SectionRemover.js&action=raw&ctype=text/javascript" );
// Citation Identifier
mw.loader.load( "//en.wikipedia.org/w/index.php?title=User:SuperHamster/CiteUnseen.js&action=raw&ctype=text/javascript" );


// [[File:Krinkle_Countervandalism.js]]
mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:Krinkle/Scripts/Countervandalism.js&action=raw&ctype=text/javascript');
$(document).ready( function () {
$('#firstHeading').after( $('.patrollink') );
} );
// rollback sum
mw.loader.load( "//en.wikipedia.org/w/index.php?title=User:Nageh/rollbackSum.js&action=raw&ctype=text/javascript" );
//<nowiki>
/* Cat-a-lot - changes category of multiple files */
mw.loader.using(['jquery.ui', 'mediawiki.util'], function(){
	mw.loader.load('//commons.wikimedia.org/w/load.php?modules=ext.gadget.Cat-a-lot');
});
////////// Cat-a-lot user preferences //////////
window.catALotPrefs = {"watchlist":"preferences","minor":true,"editpages":true,"docleanup":false,"subcatcount":10};
////////////////////////////////////catALotEnd//
//</nowiki>
//MYContribs
mw.loader.load( "//en.wikipedia.org/w/index.php?title=User:Mvolz/displayContributions.js&action=raw&ctype=text/javascript" );
//Edit war Checker
mw.loader.load("//en.wikipedia.org/w/index.php?title=User:Evad37/EditWarChecker.js&action=raw&ctype=text/javascript");
// Six tab button
mw.loader.load("//en.wikipedia.org/w/index.php?title=User:js/6tabs-vector.js&action=raw&ctype=text/javascript");
//Wiki gnome
mw.loader.load("//en.wikipedia.org/w/index.php?title=User:EpochFail/wikignome.js&action=raw&ctype=text/javascript");
//Adds more menus such as tools and analytical options
mw.loader.load('https://meta.wikimedia.org/w/index.php?action=raw&ctype=text/javascript&title=MediaWiki:MoreMenu.import.js');
// My Subpages
mw.loader.load( "//en.wikipedia.org/w/index.php?title=User:PrimeHunter/My_subpages.js&action=raw&ctype=text/javascript" );
// by [[m:user:Hoo man]] <http://meta.wikimedia.org/wiki/User:Hoo_man/Scripts/Active_sysops>
mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:Hoo_man/active_sysops.js&action=raw&ctype=text/javascript');
if(typeof(activeSysopsConfig) == 'undefined') activeSysopsConfig = {};
activeSysopsConfig.markWikisActiveSysops = true;
activeSysopsConfig.markWikisActiveSysopsLessThan = 1;
//diff-permalink
mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Enterprisey/diff-permalink.js&action=raw&ctype=text/javascript');
// Provides several useful functions for rollback (custom edit summary, mark as bot edits and mass revert)
// by [[m:user:Hoo man]] <http://meta.wikimedia.org/wiki/User:Hoo_man/Scripts/Smart_rollback>
mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:Hoo_man/smart_rollback.js&action=raw&ctype=text/javascript');
if(typeof(smartRollbackConfig) === 'undefined') smartRollbackConfig = {};
smartRollbackConfig.editSummaries = {};
smartRollbackConfig.editSummaries[0] = 'Revert; LTA Vandalism';
smartRollbackConfig.editSummaries[1] = 'Test edits/Assume Good Faith';
smartRollbackConfig.editSummaries[2] = 'UNexplained addition/Removal of huge text';
smartRollbackConfig.editSummaries[3] = 'Link Spamming/Promotional Links/Self Published Links';
smartRollbackConfig.editSummaries[4] = 'Mass changes to the content without consensus/sources/references';

// Next page in selected category
mw.loader.load( "//en.wikipedia.org/w/index.php?title=User:Danski454/cat-next.js&action=raw&ctype=text/javascript" );
// Article Quality
mw.loader.load("//en.wikipedia.org/w/index.php?title=User:EpochFail/ArticleQuality.js&action=raw&ctype=text/javascript");
//Number of tags in Article
mw.loader.load("//en.wikipedia.org/w/index.php?title=User:Ugog Nizdast/displayNumberOfTags.js&action=raw&ctype=text/javascript");
//Last Editor Info
mw.loader.load("//en.wikipedia.org/w/index.php?title=User:Eizzen/LastEditor.js&action=raw&ctype=text/javascript");
//InspectChange
mw.loader.load("//en.wikipedia.org/w/index.php?title=User:Writ Keeper/Scripts/commonHistory.js&action=raw&ctype=text/javascript");
//Page Info
mw.loader.load('//www.mediawiki.org/w/index.php?title=XTools/ArticleInfo.js&action=raw&ctype=text/javascript');
//Deletion Finder
mw.loader.load("//en.wikipedia.org/w/index.php?title=User:Writ_Keeper/Scripts/deletionFinder.js&action=raw&ctype=text/javascript");
//FancyDIFF
mw.loader.load("//en.wikipedia.org/w/index.php?title=User:Enterprisey/fancy-diffs.js&action=raw&ctype=text/javascript");
mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:Xiplus/TwinkleGlobal.js&action=raw&ctype=text/javascript');
// Unreliable sources detector
mw.loader.load("//en.wikipedia.org/w/index.php?title=User:Headbomb/unreliable.js&action=raw&ctype=text/javascript");
//QuickNote

mw.loader.load("https://en.wikipedia.org/wiki/User:Awesome Aasim/quicknote.js?action=raw&ctype=text/javascript");
$.when(mw.loader.using(['mediawiki.util'], $.ready)).done( function() {
	mw.util.addPortletLink("p-tb", mw.config.get('wgArticlePath').replace('$1', "Project:AutoWikiBrowser/Script"), "JS Wiki Browser", "tb-awbscript", "Run Javascript Wiki Browser");
});

if (mw.config.get('wgCanonicalNamespace')+':'+mw.config.get('wgTitle') === 'Project:AutoWikiBrowser/Script' && mw.config.get('wgAction') == 'view')
	mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Joeytje50/JWB.js&action=raw&ctype=text/javascript');
mw.loader.using(['mediawiki.util', 'mediawiki.api'], function() {

var config = mw.config.get([
	'debug',
	'wgAction',
	'wgArticleId',
	'wgCategories',
	'wgMonthNames',

	'wgNamespaceNumber',
	'wgPageName',
	'wgRelevantUserName'
]);

$( document ).ready( function () {
	if ( ( $( '#ca-addsection' ).length > 0 ||
		$.inArray( 'Non-talk pages that are automatically signed', config.wgCategories )  >= 0 ) &&
		config.wgAction === 'view' &&
		$.inArray( 'Pages that should not be manually archived', config.wgCategories ) === -1 ) {
		var OCAstate = mw.user.options.get( 'userjs-OCA-enabled', 'true' );
		var pageid = config.wgArticleId;
		var errorLog = { errorCount: 0 };
		new mw.Api().get( {
			action: 'query',
			prop: [ 'revisions', 'info' ],
			rvsection: 0,
			rvprop: 'content',
			pageids: pageid,
			indexpageids: 1,
			rawcontinue: ''
		} ).done( function ( response0 ) {
			var thisMonthNum, thisMonthFullName, monthNamesShort, thisMonthShortName, thisYear, archiveNum;
			
			var content0 = response0.query.pages[ pageid ].revisions[ 0 ][ '*' ];
 
			/* archiveme */// Find out if there is already an {{Archive me}} request, and if it is between 1-2 months old
			if ( config.wgNamespaceNumber === 3 ) {
				thisMonthNum = new Date().getMonth();
				thisMonthFullName = config.wgMonthNames[ thisMonthNum + 1 ];
				monthNamesShort = [ "", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ];
				thisMonthShortName = monthNamesShort[ thisMonthNum + 1 ];
				thisYear = new Date().getFullYear();
				var nowOcto = parseInt( ( ( thisYear * 12 ) + thisMonthNum + 1 ), 10 );
				var archiveme = content0.match( /\{\{Archive ?me(\| *date *= *(January|February|March|April|May|June|July|August|September|October|November|December) ([\d]{4}))?\}\}/i );
				if ( archiveme === null || archiveme === undefined ) {
					errorLog.errorCount++;
					errorLog.archiveme = '{{Archiveme}} not found.';
				} else {
					/* Archive me found - how old is it? */
					var archivemeMonth = archiveme[ 2 ];
					var archivemeMonthNum = 0;
					if ( typeof archivemeMonth === 'number' ) {
						archivemeMonthNum = parseInt( archivemeMonth, 10 );
					} else {
						for ( var i in config.wgMonthNames ) {
							if ( archivemeMonth === config.wgMonthNames[ i ] ) {
								archivemeMonthNum = parseInt( i, 10 );
							} else if ( archivemeMonth === monthNamesShort[ i ] ) {
								archivemeMonthNum = parseInt( i, 10 );
							}
						}
					}
					var archivemeYear = parseInt( archiveme[ 3 ], 10 );
					var archivemeOcto = parseInt( ( ( archivemeYear * 12 ) + archivemeMonthNum ), 10 );
					var archivemeSafe = parseInt( ( nowOcto - 2 ), 10 );
					archiveme = archiveme[ 0 ];
				}
			}
 
			/* counter */// Get the counter value
			var counterRegEx = new RegExp( '\\| *counter *= *(\\d+)' );
			var counter = counterRegEx.exec( content0 );
			if ( counter === null || counter === undefined ) {
				counter = 1;
				errorLog.errorCount++;
				errorLog.counter = counter;
			} else {
				counter = counter[ 1 ];
				archiveNum = counter;
			}
 
			/* archiveName */// Get the archiveName value
			var archiveNameRegEx = /\| *archive *= *(.*\%\(counter\)d.*) *(-->)?/;
			var archiveName = archiveNameRegEx.exec( content0 );
			var rootBase = config.wgPageName
					.replace( /\/.*/g, '' )// Chop off the subpages
					.replace( /_/g, ' ' );// Replace underscores with spaces
			if ( archiveName === null || archiveName === undefined ) {
				archiveName = rootBase + '/Archive ' + counter;
				errorLog.errorCount++;
				errorLog.archiveName = archiveName;
			} else { 
				archiveName = archiveName[ 1 ]
					.replace( /\| *archive *= */, '' )
					.replace( /\%\(year\)d/g, thisYear )
					.replace( /\%\(month\)d/g, thisMonthNum )
					.replace( /\%\(monthname\)s/g, thisMonthFullName )
					.replace( /\%\(monthnameshort\)s/g, thisMonthShortName )
					.replace( /\%\(counter\)d/g, archiveNum );
				var archiveBase = archiveName
					.replace( /\/.*/, '' )// Chop off the subpages
					.replace( /_/g, ' ' );// Replace underscores with spaces
				var archiveSub = archiveName
					.replace( /_/g, ' ' )// Replace underscores with spaces
					.replace( archiveBase, '' );// Chop off the base pagename
				if ( archiveBase != rootBase ) {
					errorLog.errorCount++;
					errorLog.archiveName = 'Archive name mismatch:<br /><br />Found: ' + archiveName;
					errorLog.archiveName += '<br />Expected: ' + rootBase.replace( '_', ' ' ) + archiveSub + '<br /><br />';
				}
			}
 
			/* archivepagesize */// Get the size of the destination archive from the API
			new mw.Api().get( {
				action: 'query',
				prop: 'revisions',rvlimit: 1,
				rvprop: [ 'size', 'content' ],
				titles: archiveName,
				list: 'usercontribs',
				uclimit: 1,
				ucprop: 'timestamp',
				ucuser: ( ( config.wgRelevantUserName ) ?
					config.wgRelevantUserName : 'Example' ),
				rawcontinue: '',
			} ).done( function ( archivePageData ) {
				var archivePageSize = 0;
				if ( archivePageData.query.pages[ -1 ] === undefined ) {
					for ( var a in archivePageData.query.pages ) {
						archivePageSize = parseInt( archivePageData.query.pages[ a ].revisions[ 0 ].size, 10 );
						archiveName = archivePageData.query.pages[ a ].title;
					}
				} else {
					archivePageSize = -1;
					archiveName = archivePageData.query.pages[ archivePageSize ].title;
					errorLog.errorCount++;
					errorLog.archivePageSize = -1;
					errorLog.archiveName = '<a class="new" href="' +
						mw.util.getUrl( archiveName, { action: 'edit', redlink: '1' } ) +
						'" title="' + archiveName + '">' + archiveName + '</a>';
				}
 
				/* maxarchivesize */// Get the defined max archive size from template
				var maxArchiveSizeRegEx = new RegExp( '\\| *maxarchivesize *= *(\\d+K?)' );
				var maxArchiveSize = maxArchiveSizeRegEx.exec( content0 );
				if ( maxArchiveSize === null || maxArchiveSize[ 1 ] === undefined ) {
					maxArchiveSize = parseInt( 153600, 10 );
					errorLog.errorCount++;
					errorLog.maxArchiveSize = maxArchiveSize;
				} else if ( maxArchiveSize[ 1 ].slice( -1 ) === "K" && $.isNumeric( maxArchiveSize[ 1 ].slice( 0, maxArchiveSize[ 1 ].length-1 ) ) ) {
					maxArchiveSize = parseInt( maxArchiveSize[ 1 ].slice( 0, maxArchiveSize[ 1 ].length - 1 ), 10 ) * 1024;
				} else if ( $.isNumeric( maxArchiveSize[ 1 ].slice() ) ) {
					maxArchiveSize = parseInt( maxArchiveSize[ 1 ].slice(), 10 );
				}
 
				/* pslimit */// If maxArchiveSize is defined, and archivePageSize >= maxArchiveSize increment counter and redfine page name.
				if ( !errorLog.maxArchiveSize && archivePageSize >= maxArchiveSize ) {
					counter++;
					archiveName = archiveNameRegEx.exec( content0 );
					archiveName = archiveName[ 1 ]
						.replace( /\| *archive *= */, '' )
						.replace( /\%\(year\)d/g, thisYear )
						.replace( /\%\(month\)d/g, thisMonthNum )
						.replace( /\%\(monthname\)s/g, thisMonthFullName )
						.replace( /\%\(monthnameshort\)s/g, thisMonthShortName )
						.replace( /\%\(counter\)d/g, counter );
					var oldCounter = counterRegEx.exec( content0 );
					var newCounter = '|counter=1';
					if ( oldCounter !== null && oldCounter !== undefined ) {
						newCounter = oldCounter[ 0 ].replace( oldCounter[ 1 ], counter );
						oldCounter = oldCounter[ 0 ];
					} else {
						errorLog.errorCount++;
						errorLog.newCounter = newCounter;
					}
				}
 
				/* archiveheader */// Get the defined archive header to place on archive page if it doesn't exist
				var archiveHeaderRegEx = new RegExp( '\\| *archiveheader *= *(\{\{[^\r\n]*\}\})' );
				var archiveHeader = archiveHeaderRegEx.exec( content0 );
				if ( archiveHeader === null || archiveHeader === undefined ) {
					archiveHeader = "{{Aan}}";
					errorLog.errorCount++;
					errorLog.archiveHeader = archiveHeader;
				} else {
					archiveHeader = archiveHeader[ 1 ];
				}
 
				/* headerlevel */// Get the headerlevel value or default to '2'
				var headerLevelRegEx = new RegExp( '\\| *headerlevel *= *(\\d+)' );
				var headerLevel = headerLevelRegEx.exec( content0 );
				if ( headerLevel === null || headerLevel === undefined ) {
					headerLevel = 2;
					errorLog.errorCount++;
					errorLog.headerLevel = headerLevel;
				} else {
					headerLevel = parseInt( headerLevel[ 1 ] );
				}
 
				/* debug */// Table to report the values found.
				if ( config.debug === true ) {
					var OCAreport = '<table style="width: 100%;" border="1"><tr><th style="font-variant: small-caps; font-size: 20px;">config</th><th style="font-variant: small-caps; font-size: 20px;">value</th></tr>';
					OCAreport += '<tr><td>Counter</td><td style="text-align: center;';
					if ( errorLog.counter ) { OCAreport += ' background-color: #FFEEEE;">' + errorLog.counter; }
						else { OCAreport += '">' + counter; }
					OCAreport += '</td></tr><tr><td colspan="2" style="text-align: center;">Archive name</td></tr><tr><td colspan="2" style="text-align: center;';
					if ( errorLog.archiveName ) { OCAreport += ' background-color: #FFEEEE;">' + errorLog.archiveName; }
						else { OCAreport += '">' + archiveName; }
					OCAreport += '</td></tr><tr><td>Header Level</td><td style="text-align: center;';
					if ( errorLog.headerLevel ) { OCAreport += ' background-color: #FFEEEE;">' + errorLog.headerLevel; }
						else { OCAreport += '">' + headerLevel; }
					OCAreport +=  '</td></tr><tr><td>Archive header</td><td style="text-align: center;';
					if ( errorLog.archiveHeader ) { OCAreport += ' background-color: #FFEEEE;">' + errorLog.archiveHeader; }
						else { OCAreport += '">' + archiveHeader; }
					OCAreport +=  '</td></tr><tr><td>Max<br />archive size</td><td style="text-align: center;';
					if ( errorLog.maxArchiveSize ) { OCAreport += ' background-color: #FFEEEE;">' + errorLog.maxArchiveSize; }
						else { OCAreport += '">' + maxArchiveSize; }
					OCAreport +=  '</td></tr><tr><td>Current<br />archive size</td><td style="text-align: center;';
					if ( errorLog.archivePageSize ) { OCAreport += ' background-color: #FFEEEE;">' + archivePageSize; }
						else if ( archivePageSize >= maxArchiveSize ) { OCAreport += ' background-color: #FFEEEE;">' + archivePageSize; }
						else { OCAreport += '">' + archivePageSize; }
					if ( !errorLog.archiveme && archiveme !== undefined ) {
						OCAreport +=  '</td></tr><tr><td colspan="2" style="text-align: center;';
						if ( ( nowOcto - archivemeOcto ) <= 1 ) { OCAreport += '">Asked to archive '; }
						if ( ( nowOcto - archivemeOcto ) === 0 ) { OCAreport += 'this month'; }
						else if ( ( nowOcto - archivemeOcto ) === 1 ) { OCAreport += 'last month'; }
						else { OCAreport += ' background-color: #FFEEEE;">Asked to archive ' + ( nowOcto - archivemeOcto ) + ' months ago'; }
					}
					if ( errorLog.archiveme || archiveme !== undefined ) { OCAreport +=  '</td></tr><tr><td colspan="2" style="text-align: center;'; }
						if ( errorLog.archiveme ) { OCAreport +=  ' background-color: #FFEEEE;">' + errorLog.archiveme; }
						else if ( archiveme !== undefined ) { OCAreport += '">' + archiveme; }
					OCAreport +=  '</td></tr><tr><td colspan="2" style="font-size: larger; text-align: center;"><a href="/wiki/User:Technical_13/Scripts/OneClickArchiver" title="User:Technical 13/Scripts/OneClickArchiver">Documentation</a></td></tr></table>';
					mw.notify( $( OCAreport ), { title: 'OneClickArchiver report!', tag: 'OCA', autoHide: false } );
				}
 
				var OCAerror = '<p>The following errors detected:<br />';
				if ( errorLog.counter ) { OCAerror += '<b style="font-size: larger; color: #FF0000;">&bull;</b>&nbsp;Unable to find <b>|counter=</b><br />&nbsp; &nbsp; &nbsp;Default value: <b>1</b><br />'; }
				if ( errorLog.archiveName && errorLog.archiveName.search( 'defaulted to' ) !== -1 ) { OCAerror += '<b style="font-size: larger; color: #FF0000;">&bull;</b>&nbsp;Unable to find <b>|archive=</b><br />&nbsp; &nbsp; &nbsp;Default value: <b>' + archiveName + '</b><br />'; }
				if ( errorLog.archiveName && errorLog.archiveName.search( 'mismatch' ) !== -1 ) { OCAerror += '<b style="font-size: larger; color: #FF0000;">&bull;</b>&nbsp;Archive name mismatch detected.<br />'; }
				if ( errorLog.headerLevel ) { OCAerror += '&nbsp; Unable to find <b>|headerlevel=</b><br />&nbsp; &nbsp; &nbsp;Default value: <b>2</b><br />'; }
				if ( errorLog.archiveHeader ) { OCAerror += '&nbsp; Unable to find <b>|archiveheader=</b><br />&nbsp; &nbsp; &nbsp;Default value: <b>"{{Aan}}"</b><br />'; }
				if ( errorLog.maxArchiveSize ) { OCAerror += '&nbsp; Unable to find <b>|maxarchivesize=</b><br />&nbsp; &nbsp; &nbsp;Default value: <b>153600</b><br />'; }
				if ( errorLog.counter || errorLog.archiveName ) { OCAerror += '<br /><b style="font-size: larger; color: #FF0000;">&bull;</b>&nbsp;Causing the script to abort.<br />'; }
				OCAerror += '<br /><span style="font-size: larger;">Please, see <a href="/wiki/User:Technical_13/Scripts/OneClickArchiver" title="User:Technical 13/Scripts/OneClickArchiver">the documentation</a> for details.</span></p>';
				var archiverReport = mw.util.addPortletLink(
					'p-cactions',
					'#archiverNoLink',
					'|Archive',
					'pt-OCA-report',
					'Report for why there are no |Archive links on this page',
					null,
					null
				);
				$( archiverReport ).click( function ( e ) {
					e.preventDefault();
					mw.notify( $( OCAerror ), { title: 'OneClickArchiver errors!', tag: 'OCAerr', autoHide: false } );
				} );
 
				if ( config.wgNamespaceNumber === 3 && ( errorLog.counter || errorLog.archiveName ) &&
				config.debug === true && errorLog.archiveme )  {
					if ( confirm( 'Click [OK] to post {{Archiveme|{{SUBST:DATE}}}} to the top of the page and abort or\n\t[Cancel] to attempt running with default values.' ) === true ) {
						new mw.Api().postWithToken( 'edit', {
							action: 'edit',
							section: 0,
							pageid: pageid,
							text: '{{Archiveme|{{SUBST:DATE}}}}\n' + content0,
							summary: '{{[[Template:Archiveme|Archiveme]]}} posted with [[User:Evad37/OneClickArchiver|OneClickArchiver]].'
						} ).done( function () {
							alert( 'Request for user to set up archiving posted.' );
							location.reload();
						} );
					}
				} else if ( config.wgNamespaceNumber === 3 && archivemeOcto >= archivemeSafe ) {
 
					/* Archive me request was made, give the user a chance to comply */
 
				} else if ( config.wgNamespaceNumber === 3 && ( errorLog.counter || errorLog.archiveName ) && config.debug === true && confirm( '{{Archiveme}} found on the top of the page:\n\n\t Click [OK] abort or\n\t[Cancel] to attempt running with default values.' ) === true ) {
 
					/* User aborted script */
 
				} else {
					$( 'h' + headerLevel + ' span.mw-headline' ).each( function() {
						var sectionName = $( this ).text();
						var editSectionUrl = $( this ).parent().find('.mw-editsection a').not('.mw-editsection-visualeditor').first().attr( 'href' );
						var sectionReg = /&section=(.*)/;
						var sectionRaw = sectionReg.exec( editSectionUrl );
						if ( sectionRaw != null && sectionRaw[ 1 ].indexOf( 'T' ) < 0 ) {
							var sectionNumber = parseInt( sectionRaw[ 1 ] );
							if ( $( this ).parent().prop( 'tagName' ) === 'H' + headerLevel ) {
 
								$( this ).parent( 'h' + headerLevel ).append(
									' <div style="font-size: 0.6em; font-weight: bold; float: right;"> | <a id="' + sectionNumber +
									'" href="#archiverLink" class="archiverLink">' + 'Archive' + '</a></div>'
								);
								$(this).parent('h' + headerLevel).find('a.archiverLink').attr('title', 'Archive to: "'+archiveName+'"');
								$( this ).parent( 'h' + headerLevel ).find( 'a.archiverLink' ).click( function() {
 
									var mHeaders = '<span style="color: #444444;">Retrieving headers...</span>';
									var mSection = 'retrieving section content...';
									var mPosting = '<span style="color: #004400">Content retrieved,</span> performing edits...';
									var mPosted = '<span style="color: #008800">Archive appended...</span>';
									var mCleared = '<span style="color: #008800">Section cleared...</span>';
									var mReloading = '<span style="color: #000088">All done! </span><a href="#archiverLink" onClick="javascript:location.reload();" title="Reload page">Reloading</a>...';
 
									$( 'body' ).append( '<div class="overlay" style="background-color: #000000; opacity: 0.4; position: fixed; top: 0px; left: 0px; width: 100%; height: 100%; z-index: 500;"></div>' );					
 
									$( 'body' ).prepend( '<div class="arcProg" style="font-weight: bold; box-shadow: 7px 7px 5px #000000; font-size: 0.9em; line-height: 1.5em; z-index: 501; opacity: 1; position: fixed; width: 50%; left: 25%; top: 30%; background: #F7F7F7; border: #222222 ridge 1px; padding: 20px;"></div>' );
 
									$( '.arcProg' ).append( '<div>' + mHeaders + '</div>' );
 
									$( '.arcProg' ).append( '<div>' + 'Archive name <span style="font-weight: normal; color: #003366;">' + archiveName + '</span> <span style="color: darkgreen;">found</span>, ' + mSection + ' (' + archivePageSize + 'b)</div>' );
									new mw.Api().get( {
										action: 'query',
										pageids: pageid,
										rvsection: sectionNumber,
										prop: [ 'revisions', 'info' ],
										rvprop: 'content',
										indexpageids: 1,
										rawcontinue: ''
									} ).done( function ( responseSection ) {
										var sectionContent = responseSection.query.pages[ pageid ].revisions[ 0 ][ '*' ];
										$( '.arcProg' ).append( '<div>' + mPosting + '</div>' );
 
										var dnau = sectionContent.match( /<!-- \[\[User:DoNotArchiveUntil\]\] ([\d]{2}):([\d]{2}), ([\d]{1,2}) (January|February|March|April|May|June|July|August|September|October|November|December) ([\d]{4}) \(UTC\) -->/ );
										var dnauDate;
										if ( dnau === null || dnau === undefined ) {
											dnauDate = Date.now();
											dnau = null;
										} else {
											dnau = dnau[ 1 ] + ':' + dnau[ 2 ] + ' ' + dnau[ 3 ] + ' ' + dnau[ 4 ] + ' ' + dnau[ 5 ];
											dnauDate = new Date( dnau );
											dnauDate = dnauDate.valueOf();
										}
 
										if ( dnauDate > Date.now() ) {
											$( '.arcProg' ).remove();
											$( '.overlay' ).remove();
											var dnauAbortMsg = '<p>This section has been marked \"Do Not Archive Until\" ' + dnau + ', so archiving was aborted.<br /><br /><span style="font-size: larger;">Please, see <a href="/wiki/User:Technical_13/Scripts/OneClickArchiver" title="User:Technical 13/Scripts/OneClickArchiver">the documentation</a> for details.</span></p>';
											mw.notify( $( dnauAbortMsg ), { title: 'OneClickArchiver aborted!', tag: 'OCAdnau', autoHide: false } );
										} else {
											var archiveAction = 'adding section';
											if ( archivePageSize <= 0 || ( archivePageSize >= maxArchiveSize && !errorLog.maxArchiveSize ) ) {
												sectionContent = archiveHeader + '\n\n' + sectionContent;
												archiveAction = 'creating';
												mPosted = '<span style="color: #008800">Archive created...</span>';
											} else {
												sectionContent = '\n\n{{Clear}}\n' + sectionContent;
											}
 
											if ( dnau != null ) {
												sectionContent = sectionContent.replace( /<!-- \[\[User:DoNotArchiveUntil\]\] ([\d]{2}):([\d]{2}), ([\d]{1,2}) (January|February|March|April|May|June|July|August|September|October|November|December) ([\d]{4}) \(UTC\) -->/g, '' );
											}
 
											new mw.Api().postWithToken( 'edit', {
												action: 'edit',
												title: archiveName,
												appendtext: sectionContent,
												summary: '/* '+sectionName+' */ archived using [[User:Evad37/OneClickArchiver|OneClickArchiver]])'
											} ).done( function () {
												$( '.arcProg' ).append( '<div class="archiverPosted">' + mPosted + '</div>' );
												new mw.Api().postWithToken( 'edit', {
													action: 'edit',
													section: sectionNumber,
													pageid: pageid,
													text: '',
													summary: '[[User:Evad37/OneClickArchiver|OneClickArchived]] "' + sectionName + '" to [[' + archiveName + ']]'
												} ).done( function () {
													$( '.arcProg' ).append( '<div class="archiverCleared">' + mCleared + '</div>' );
													if ( archivePageSize >= maxArchiveSize && !errorLog.maxArchiveSize ) {
														var mUpdated = '<span style="color: #008800">Counter updated...</span>';
														new mw.Api().postWithToken( 'edit', {
															action: 'edit',
															section: 0,
															pageid: pageid,
															text: content0.replace( oldCounter, newCounter ),
															summary: '[[User:Evad37/OneClickArchiver|OneClickArchiver]] updating counter.'
														} ).done( function () {
															$( '.arcProg' ).append( '<div class="archiverPosted">' + mUpdated + '</div>' );
															$( '.arcProg' ).append( '<div>' + mReloading + '</div>' );
															location.reload();
														} );
													} else {
														$( '.arcProg' ).append( '<div>' + mReloading + '</div>' );
														location.reload();
													}
												} );
											} );
										}
									} );
								} );
							}
						}
					} );
				}
			} );
		} );
		var linkTextD = '1CA is on', linkDescD = 'Disable OneClickArchiver';
		var linkTextE = '1CA is off', linkDescE = 'Enable OneClickArchiver';
		var linkText = linkTextD, linkDesc = linkDescD;
		if ( OCAstate === 'false' ) {
			linkText = linkTextE; linkDesc = linkDescE;
			$( 'div.archiverDiv, li#pt-OCA-report' ).css( 'display', 'none' );
		}
		var archiverToggle = mw.util.addPortletLink(
			'p-cactions',
			'#archiverLink',
			linkText,
			'pt-OCA',
			linkDesc,
			'o',
			null
		);
		$( archiverToggle ).click( function ( e ) {
			e.preventDefault();
			/* Toggle the archiveLinks */
			$( 'div.archiverDiv' ).css( 'display', function ( _i, val ) {
				return val === 'none' ? '' : 'none';
			});
			/* Toggle the toggle link */
			$( 'li#pt-OCA a' ).html( function ( _i, val ) {
				return val === linkTextD ? linkTextE : linkTextD;
			});
			/* Toggle the toggle description */
			$( 'li#pt-OCA a' ).attr( 'title', function ( _i, val ) {
				return val === linkDescD ? linkDescE : linkDescD;
			});
			/* Toggle the error report link */
			if ( ( errorLog.counter || errorLog.archiveName ) ) {
				$( 'li#pt-OCA-report' ).css( 'display', function ( _i, val ) {
					return val === 'none' ? '' : 'none';
				});
			}
			/* Toggle default state */
			new mw.Api().postWithToken( 'options', {
				action: 'options',
				optionname: 'userjs-OCA-enabled',
				optionvalue: OCAstate === 'true' ? 'false' : 'true'
			} ).done( function() {
				var resultMsg = 'OneClickArchiver is now ' + ( OCAstate === 'true' ? 'disabled' : 'enabled' ) + ' by default.';
				mw.notify(resultMsg);
				OCAstate = OCAstate === 'true' ? 'false' : 'true';
			} );
		} );
	}
} );

});
// </nowiki>
mw.loader.load('https://commons.wikimedia.org/w/index.php?title=MediaWiki:Gadget-HotCat.js&action=raw&ctype=text/javascript');
$(document).ready( function () {
    // Remove redlinks if they exist upon pageload
    redlinks_removeall();
});
$(function($) {
	mw.loader.using( ['mediawiki.util'] ).then( function () {
		var portletlink = mw.util.addPortletLink('p-tb', '#', 'Remove redlinks');
		$(portletlink).click( function(e) {
			e.preventDefault();
			// Default parameters, and begin script on regular view of article
			var loc = window.location.href;
			var redlinks; var i;
			
			// Gather all redlinks with class "new"
			redlinks = [];
			var b = document.getElementsByTagName('b');
			for (i = 0; i < b.length; i++) {
				if (b[i].getAttribute('class') == "new") {
					redlinks[redlinks.length] = a[i].href.replace('https://en.wikipedia.org/w/index.php?title=','').replace('&action=edit&redlink=1','');
					redlinks[redlinks.length-1] = redlinks[redlinks.length-1].replace(/_/g,' ');
					redlinks[redlinks.length-1] = decodeURIComponent(redlinks[redlinks.length-1]);
				}
			}
			
			// Save all redlinks
			if (redlinks.length > 0) {
				localStorage.redlinks = JSON.stringify(redlinks);
				
				// If we are in the edit page, then remove redlinks automatically; if we are on the reading page, then go to the edit page
				if (window.location.href.indexOf('action') >= 0) redlinks_removeall();
				else window.location = window.location.href.substr(0, window.location.href.indexOf('#'))+"?action=edit";
			} else {
				alert('No redlinks!');
			}
		});
	});
});

function redlinks_removeall() {
	// Automatic removal of redlinks when stored.
    if (localStorage.redlinks !== "" && localStorage.redlinks !== undefined) {
		// Gather saved redlinks
		var redlinks = JSON.parse(localStorage.redlinks);
		
		// Regular expression to escape special characters
		var totalredlinks = 0;
		RegExp.quote = function(str) { return str.replace(/[.?*+^$[\]\\(){}|-]/g, "\\$&"); };
		
		var wpTextbox1 = document.getElementById('wpTextbox1');
		for (i = 0; i < redlinks.length; i++) {
			// Regular expression for piped links and direct links
			var reglink1 = new RegExp('\\[\\[\\s*('+RegExp.quote(redlinks[i]).replace(/\s/g, "[\\s\\_]*")+')\\s*\\|\\s*([^\\]]*)\\s*\\]\\]','gi');
			var reglink2 = new RegExp('\\[\\[\\s*('+RegExp.quote(redlinks[i]).replace(/\s/g, "[\\s\\_]*")+')\\s*\\]\\]','gi');
			
			// Add total number of matches for both
			if (wpTextbox1.value.match(reglink1) !== null) totalredlinks += wpTextbox1.value.match(reglink1).length;
			if (wpTextbox1.value.match(reglink2) !== null) totalredlinks += wpTextbox1.value.match(reglink2).length; // Includes categories
			
			// Remove category rather than simply convert it to unlinked text
			if (redlinks[i].substr(0,9) == "Category:") {
				var reglink3 = new RegExp('\\[\\[\\s*('+RegExp.quote(redlinks[i])+')\\s*\\]\\]\\n','gi');
				wpTextbox1.value = wpTextbox1.value.replace(reglink3,"");
			}
			
			// Remove redlinks and convert to unlinked text
			wpTextbox1.value = wpTextbox1.value.replace(reglink1,"$2");
			wpTextbox1.value = wpTextbox1.value.replace(reglink2,"$1");
		}
		
		// Alert for summary of removed redlinks; total in edit summary
		if (totalredlinks > 0) {
			document.getElementById('wpSummary').value += "Removed "+totalredlinks+" redlink"+(totalredlinks==1?"":"s")+" via [[User:Alex 21/script-redlinks|script]].";
			alert("Automatically removed "+totalredlinks+" redlink"+(totalredlinks==1?"":"s")+"!");
		} else {
			// Redlinks were seen in the article but none were found in the wikicode - check the nevigational boxes for these redlinks
			alert('No redlinks in the article! (Check transcluded templates and the navigational boxes.)');
		}
		
		// Remove the template(s)
		wbTextbox1.value = wbTextbox1.value.replace(/\{\{[Cc]leanup-?\s*[Rr]ed\s*[Ll]inks?[^\}]*\}\}/g, "");
		wbTextbox1.value = wbTextbox1.value.replace(/\{\{[Rr]ed\s*links?[^\}]*\}\}/g, "");
		wbTextbox1.value = wbTextbox1.value.replace(/\{\{[Tt]oo many red links[^\}]*\}\}/g, "");
		
		// Clear all saved redlinks
		localStorage.redlinks = '';
	}
}
mw.loader.load( 'https://en.wikipedia.org/w/index.php?title=User:Alex_21/script-functions.js&oldid=975890371&action=raw&ctype=text/javascript' );
importScript( 'User:Majavah/script-redlinks.js' ); // Backlink: [[User:Majavah/script-redlinks.js]]