Jump to content

User:Titodutta/scripts/SearchHelper.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Titodutta (talk | contribs) at 16:24, 29 January 2019 (Add). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
/*
The script adds a few options beside article
Main script by Writ and may be seen at https://en.wikipedia.org/wiki/User:Writ_Keeper/Scripts/googleTitle.js
*/$(document).ready(function()
{
		if(mw.config.get("wgCanonicalNamespace") == "")
		{
			var subjectName;
			var pageName = mw.config.get("wgPageName");
			if(pageName.charAt(pageName.length - 1) == ")")
			{
				subjectName = pageName.substring(0, pageName.lastIndexOf("(") - 1);
			}
			else
			{
				subjectName = pageName;
			}
			var newNode = " <a href='http://www.google.com/search?q=" + encodeURIComponent(subjectName.replace(/_/g, " ")).replace(/'/g,"%27") + "+-wikipedia.org' target='_blank'><span style='font-size:x-small;'>Google search</span></a>"
						$("#firstHeading").append(newNode);
            var newNode = " <a href='https://www.google.com/search?tbm=isch&q=" + encodeURIComponent(subjectName.replace(/_/g, " ")).replace(/'/g,"%27") + "' target='_blank'><span style='font-size:x-small;'>Google mages</span></a>"
            			$("#firstHeading").append(newNode);
			var newNode = " <a href='https://commons.wikimedia.org/w/index.php?search=" + encodeURIComponent(subjectName.replace(/_/g, " ")).replace(/'/g,"%27") + "' target='_blank'><span style='font-size:x-small;'>Commons</span></a>"
						$("#firstHeading").append(newNode);
			var newNode = " <a href='http://edwardbetts.com/find_link/" + encodeURIComponent(subjectName.replace(/_/g, " ")).replace(/'/g,"%27") + "' target='_blank'><span style='font-size:x-small;'>Find link</span></a>"
			            $("#firstHeading").append(newNode);
		    var newNode = " <a href='https://www.google.com/custom?hl=en&cx=014196815420355252912:fownxmjrhle&cof=FORID%3A13%3BAH%3Aleft%3BCX%3AWikipedia%2520Reference%2520Search&q=" + encodeURIComponent(subjectName.replace(/_/g, " ")).replace(/'/g,"%27") + "' target='_blank'><span style='font-size:x-small;'>Indian newspapers</span></a>";
			$("#firstHeading").append(newNode);

		}
});
if ( $('#t-wikibase').length ){
	console.log('Exist');
	link = $('li#t-wikibase a:first').attr('href');
	console.log( link );
}

$(document).ready(function()
{
		if(mw.config.get("wgCanonicalNamespace") == "" && $('#t-wikibase').length )
		{
			console.log('Exist');
			link = $('li#t-wikibase a:first').attr('href');

			var newNode = "<a href='" + link + "' target='_blank'><span style='font-size:x-small;'>Wikidata</span></a>";
			$("#firstHeading").append(newNode);
		}
});