User:Andrybak/common.js

// 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 6 if(!/\bnocache=\b/.test(location.href)){let e=(e,t,n)=>(e=e.replace(/special:mypage/i,"User:"+mw.config.get("wgUserName")),$.get("https://"+t+"/w/api.php?titles="+e+"&origin=*&format=json&formatversion=2&uselang=content&maxage=86400&smaxage=86400&action=query&prop=revisions|info&rvprop=content&rvlimit=1").then((r=>{let o=r.query.pages[0];if(o.missing)return;let a=o.revisions[0].content;if(n&&"text/javascript"!==n||"javascript"!==o.contentmodel){if("text/css"!==n||"css"!==o.contentmodel)return $.Deferred.reject('Refused to load "'+e+'"@'+t+": content type mismatch");mw.loader.addStyleTag(a)}else{let e=document.createElement("script");e.innerHTML=a,document.head.appendChild(e)}}))),t=e=>{let t=/^(?:(?:https:)?\/\/(.*))?\/w\/index.php/.exec(e),n=/\btitle=([^=?&]*)/.exec(e);return t&&n&&/\baction=raw\b/.test(e)&&/\bctype=/.test(e)?[n[1],t[1]||mw.config.get("wgServerName")]:null};window.importScript=t=>{e(encodeURIComponent(t),mw.config.get("wgServerName"),"text/javascript")},window.importStyleSheet=t=>{e(encodeURIComponent(t),mw.config.get("wgServerName"),"text/css")};let n=mw.loader.load;mw.loader.load=function(r,o){let a=t(r);a?e(a[0],a[1],o):n.apply(mw.loader,[...arguments])};let r=mw.loader.getScript;mw.loader.getScript=function(n){let o=t(n);return o?e(o[0],o[1],"text/javascript"):r.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, fork of User:Σ/Testing facility/Archiver mw.loader.load( '/w/index.php?title=User:Joeytje50/JWB.js/load.js&action=raw&ctype=text/javascript' ); // Backlink: User:Joeytje50/JWB.js/load.js importScript('User:קיפודנחש/cat-a-lot.js'); // Backlink: User:קיפודנחש/cat-a-lot.js importScript('User:Jackmcbarn/editProtectedHelper.js'); // Backlink: User:Jackmcbarn/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 and comments in MediaWiki:Gadget-charinsert-core.js */ window.charinsertCustom = { "Wiki markup": ' Wikilinks: Template:+ Templates: {\{Sandbox.other||+}} {\{para|+}}  +        {\{Documentation}}  {\{Documentation|content=+}}', "Category cleanup": 'Categories: break.categorization.cycle:. ' +		'Template_categories: remove.content.categories.per.WP:CAT:. 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  +  +  ' + 'User_pages: user.sandbox.is.not.a.template:. user.page.is.not.a.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(/\[\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('categorization (WP:CAT)');				}			},			{				// 				name: '→',				script: function(editor) {					editor						.replace(/\{\{[cC]ollapsible option\}\}/gm, '')						.appendEditSummary('Template:Navbox documentation');				}				// 			},		]); }); }); // 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')						.replace(/ *[|]description= *[|]portal= *[|]help= *\}\}/, '}}')						.appendEditSummary('remove content categories per WP:CAT');				}			},			{				name: 'Nav2Side',				script: function(editor) {					editor						.replace(/ *[|] *type *= *navbox */g, '|type=sidebar')						.replace(/navigational boxes/g, 'sidebar templates')						.appendEditSummary('create a new 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'); importScript('User:Andrybak/Scripts/Not around.js'); // Backlink: User:Andrybak/Scripts/Not around.js