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.
// See also: [[meta:User:Andrybak/global.js]]. Fake backlinks for tracking:
// * [[User:Enterprisey/diff-permalink-2.js]]
// * [[User:Andrybak/Scripts/copy-section-link.js]]
// See also: [[meta:User:Andrybak/vector-2022.js]]

// Enable caching for resource loads, see [[User:SD0001/Making_user_scripts_load_faster]], @revision 7
if(!/\bnocache=\b/.test(location.href)){let e=mw.config.values,t="text/javascript",r="text/css",n=(n,o,i)=>(n=n.replace(/special:mypage/i,"User:" e.wgUserName),$.get("https://" o "/w/api.php?titles=" n "&origin=*&format=json&formatversion=2&uselang=content&maxage=86400&smaxage=86400&action=query&prop=revisions|info&rvprop=content&rvlimit=1&inprop=protection").then(e=>{let a=e.query.pages[0];if(!a.missing){if(2!==a.ns&&8!==a.ns&&!a.protection.find(e=>"edit"===e.type&&"sysop"===e.level))return $.Deferred().reject('Refused to load "' n '"@' o ": unprotected page");let l=a.revisions[0].content;if(i&&i!==t||"javascript"!==a.contentmodel){if(i!==r||"css"!==a.contentmodel)return $.Deferred().reject('Refused to load "' n '"@' o ": content type mismatch");mw.loader.addStyleTag(l)}else document.head.appendChild(document.createElement("script")).innerHTML=l}})),o=e.wgServerName,i=e=>{let t=/^(?:(?:https:)?\/\/(.*))?\/w\/index.php/.exec(e),r=/\btitle=([^=?&]*)/.exec(e);return t&&r&&/\baction=raw\b/.test(e)&&/\bctype=/.test(e)?[r[1],t[1]||o]:null};window.importScript=e=>{n(encodeURIComponent(e),o,t)},window.importStyleSheet=e=>{n(encodeURIComponent(e),o,r)};let a=mw.loader.load;mw.loader.load=function(e,t){let r=i(e);r?n(r[0],r[1],t):a.apply(mw.loader,[...arguments])};let l=mw.loader.getScript;mw.loader.getScript=function(e){let r=i(e);return r?n(r[0],r[1],t):l.apply(mw.loader,[...arguments])}}

window.hh_highlight = "rgba(144, 238, 144, 0.14)";
importScript('User:Guywan/Scripts/HistoryHighlight.js'); // Backlink: [[User:Guywan/Scripts/HistoryHighlight.js]]
importScript('User:Andrybak/Scripts/Archiver.js'); // Backlink: [[User:Andrybak/Scripts/Archiver.js]]
importScript('User:Joeytje50/JWB.js/load.js'); // Backlink: [[User:Joeytje50/JWB.js/load.js]]

//importScript('User:קיפודנחש/cat-a-lot.js'); // Backlink: [[User:קיפודנחש/cat-a-lot.js]]
window.catALotPrefs = {editpages:  true, minor: false};
mw.loader.using(['mediawiki.util']).done(function() {
mw.loader.load('//commons.wikimedia.org/w/index.php?title=User:Andrybak/sandbox/Gadget-Cat-a-lot.js&action=raw&ctype=text/javascript');
	mw.loader.load('//commons.wikimedia.org/w/index.php?title=MediaWiki:Gadget-Cat-a-lot.css&action=raw&ctype=text/css', 'text/css');
});

importScript('User:Andrybak/sandbox/editProtectedHelper.js'); // Backlink: [[User:Andrybak/sandbox/editProtectedHelper.js]]
importScript('User:DannyS712/Draft_no_cat.js'); // Backlink: [[User:DannyS712/Draft no cat.js]]
importScript('User:Novem Linguae/Scripts/UserRightsDiff.js'); // Backlink: [[User:Novem Linguae/Scripts/UserRightsDiff.js]]

// Enable ↑ ↓ links of HotCat
window.hotcat_use_category_links = true;
/*
 * Add custom CharInsert entries. See instructions at [[MediaWiki talk:Edittools]] and
 * [[Help:CharInsert#Customization]] and comments in [[MediaWiki:Gadget-charinsert-core.js]]
 */
