User:Eckserah/common.js

(function {	mw.loader.using( 'mw.Api' ).then(function { var api = new mw.Api; var actualPageLinks = "No Links Found"; var linkBase = "https://fallout.fandom.com/wiki/"; var processingLinks = false; var numLinks = 0; function getLinksFromPage(pageName) { api.get({				action: 'query',				prop: 'linkshere',				format: 'json',				lhshow: '!redirect',				lhlimit: 500,				titles: pageName			}).done(function(e) {				var linkInfos = e.query.pages;		       for (var titleLink in linkInfos) {		        	if (linkInfos[titleLink].linkshere !== undefined) {			            numLinks = linkInfos[titleLink].linkshere.length;			            for (var linkInf in linkInfos[titleLink].linkshere) {			                var linkCheck = checkIfLinksReal(linkInfos[titleLink].linkshere[linkInf],pageName);			            }		        	} else {		        		$('#AllWhatLinksHere').append(actualPageLinks);		        		$('#LoadingInfo').hide;		        	}		        }			}); }		function checkIfLinksReal(pageLinks, basePageName) { api.get({				action: 'parse',				prop: 'wikitext',				format: 'json',				page: pageLinks.title			}).done(function(data) {				if (data.error === undefined) {		           var wikitext = data.parse.wikitext['*'];		            if (findLinkInPage(basePageName, wikitext))		                $('#AllWhatLinksHere').append($(''+pageLinks.title+' '));		            numLinks = numLinks - 1;		            if (numLinks === 0) {		            	if ($('#AllWhatLinksHere').find('a').length === 0)		            		$('#AllWhatLinksHere').append(actualPageLinks);		                $('#LoadingInfo').hide;		                processingLinks = false;		            }		        } else {		        	numLinks = numLinks - 1;		        	console.log(parseWikiTextUrl+pageLinks.title);		        	console.log(data.error);		        }			}); }		function findLinkInPage(SearchPageTitle, wikiText) { var modPageTitle = SearchPageTitle.replace(/[ _]/g,'[ _]'); var regexStr = '\\[\\[' + modPageTitle + '*[^\\]]+\\]\\]'; var testReg = new RegExp(regexStr); return testReg.test(wikiText); }		$(document).ready(function {			var IsBetterWhatLinksHere = $('#BetterWhatLinksHere');			if (IsBetterWhatLinksHere.length > 0) {				$('#BetterWhatLinksHereForm').submit(function(e) { e.preventDefault; if (processingLinks) return; processingLinks = true; $('#LoadingInfo').show; $('#AllWhatLinksHere').html(''); var searchText = $('#BetterWhatLinksHereForm').find('input[type=text]').val; if (searchText !== '') { setTimeout(function {							getLinksFromPage(decodeURIComponent(searchText));						}, 200); }					return false; });				if (location.hash !== '') {					$('#BetterWhatLinksHereForm').find('input[type=text]').val(location.hash.substring(1));					$('#BetterWhatLinksHereForm').submit;				}			}			var whatLinksHere = $('#WikiaBarWrapper').find('[data-name=whatlinkshere]').parent.clone;			whatLinksHere.find('a').prop('href',whatLinksHere.find('a').prop('href').replace('Special:WhatLinksHere/','User:Eckserah/BetterWhatLinksHere#')).text('What really links here');			whatLinksHere.insertAfter($('#WikiaBarWrapper').find('[data-name=whatlinkshere]').parent);		}); }); });