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 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).hasClass("CategoryTreeLabel") ? "Category:" + title : 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 search results */ $(function {	if (mw.config.get('wgTitle') != 'Search') return;	$(mw.util.addPortletLink('p-cactions', 'javascript:;', '!Copy Results', 'ca-copy-search-results', 'Copy Search Results', null, '#ca-move-to-user')).click(function { var pageList = []; $('.mw-search-result-heading a:first-of-type').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; }); });

/* press alt shift E to start creating a page that doesn't exist yet from search */ $(function {	if (! document.getElementById('powersearch')) 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/', '');	return new mw.Api.get({ action : 'query', prop : 'linkshere|transcludedin', titles : title, lhlimit : 'max', tilimit : 'max', lhnamespace : ns == 'all' ? '' : ns, tinamespace : ns == 'all' ? '' : ns, }).then(function(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; }		var display = [ 'Total links: ' + lh, 'Total transclusions: ' + ti, 'Redirects and links to redirects are NOT included!' ];		var el = document.createElement('div'); $(el).html(display.join(' ')).insertAfter($('#firstHeading')); }); });

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

//