window.charinsertCustom = { 
	"Wiki markup": ' Wikilinks: [[Template: ]] Templates: {\{Sandbox.other|| }}  {\{para| }}  <var> </var>  <syntaxhighlight.lang="wikitext">\n \n</syntaxhighlight>  <code><nowiki> </nowiki></code>  {\{Documentation}}  {\{Documentation|content= }}',
	"Category cleanup":  'Categories: break.categorization.cycle:.  '  
		'Template_categories: remove.content.categories.per.[[WP:CAT#T|template.categorization.guidelines]]:. add.[[Template:Template.category]];.  {\{Template.category\n|topic=[[ ]]\n}}\n  \n|topic=[[ ]]\n  \n|description= \n  {\{Category.see.also| }}  not.just.navboxes;.  '  
		'{\{Sandbox.other|| }}  \n|type=navbox  \n|type=sidebar  <noinclude> </noinclude>  <includeonly> </includeonly>  '  
		'User_pages: user.sandbox.is.not.a.[[Help:Template|template]]:. [[Wikipedia:User.pages|user.page]].is.not.a.[[Help:Template|template]]:. remove.content.categories.from.a.user.page.per.[[WP:USERNOCAT]]:.  '  
		'{\{Navbox.documentation|3=\n==See.also== }}  {\{Documentation|content= }}  '
};

$.ready.then(function() {
	var scroll = true; // whether or not to scroll the first highlight into view
	// Highlight possible errors on template categories.
	if (mw.config.get('wgNamespaceNumber') !== 14)
		return;
	var pageName = mw.config.get('wgPageName');
	if (!(/[tT]emplates/.test(pageName) || /navigational_boxes/.test(pageName)))
		return;

	// 1. Highlight user pages in template categories
	var userRgx = /.*\/wiki\/User(_talk)?:[^/]*([Uu][Bb][Xx]|\/[Uu]serboxe[sn])?$/;
	$('#mw-pages a[href^="/wiki/User"]').each(function() {
		if (userRgx.test(this.href)) {
			$(this).css('outline', '2px solid orange');
			if (!scroll)
				return;
			this.scrollIntoView();
			scroll = false;
		}
	});

	// 2. Highlight possible categorization into content categories
	$('#mw-normal-catlinks a[href^="/wiki/Category:"]').each(function() {
		var excludes = ["Template", "template", "boxes",
			"WikiProject", "Wikipedia", "work_group", "stubs",
			"Documentation", "Main_Page"
		];
		var n = excludes.length;
		for (var i = 0; i < n; i  ) {
			if (this.href.includes(excludes[i]))
				return;    		
		}

		$(this).css('outline', '2px solid maroon');
		if (!scroll)
			return;
		this.scrollIntoView();
		scroll = false;
	});

	// 3. Highlight articles and all talk pages in template categories
	var articleRgx = /(.*\/wiki\/[^:/]*|.*\/wiki\/([A-Z][a-z]*_talk|Talk):.*)$/;
	$('#mw-pages a[href^="/wiki/"]').each(function() {
		if (articleRgx.test(this.href)) {
			$(this).css('outline', '2px solid maroon');
			if (!scroll)
				return;
			this.scrollIntoView();
			scroll = false;
		}
	});
});

