Jump to content

User:Mr. Stradivarius/SourceLinks.js

From Wikipedia, the free encyclopedia
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
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.
$( document ).ready( function () {
	'use strict';

	var config = mw.config.get( [ 'wgTitle', 'wgNamespaceNumber' ] );
	if ( config.wgNamespaceNumber === -1 ) {
		return;  // no links for special pages
	}

	var title = config.wgTitle;
	if ( config.wgNamespaceNumber !== 0 ) {
		title = title.replace( /^.*\//, "" );  // subpage name only
	}

	var query = encodeURIComponent('"' + title + '" -Wikipedia' ); 
	var escapedTitle = mw.html.escape( title );

	mw.util.addPortletLink(
		'p-tb',
		'https://www.google.co.uk/search?&q=' + query,
		'Web search',
		't-googlesearch',
		'Search Google for "' + escapedTitle + '"'
	);
	mw.util.addPortletLink(
		'p-tb',
		'https://www.google.co.uk/?#q=' + query + '&tbm=nws',
		'News search',
		't-googlenewssearch',
		'Search Google News for "' + escapedTitle + '"'
	);
	mw.util.addPortletLink(
		'p-tb',
		'https://www.google.co.uk/search?q=' + query + ' -inpublisher:icon&btnG=Search+Books&tbm=bks&tbo=1',
		'Books search',
		't-googlebookssearch',
		'Search Google Books for "' + escapedTitle + '"'
	);
	mw.util.addPortletLink(
		'p-tb',
		'https://scholar.google.co.uk/scholar?&q=' + query,
		'Scholar search',
		't-googlescholarsearch',
		'Search Google Scholar for "' + escapedTitle + '"'
	);
} );