User:Eckserah/common.js

(function {	if (window.WhatReallyLinksHereLoaded) return;	window.WhatReallyLinksHereLoaded = true;	mw.loader.using( 'mw.Api' ).then(function { var api = new mw.Api; var actualPageLinks = "No Links Found"; var linkBase = location.protocol + '//' + location.host + '/wiki/'; var whatReallyLinksHerePage = "Special:WhatReallyLinksHere"; var processingLinks = false; var maxNumProcessingAtOnce = 250; var numLinks = 0; var totalLinks = 0; var currNumProcessing = 0; var lasthash = location.hash; var mainLinkArea = '#AllWhatLinksHere'; var RedirectArea = '#AllRedirectArea'; var hasRedirects = false; var linkData = { links: {}, Redirects: {} }; function generateSpecialPage { var WhatReallyLinksHereContainer = $(' ');

var inputBox = $(' '); var searchBoxForm = $(''); var searchBoxInput = $(''); var searchBoxButton = $('<input type="submit" name="fulltext" class="mw-ui-button" style="background-color: #f8f9fa;color: #222222;display: inline-block;-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;min-width: 4em;max-width: 28.75em;margin: 0;padding: 0.57142857em 0.9375em;border: 1px solid #a2a9b1;border-radius: 2px;font-family: inherit;font-size: 1em;font-weight: bold;line-height: 1;text-align: center;-webkit-appearance: none;zoom: 1;vertical-align: middle;cursor: pointer;" value="What Really Links Here" />'); searchBoxForm.append($(' ').append(searchBoxInput).append($(' ')).append(searchBoxButton)); searchBoxForm.append($(' ').append(searchBoxInput.clone.prop('name','filter').prop('id','FilterTxt').css('width','250px')).append($(' ')).append(searchBoxButton.clone.prop('type','button').prop('name','filter').prop('id','FilterBtn').val('Link Text Filter'))); searchBoxForm.submit(function(e) {               e.preventDefault;                if (processingLinks)                    return;                processingLinks = true;                $('#LoadingInfo').show;                $(mainLinkArea).html();                $(RedirectArea).html();                var searchText = $('#WhatReallyLinksHereForm').find('#searchBox').val;                if (searchText !== '') {                	updateTitleHeading('What Really Links Here');                    setTimeout(function { getLinksFromPage(decodeURIComponent(searchText), '', false); }, 200);               } else                 	updateTitleHeading(searchText);                return false;            }); searchBoxForm.find('#FilterBtn').click(function(e) {               var inputInfo = $('FilterTxt').val;                if (inputInfo !== '') {                }            }); inputBox.append(searchBoxForm); WhatReallyLinksHereContainer.append(inputBox).append($(' ')).append($(' '));

var loadingInfoBox = $(''); var center = $(' ').append($(' Loading. Please wait. 0/0 Done ')).append($('')); loadingInfoBox.append(center); WhatReallyLinksHereContainer.append(loadingInfoBox); $('#mw-content-text').children.remove; $('#mw-content-text').append(WhatReallyLinksHereContainer); var firstHeadingText = 'What Really Links Here'; if (wgPageName.indexOf('/') != -1) { var subSearchPage = wgPageName.substr(wgPageName.indexOf('/')+1); if (subSearchPage != '') { $('#WhatReallyLinksHereForm').find('#searchBox').val(subSearchPage); $('#WhatReallyLinksHereForm').submit; firstHeadingText = 'Pages that really link to "' + subSearchPage + '"'; }           }            updateTitleHeading(firstHeadingText); }       function highlightFilters(filterText) { $('.filterHighlights').css('background-color','').RemoveClass('filterHighlights'); if (linkData.links.length > 0) { /*linkData.links.forEach(link => {                   for (var i = 0; i < link.length; i++) {                    }                });*/ }           if (linkData.Redirects.length > 0) { }       }        function updateTitleHeading(newText) { $('#firstHeading').text(newText); document.title = newText + ' - The Fallout Wiki'; }		function getLinksFromPage(pageName, lhContinue, isRedirectPage) { if (lhContinue === undefined) lhContinue = ''; api.get({				action: 'query',				prop: 'linkshere',				format: 'json',				//lhshow: 'redirect|!redirect',				lhlimit: 500,				titles: pageName,				lhcontinue: lhContinue			}).done(function(e) {				if (e.continue !== undefined)					getLinksFromPage(pageName, e.continue.lhcontinue, isRedirectPage);				var linkInfos = e.query.pages;		       for (var titleLink in linkInfos) {		        	if (linkInfos[titleLink].linkshere !== undefined) {			            numLinks += linkInfos[titleLink].linkshere.length;			            totalLinks += linkInfos[titleLink].linkshere.length;			            for (var linkInf in linkInfos[titleLink].linkshere) {			            	if (linkInfos[titleLink].linkshere[linkInf].redirect !== undefined) {                                numLinks -= 1;                                if (!hasRedirects) {                                    $(RedirectArea).append(' Redirects: ');                                    hasRedirects = true; }			           		$(RedirectArea).append(' '+linkInfos[titleLink].linkshere[linkInf].title+'  '); getLinksFromPage(linkInfos[titleLink].linkshere[linkInf].title, '', true); } else checkIfLinksReal(linkInfos[titleLink].linkshere[linkInf], pageName, isRedirectPage); }		       	} else { if (!isRedirectPage) { $(mainLinkArea).append(actualPageLinks); $('#LoadingInfo').hide; $('#LoadingInfo').find('#RecordInfo').text('0/0 Records Done.'); processingLinks = false; }		       	}		        }			});		}		function checkIfLinksReal(pageLinks, basePageName, IsRedirectPage) {			if (currNumProcessing >= maxNumProcessingAtOnce)			{				setTimeout(function { checkIfLinksReal(pageLinks,basePageName, IsRedirectPage) }, 100);				return;			}			currNumProcessing += 1;			api.get({ action: 'parse', prop: 'wikitext', format: 'json', page: pageLinks.title }).done(function(data) { if (data.error === undefined) { var wikitext = data.parse.wikitext['*']; var pageLinkArr = findLinkInPage(basePageName, wikitext); if (pageLinkArr !== null) { var linkDataID = stripRegExp(basePageName)+'_'+stripRegExp(pageLinks.title); var checkContainer = mainLinkArea; var ContainerID = ' id="'+linkDataID+'"'; if (IsRedirectPage) checkContainer = '#'+stripRegExp(basePageName); if (IsRedirectPage) { linkData.Redirects[linkDataID] = pageLinkArr; } else linkData.links[linkDataID] = pageLinkArr; $(checkContainer).append($(''+pageLinks.title+' ')); var allLinks = $(checkContainer+' div').sort(function (a,b) { 		               	var aText = $(a).find('a').text;		                	var bText = $(b).find('a').text;							if (aText > bText)								return 1;							if (aText < bText)								return -1;							return 0;						}); $(checkContainer).append(allLinks); }		           numLinks -= 1; currNumProcessing -= 1; $('#LoadingInfo').find('#RecordInfo').text((totalLinks-numLinks).toString+'/'+totalLinks.toString+ ' Records Done.'); if (numLinks <= 0) { debugger; if ($(mainLinkArea).children('div').length === 0 && $(RedirectArea).children('div').length === 0) $(mainLinkArea).append(actualPageLinks); if ($(RedirectArea).children('div').length > 0) $(RedirectArea).children('div').children('div').each(function(i, e) {                               if ($(e).children('div').length === 0)                                    $(e).append(actualPageLinks);                            }); $('#LoadingInfo').hide; $('#LoadingInfo').find('#RecordInfo').text('0/0 Records Done.'); processingLinks = false; }		       } else { numLinks -= 1; currNumProcessing -= 1; if (numLinks <= 0) { if ($(mainLinkArea).children('div').length === 0 && $(RedirectArea).children('div').length === 0) $(mainLinkArea).append(actualPageLinks); if ($(RedirectArea).children('div').length > 0) $(RedirectArea).children('div').children('div').each(function(i, e) {                               if ($(e).children('div').length === 0)                                    $(e).append(actualPageLinks);                            }); $('#LoadingInfo').hide; $('#LoadingInfo').find('#RecordInfo').text('0/0 Records Done.'); processingLinks = false; }		       	console.log(parseWikiTextUrl+pageLinks.title); console.log(data.error); }			});		}		function concatPageLink {			return linkBase+whatReallyLinksHerePage+'/'+wgPageName;		}		function escapeRegExp(text) {		 return text.replace(/[-[\]{}*+?.,\\^$|#\s]/g, '\\$&');		}		function stripRegExp(text) {		  return text.replace(/[-[\]{}*+?.,\\^$|#\s'"]/g, '');		}		function findLinkInPage(SearchPageTitle, wikiText) {		    var modPageTitle = escapeRegExp(SearchPageTitle).replace(/\\*[ _]/g,'[ _]');		    //var regexStr = '\\[\\[' + modPageTitle + '*[^\\]]+\\]\\]';		    var regexStr = '\\[{2}' + modPageTitle + '[|#]*[^\[]*\]{2}';		    var testReg = new RegExp(regexStr, 'g');            var matches = wikiText.match(testReg);		    return matches;		}		$(document).ready(function {			if (wgPageName.indexOf(whatReallyLinksHerePage) === 0) {				generateSpecialPage;			}            var whatReallyLinksHereElem = $(' ').append($('').text('What really links here')); var baseLink = $('#WikiaBarWrapper').find('[data-name=whatlinkshere]'); if (baseLink.length > 0) { baseLink = baseLink.parent; whatReallyLinksHereElem.insertAfter(baseLink); } else { baseLink = $('#WikiaBarWrapper').find('.tools-customize'); whatReallyLinksHereElem.insertBefore(baseLink); }		});	}); });