Jump to content

User:Mr. Stradivarius/SourceLinks.js

From Wikipedia, the free encyclopedia
This is the current revision of this page, as edited by Mr. Stradivarius (talk | contribs) at 18:26, 15 April 2015 (images search is broken, and I never use it anyway). The present address (URL) is a permanent link to this version.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
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 + '"'
	);
} );