User:RheingoldRiver/common.js

// // Disable triggering of new browser tab when clicking URL links that point to internal wiki addresses (purge, edit, etc) $('a[href*="gamepedia.com"]').removeAttr('target').removeClass('external text');

/* add edit buttons for recent changes, categories, contributions, and search */ $(function {	function addTagMarker(obj) {		var classes = $(obj).attr('class');		var re = /.*mw-tag-marker-([^\s]*)/g;		var thisClass = re.exec(classes)[1];		if (thisClass) {			var sep = (window.location.href.indexOf("?") === -1) ? "?" : "&";			$('')			.addClass('tag-filter-link')			.attr({ href: window.location.href + sep + 'tagfilter=' + thisClass, title: 'Filter to this tag' })			.css({'margin-left':'.5em','background-color':'#0FE40F'})			.text('...')			.insertAfter(obj);		}	}	$('.mw-tag-marker').each(function{ addTagMarker(this); });	function addEditlink(elem, target) {		addEditlinkFromUrl(elem, mw.util.getUrl(target, { action : 'edit' }));	}	function addEditlinkFromUrl(elem, url) {		$('').addClass('custom-editlink').attr({ href : url, title : 'Edit this page' }).text('✎').insertAfter(elem);	}	function addDeletelink(elem, target) {		addDeletelinkFromUrl(elem, mw.util.getUrl(target, { action : 'delete' }));	}

function addDeletelinkFromUrl(elem, url) { $('').addClass('custom-deletelink').attr({			href : url,			title : 'Delete this page'		}).text('X').insertAfter(elem); }

function fixProfileLink(elem, title) { if (! title.match(/^User:/)) return; var oldlink = $(elem).attr('href'); var newlink = oldlink + '?profile=no'; $(elem).attr('href', newlink); }	mw.loader.using('mediawiki.util').then(function {		$('.mw-changeslist').find('.mw-title').each(function { var title_obj = $(this).find('.mw-changeslist-title'); if (title_obj) { var title = title_obj.attr('title'); addEditlink(this, title); fixProfileLink(title_obj, title); }		});		$('.mw-category-generated').find('.mw-content-ltr ul li a').each(function { var title = $(this).text; if (title) { title = $(this).parent.hasClass("CategoryTreeItem") ? "Category:" + title : title; addDeletelink(this, title); addEditlink(this, title); }		});		$('ul.mw-contributions-list').find('a.mw-contributions-title').each(function { var title = $(this).attr('title'); fixProfileLink(this, title); addEditlink(this, title); });		$('.searchresults').find('.mw-search-result-heading').each(function { var title_obj = $(this).find('a'); if (title_obj) { var title = title_obj.attr('title'); addEditlink(title_obj, title); fixProfileLink(title_obj, title); }		});		$('#pagehistory').find('.mw-changeslist-date').each(function { addEditlinkFromUrl(this, $(this).attr('href') + '&action=edit'); });	}); });

/* silly workaround to add a page values hotkey, alt shift 1 */ $.when(mw.loader.using('mediawiki.util'), $.ready).then(function { 	mw.util.addPortletLink('p-tb', mw.config.get('wgServer') + mw.config.get('wgArticlePath').replace("$1", "index.php?title="+ encodeURI(mw.config.get('wgPageName')) + '&action=pagevalues'), 'Page Values 2', 'pv2','page values','1','#t-cargopagevalueslink'); });

/* copy category members */ $(function {	wgNamespace = mw.config.get('wgCanonicalNamespace');	if (wgNamespace != 'Category') return;	$(mw.util.addPortletLink('p-cactions', 'javascript:;', '!Copy Members', 'ca-copy-cat-members', 'Copy Category Members', null, '#ca-move-to-user')).click(function { a = new mw.Api; a.get({			action : 'query',			list : 'categorymembers',			cmtitle : mw.config.get('wgPageName'),			cmlimit : 'max'		}).then(function(data) {			tbl = [];			for (page in data.query.categorymembers) {				tbl.push(data.query.categorymembers[page].title);			}			var str = tbl.join('\n');			var el = document.createElement('textarea');			el.value = str;			el.setAttribute('readonly', '');			$(el).insertAfter('#contentSub');			el.select;		}); }); });

/* copy titles from search, recentchanges, contribs */ $(function {	var selectors = [		{ pattern: 'Special:Search', selector: '.mw-search-result .mw-search-result-heading a:first-of-type' },		{ pattern: 'Special:Contributions/', selector: '.mw-contributions-title' },		{ pattern: 'Special:RecentChanges', selector: '.mw-changeslist-line-inner .mw-title a' },	]	var pageName = mw.config.get('wgPageName');	for (i in selectors) {		if (!pageName.includes(selectors[i].pattern)) continue;		$(mw.util.addPortletLink('p-cactions', 'javascript:;', '!Copy Titles', 'ca-copy-search-results', 'Copy Titles', null, '#ca-move-to-user')).click(function { var pageList = []; $(selectors[i].selector).each(function {				pageList.push($(this).attr('title'));			}); var str = pageList.join('\n'); var el = document.createElement('textarea'); el.value = str; el.setAttribute('readonly', ''); $(el).insertAfter('#contentSub'); el.select; });		// don't let i keep incrementing		return;	} });

/* press alt shift E to start creating a page that doesn't exist yet from search */ $(function {	if (! document.getElementById('powersearch') && ! document.getElementById('search')) return;	$(mw.util.addPortletLink('p-cactions', 'javascript:;', '!Create Page', 'ca-copy-cat-members', 'Create Page', 'e')).click(function { $('.new').each(function {this.click;}); }); });

/* See totals at the top of WLH pages */ $(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/', '');	var el = document.createElement('div');	var display = [ 'Total links: ', 'Total transclusions: ', 'Redirects and links to redirects are NOT included!' ];	$(el).html(display.join(' ')).insertAfter($('#firstHeading'));	return new mw.Api.get({ action : 'query', prop : 'linkshere|transcludedin', titles : title, lhlimit : 'max', tilimit : 'max', lhnamespace : ns == '' ? '*' : ns, tinamespace : ns == '' ? '*' : ns, }).then(function(data) { console.log(data); var lh, ti; for (p in data.query.pages) { var page = data.query.pages[p]; lh = page.linkshere ? page.linkshere.length : 0; ti = page.transcludedin ? page.transcludedin.length : 0; }		display = [ 'Total links: ' + lh, 'Total transclusions: ' + ti, 'Redirects and links to redirects are NOT included!' ];		$(el).html(display.join(' ')) }); });

/* Add line numbers to modules */ $(function {	$('.ns-828 pre').each(function { // Module:Teamnames on Leaguepedia is like 10,000 lines long. let's not do this there if (mw.config.get('wgTitle') == 'Teamnames') return; var lines = $(this).html.split('\n'); $(this).html(			lines				.map(function(str) { return "" + str + " " })				.join('\n')		); }); });

// show table name by each cargo table value set $(function {	var currTable = '';	$('.action-pagevalues h2 span, .action-pagevalues #mw-content-text > .wikitable').each(function { if ($(this).hasClass('wikitable')) { $(this).attr('style', '--table-name:"' + currTable + '"'); $(this).addClass('cargo-values'); return }		currTable = $(this).text.match(/^"(.+?)".*/)[1]; }); });

//////////////////////////////////////////////

$(function {	$('.cargoReplacementTableInfo').each(function { var parent = $(this).closest('li').detach; $('#mw-content-text > ul:first-of-type').prepend(parent); }); });

//