User:Eckserah/common.js

var findLinksUrl = "https://fallout.fandom.com/api.php?action=query&prop=linkshere&lhshow=!redirect&lhlimit=1000&format=json&titles="; var parseWikiTextUrl = "https://fallout.fandom.com/api.php?action=parse&prop=wikitext&format=json&page="; var actualPageLinks = "No Links Found"; var linkBase = "https://fallout.fandom.com/wiki/"; var processingLinks = false; var numLinks = 0;

function getLinksFromPage(pageName) { jQuery.ajax(findLinksUrl+pageName, {success: 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 {        		jQuery('#AllWhatLinksHere').append(actualPageLinks);        		jQuery('#LoadingInfo').hide;        	}        }    }}); }

function checkIfLinksReal(pageLinks, basePageName) { var parseWikiTextUrl = "https://fallout.fandom.com/api.php?action=parse&prop=wikitext&format=json&page="; jQuery.ajax(parseWikiTextUrl+pageLinks.title, {success: function( data ) {       if (data.error === undefined) {            var wikitext = data.parse.wikitext['*'];            if (findLinkInPage(basePageName, wikitext))                jQuery('#AllWhatLinksHere').append($(''+pageLinks.title+' '));            numLinks = numLinks - 1;            if (numLinks === 0) {            	if (jQuery('#AllWhatLinksHere').find('a').length === 0)            		jQuery('#AllWhatLinksHere').append(actualPageLinks);                jQuery('#LoadingInfo').hide;            }        }    }}); }

function findLinkInPage(SearchPageTitle, wikiText) { var modPageTitle = SearchPageTitle.replace(/[ _]/g,'[ _]'); var regexStr = '\\[\\[' + modPageTitle + '*[^\\]]+\\]\\]'; var testReg = new RegExp(regexStr); return testReg.test(wikiText); }

jQuery(document).ready(function {	var IsBetterWhatLinksHere = jQuery('#BetterWhatLinksHere');	if (IsBetterWhatLinksHere.length > 0) {		jQuery('#BetterWhatLinksHereForm').submit(function(e) { e.preventDefault; if (processingLinks) return; processingLinks = true; jQuery('#LoadingInfo').show; jQuery('#AllWhatLinksHere').html(''); var searchText = jQuery('#BetterWhatLinksHereForm').find('input[type=text]').val; if (searchText !== '') { setTimeout(function {					getLinksFromPage(searchText);				}, 200); }			return false; });		if (location.hash !== '') {			jQuery('#BetterWhatLinksHereForm').find('input[type=text]').val(location.hash.substring(1));			jQuery('#BetterWhatLinksHereForm').submit;		}	}	var whatLinksHereLink = jQuery('#WikiaBarWrapper').find('[data-name=whatlinkshere]');	whatLinksHereLink.prop('href',whatLinksHereLink.prop('href').replace('Special:WhatLinksHere/','User:Eckserah/BetterWhatLinksHere#')); });

// Tools/Navigation popups var popScript    = '//en.wikipedia.org/w/index.php?action=raw&ctype=text/javascript&title=MediaWiki:Gadget-popups.js&oldid=883914659'; var popStyleSheet = '//en.wikipedia.org/w/index.php?action=raw&ctype=text/css&title=MediaWiki:Gadget-navpop.css'; if ( window.localCSS ) { popStyleSheet = 'http://localhost:8080/js/navpop.css'; }

function popups_importScriptURI(url) { var s = document.createElement('script'); s.setAttribute('src',url); s.setAttribute('type','text/javascript'); document.getElementsByTagName('head')[0].appendChild(s); return s; }

function popups_importStylesheetURI(url) { return document.createStyleSheet ? document.createStyleSheet(url) : popups_appendCSS('@import "' + url + '";'); }

function popups_appendCSS(text) { var s = document.createElement('style'); s.type = 'text/css'; s.rel = 'stylesheet'; if (s.styleSheet) s.styleSheet.cssText = text //IE else s.appendChild(document.createTextNode(text + '')) //Safari sometimes borks on null document.getElementsByTagName('head')[0].appendChild(s); return s; }

popups_importStylesheetURI(popStyleSheet); popups_importScriptURI(popScript);