User:SizableShrimp/common/wlhtotals.js

// See totals at the top of WLH pages // Modified by: SizableShrimp // Author: RheingoldRiver $(function {	if (mw.config.get('wgCanonicalSpecialPageName') !== 'Whatlinkshere') return;	var title = $('#mw-whatlinkshere-target').val;	var ns = $('#namespace').val;	title = title ? title : mw.config.get('wgTitle').replace('WhatLinksHere/', );	async function getTransclusionsAndLinks {		var transclusionParams = {			action : 'query',			prop : 'linkshere|transcludedin',			titles : title,			lhlimit : 'max',			tilimit : 'max',			// lhnamespace : ns == 'all' ?  : ns,			// tinamespace : ns == 'all' ? '' : ns,		};		var api = new mw.Api;		var data = {			linkshere: [],			transcludedin: []		};		while (true) {			// console.log(transclusionParams);			var result = await api.get(transclusionParams);			// console.log(result);			var pages = result.query.pages;			for (var p in pages) {				var page = pages[p];				if (page.transcludedin) {					data.transcludedin = data.transcludedin.concat(page.transcludedin); }				if (page.linkshere) { data.linkshere = data.linkshere.concat(page.linkshere); }			}			if (data.transcludedin.length >= 10000 || data.linkshere.length >= 10000) { data.capped = true; }			if (result.continue !== undefined && !data.capped) { for (var param in result.continue) { transclusionParams[param] = result.continue[param]; }			} else { return data; }		}	}	getTransclusionsAndLinks.then(function(data) {		var lh = data.linkshere.length;		var ti = data.transcludedin.length;		var redirects = 0;		for (var i = 0; i < lh; i++) {			var page = data.linkshere[i];			if (page.redirect === "") {				redirects++;			}		}		var display = [			'Total links: ' + lh,			'Total redirects (not double redirects): ' + redirects,			'Total transclusions: ' + ti,		];		if (data.capped) {			display.push('Request capped at 10,000 to not overload API.');		}		var el = document.createElement('div');		$(el).html(display.join(' ')).insertAfter($('#firstHeading'));	}); });