Jump to content

User:PSaxena (WMF)/common.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// IP Info gadget
// mw.loader.load('/w/index.php?title=User:PSaxena_(WMF)/ipinfo-uxtest.js&action=raw&ctype=text/javascript');
// mw.loader.load('/w/index.php?title=User:PSaxena_(WMF)/ipinfo-uxtest.css&action=raw&ctype=text/css', 'text/css');

/*mw.loader.load('/w/index.php?title=User:PSaxena_(WMF)/ipinfo.js&action=raw&ctype=text/javascript');
mw.loader.load('/w/index.php?title=User:PSaxena_(WMF)/ipinfo.css&action=raw&ctype=text/css', 'text/css');

mw.loader.load('/w/index.php?title=User:PSaxena_(WMF)/info.js&action=raw&ctype=text/javascript');
mw.loader.load('/w/index.php?title=User:PSaxena_(WMF)/info.css&action=raw&ctype=text/css', 'text/css');

mw.loader.using( ['jquery'], function () {
	var href = '#';
	
	var itsUserPage = function() {
		return (
			$('#t-userrights').length > 0 && // A user page
			window.location.href.split('User')[1].indexOf('/') < 0  // and not a sub-page
		)
	};
	
	var itsHistoryPage = function() {
		return ($('.mw-thanks-thank-link').length > 0 );
	};
	
	var itHasUserTalkLinks = function() {
		return ( $('#mw-content-text a[href*="/wiki/User_talk"]').length > 0 );
	};
	
	var addButtonInNavigation = function() {
		$('#ca-view').after( 
			$('<li>')
				.addClass('collapsible')
				.append(
					$('<span>').append(
						$('<a>')
							.text('Report')
							.attr( 'href', href)
					)
				)
		);
	};
	
	var addButtonInTools = function() {
		$('#t-contributions').after(
			$('<li>').append(
				$('<a>')
					.text('Report user')
					.attr('href', href)
			)
		);
	};
	
	var addLinkAfterThank = function() {
		var $reportLink = $('<a>')
			.text('report')
			.attr('href', href);
		$('.mw-thanks-thank-link').after([' | ',$reportLink]);
	}; 
	
	var addLinkInSignature = function() {
		var $reportLink = $('<a>')
			.text('report')
			.attr('href', href);
		$('#mw-content-text a[href*="/wiki/User_talk"]').after( [ ' | ', $reportLink]);
		$('#mw-content-text a[href*="/w/index.php?title=User_talk"]').after( [ ' | ', $reportLink]);
	};
	
	if (itsUserPage()) {
		addButtonInNavigation();
		addButtonInTools();
	}
	
	if (itsHistoryPage()) {
		addLinkAfterThank();
	}
	
	if (itHasUserTalkLinks()) {
		addLinkInSignature();
	}
	
});