User:NguoiDungKhongDinhDanh/AjaxCat.js

$(function {	if (mw.config.get('wgNamespaceNumber') !== 14) return;	// For attribution: //loading.io/css (CC0)	var css = `		.ajaxcat-loader-wrapper {			display: block;			margin: 3em 0;			text-align: center;		}		.ajaxcat-loader {			display: inline-block;			position: relative;			width: 80px;			height: 80px;		}		.ajaxcat-loader .ajaxcat-loader-items {			transform-origin: 40px 40px;		}		.ajaxcat-loader .ajaxcat-loader-items::after {			content: ' ';			display: block;			position: absolute;			top: 4px;			left: 36px;			width: 6px;			height: 18px;			border-radius: 20%;			background: #000000;		}		@keyframes ajaxcat-loader {			0% {				opacity: 1;			}			100% {				opacity: 0;			}		}	`;	try {		mw.util.addCSS(css);	} catch (e) {		mw.loader.addStyleTag(css);	}	$('body').on('click', '#mw-subcategories > a, #mw-pages > a, #mw-category-media > a', function(e) { e.preventDefault; var link = new mw.Uri($(this).attr('href')).extend({			action: 'render'		}).toString; var sect = link.split('#').pop; $('#' + sect + ' > a').replaceWith(function {			return $(' ').attr('data-href', $(this).attr('href')).append($(this).contents);		}); $('#' + sect + ' > ' + (sect !== 'mw-category-media' ? 'div' : 'ul') + ':first-of-type').hide.after(function {			var l = $(' ').attr('class', 'ajaxcat-loader');			for (let i = 0; i < 12; i++) {				l.append( $(' ')					.attr('class', 'ajaxcat-loader-items') .css({						'animation': 'ajaxcat-loader 1.2s linear infinite',						'transform': 'rotate(' + (i * 30) + 'deg)',						'animation-delay': Math.round((-1.1 + (i * 0.1)) * 10) / 10 + 's'					}) );			}			return $(' ').attr({ class: 'ajaxcat-loader-wrapper', id: 'ajaxcat-loader' }).append(l);		}); $.ajax({			url: link,			success: function(response) {				$('#' + sect).replaceWith($('#' + sect, response));			},			error: function {				$('#ajaxcat-loader').remove;				$('#' + sect + ' > span').replaceWith(function { return $('').attr('href', $(this).attr('data-href')).append($(this).contents); });				$('#' + sect + ' > div:first-of-type').show;				alert('Error: Cannot get pages.');			}		}); }); });