// Wikitext clean up buttons
$.ajax('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js', { dataType:'script', cache:true }).then(function() {
	pathoschild.TemplateScript.add([
		{
			name: 'Wikitext cleanup',
			script: function(editor) {
				editor
					.replace(/\[\[[iI]mage[:]/g, '[[File:')
					.replace(/  *$/gm, '')
					.replace(/<br>/gi, '<br />')
					.replace(/<noinclude>[ \n]*<\/noinclude>/gm, '')
					.replace(/[{][{][Tt]emplate:/g, '{{')
					.replace(/info-op *= *text-align: *(center|left|right) *; *$/gm, 'info-a = $1')
					.replace(/usercategory  =/g, 'usercategory =')
					.replace(/description=Templates relating to (\[\[.*\]\])/g, 'topic=$1')
					.replace(/\{\{ *(Category:.*?)\}\}/g, '[[:$1]]')
					.appendEditSummary('cleaned up wikitext')
					.clickDiff();
			}
		},
		{
			name: 'Fix category links',
			script: function(editor) {
				editor
					.replace(/\{\{ *(Category:.*?)\}\}/g, '[[:$1]]')
					.appendEditSummary('fix category links')
					.clickDiff();
			}
		},
	]);
});

(function () { // for content categories on template pages
	if (mw.config.get('wgNamespaceNumber') !== 10)
		return;
	$.ajax('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js', { dataType:'script', cache:true }).then(function() {
		pathoschild.TemplateScript.add([
			{
				name: 'Content categories',
				script: function(editor) {
					editor
						.replace(/^\[\[(Category:((?!([tT]emplates|[nN]avigational boxes))[^|])*)([|].*)?\]\]$/gm, '* [[:$1]]')
						.appendEditSummary('per [[WP:CAT#T|template categorization guidelines]]');
				}
			},
			{
				// <nowiki>
				name: '→{{Navbox documentation}}',
				script: function(editor) {
					editor
						.replace(/\{\{[cC]ollapsible option\}\}/gm, '{{Navbox documentation}}')
						.appendEditSummary('[[Template:Navbox documentation|{{Navbox documentation}}]]');
				}
				// </nowiki>
			},
		]);
	});
})();
// for content categories on template Category pages
(function() {
	if (mw.config.get('wgNamespaceNumber') !== 14)
		return;
	$.ajax('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js', { dataType:'script', cache:true }).then(function() {
		pathoschild.TemplateScript.add([
			{
				name: 'CatRel',
				script: function(editor) {
					editor
						.replace(/\n\n*\[\[Category:(((?!([tT]emplates|navigational boxes))[^|])*)([|].*)?\]\]$/gm, '\n{{Category see also|$1}}')
						.replace(/ *[|]description= *[|]portal= *[|]help= *\}\}/, '}}')
						.appendEditSummary('remove content categories per [[WP:CAT#T|template categorization guidelines]]');
				}
			},
			{
				name: 'Nav2Side',
				script: function(editor) {
					editor
						.replace(/ *[|] *type *= *navbox */g, '|type=sidebar')
						.replace(/navigational boxes/g, 'sidebar templates')
						.appendEditSummary('create a new [[Wikipedia:SIDEBAR|sidebar template]] category');
				}
			},
		]);
	});
})();

/*** BEGIN WIKIBREAK ENFORCER ***/
$(document).ready(function() 
{
	var log = function(s) {
		console.log("[wikibreak enforcer] "   s);
	};
	// When you want to end your break?
	// no leading zeroes. (example: 9 - correct, 09 - incorrect)
	var date = { year: 2024, month: 4, day: 6 };
	var time = { hours: 23, minutes: 59, seconds: 59 };

	var currentDate = new Date();
	var enforcedBreakEnd = new Date(date.year, date.month - 1, date.day,
		time.hours, time.minutes, time.seconds);
	if (currentDate <= enforcedBreakEnd) {
		alert("Enforced wikibreak until "   enforcedBreakEnd.toLocaleString()
			  "\n(now is "   currentDate.toLocaleString()   ")\n\nBye!");
		mw.loader.using(["mediawiki.api", "mediawiki.user"]).then(function () {
			new mw.Api().post({
				action: 'logout',
				token: mw.user.tokens.get('csrfToken')
			}).done(function (data)	{
				location = "//"   location.host   "/w/index.php?title="
					  "Special:Userlogin&returnto=Main_Page";
			}).fail(function () {
				log("logout failed");
			});
		});
	}
});
/*** END WIKIBREAK ENFORCER ***/
//importScript('User:Anomie/unsignedhelper.js'); // Backlink: [[User:Anomie/unsignedhelper.js]]
importScript('User:Andrybak/Scripts/Unsigned_helper.js'); // Backlink: [[User:Andrybak/Scripts/Unsigned helper.js]]
importScript('User:Andrybak/Scripts/Unsigned_generator.js'); // Backlink: [[User:Andrybak/Scripts/Unsigned generator.js]]

window.scriptInstallerAutoReload = false;
window.scriptInstallerUnwatch = true;
importScript('User:Andrybak/sandbox/Gadget-script-installer.js'); // Backlink: [[User:Andrybak/sandbox/Gadget-script-installer.js]]
importScript('User:Andrybak/Scripts/Contribs_ranger.js'); // Backlink: [[User:Andrybak/Scripts/Contribs_ranger.js]]
importScript('User:BrandonXLF/WatchDoc.js'); // Backlink: [[User:BrandonXLF/WatchDoc.js]]
importScript('User:Rummskartoffel/share_ExpandTemplates_url.js'); // Backlink: [[User:Rummskartoffel/share_ExpandTemplates_url.js]]
importScript('User:Andrybak/sandbox/Section_redirect_note.js'); // Backlink: [[User:Andrybak/sandbox/Section redirect note.js]]
importScript('User:Amorymeltzer/logSwap.js'); // Backlink: [[User:Amorymeltzer/logSwap.js]]
importScript('User:Andrybak/Scripts/Not_around.js'); // Backlink: [[User:Andrybak/Scripts/Not_around.js]]