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 = ""; var linkBase = "https://fallout.fandom.com/wiki/";

function getLinksFromPage(pageName) { jQuery.ajax(findLinksUrl+pageName, {async:false, success: function(e) {       var linkInfos = e.query.pages;        for (var titleLink in linkInfos) {            for (var linkInf in linkInfos[titleLink].linkshere) {                var linkCheck = checkIfLinksReal(linkInfos[titleLink].linkshere[linkInf],pageName);                if (linkCheck !== undefined) {                    actualPageLinks = actualPageLinks + ''+linkCheck.title+' ';                }            }        }    }}); return actualPageLinks; }

function checkIfLinksReal(pageLinks, basePageName) { var parseWikiTextUrl = "https://fallout.fandom.com/api.php?action=parse&prop=wikitext&format=json&page="; var found; jQuery.ajax(parseWikiTextUrl+pageLinks.title, {async: false, success: function( data ) {       if (data.error === undefined) {            var wikitext = data.parse.wikitext['*'];            if (findLinkInPage(basePageName, wikitext)) {                found = pageLinks;            }        }    }}); return found; }

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; var searchText = jQuery('#BetterWhatLinksHereForm').find('input[type=text]').val; if (searchText !== '') { $.when(getLinksFromPage(searchText)).done(function(data) {					jQuery('#AllWhatLinksHere').html(data);				}); }			return false; });	} });