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 {	var $changeList = $( '.mw-changeslist' );	var $catList = $('.mw-category-generated');	var $contribList = $('ul.mw-contributions-list');	var $searchList = $('.searchresults');	if ( !$changeList.length && !$catList.length && !$contribList.length && !$searchList.length) {		return;	}	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.loader.using( 'mediawiki.util' ).then( function { $changeList.find( '.mw-title' ).each( function {			var title_obj = $( this ).find( '.mw-changeslist-title' );			if ( title_obj ) {				var title = title_obj.attr( 'title' );				$( '' ).addClass( 'custom-editlink' ).attr( { href: mw.util.getUrl( title, { action: 'edit' } ), title: 'Edit this page' } ).text( '✎' ).insertAfter( this );				if (title.match(/^User/)) {					$(title_obj).attr('href', $(title_obj).attr('href') + '?profile=no');				}			}		} ); $changeList.find('.mw-tag-marker').each( function{			addTagMarker(this);		}); $catList.find('.mw-content-ltr ul li a').each(function {			var title = $(this).text;			if (title) {				if ($(this).hasClass("CategoryTreeLabel")) {					title = "Category:" + title;				}				$('').addClass('custom-editlink').attr( { href: mw.util.getUrl(title, { action: 'edit' }), title: 'Edit this page' }).text('✎').insertAfter(this);			}		}); $contribList.find('a.mw-contributions-title').each( function {			var title = $(this).attr('title');			if (title.match(/^User/)) {				$(this).attr('href', $(this).attr('href') + '?profile=no');			}			$('').addClass('custom-editlink').attr( { href: mw.util.getUrl(title, { action: 'edit' }), title: 'Edit this page' }).text('✎').insertAfter(this);		} ); $contribList.find('.mw-tag-marker').each( function{			addTagMarker(this);		}); $searchList.find( '.mw-search-result-heading' ).each( function {			var title_obj = $( this ).find( 'a' );			if ( title_obj ) {				var title = title_obj.attr( 'title' );				$( '' ).addClass( 'custom-editlink' ).attr( { href: mw.util.getUrl( title, { action: 'edit' } ), title: 'Edit this page' } ).text( '✎' ).insertAfter( title_obj );				if (title.match(/^User/)) {					$(title_obj).attr('href', $(title_obj).attr('href') + '?profile=no');				}			}		} ); }); } );

/* page values hotkey */ $.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 page name with/without ns */

$(function {	var el = document.createElement('div')	$(el).attr('id', 'title-copy-outer').html('  ');	$('#firstHeading').wrapInner(' ');	$(el).insertAfter(document.getElementById('first-heading-text'));	console.log('copy');	$('#title-copy-content').click(function { var text = mw.config.get('wgTitle'); var copyEl = document.createElement('textarea'); copyEl.value = text; document.body.appendChild(copyEl); copyEl.select; document.execCommand('copy'); document.body.removeChild(copyEl); $('#title-copy-content').css('color','green'); setTimeout(function {			$('#title-copy-content').css('color','');		}, 2000); });	$('#title-copy-all').click(function { var text = mw.config.get('wgPageName'); var copyEl = document.createElement('textarea'); copyEl.value = text; document.body.appendChild(copyEl); copyEl.select; document.execCommand('copy'); document.body.removeChild(copyEl); document.execCommand('copy'); $('#title-copy-all').css('color','green'); setTimeout(function {			$('#title-copy-all').css('color','');		}, 2000); }); });

/* Copy category */

$(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;		}); }); });

//