Jump to content

User:Kku/Scripts/SpTitle.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.
$(document).ready(function()
{

        console.log("SpTitle.js");


		if(mw.config.get("wgCanonicalNamespace") == "")
		{
			var subjectName;
            var smallstyle="font-size:x-small;";
			var pageName = mw.config.get("wgPageName");
			if(pageName.charAt(pageName.length - 1) == ")")
			{
				subjectName = pageName.substring(0, pageName.lastIndexOf("(") - 1);
			}
			else
			{
				subjectName = pageName;
			}
			var spacer= document.createElement("span");
            spacer.innerHTML=" - ";
            spacer.style.cssText=smallstyle; // https://stackoverflow.com/questions/5927012/javascript-createelement-style-problem
            var searchNodeSp = document.createElement("a");
			searchNodeSp.href = "http://www.startpage.com/do/search?query=" + encodeURIComponent(subjectName.replace(/_/g, " ")); //+ "+-wikipedia.org";
			searchNodeSp.target = "_blank";
//			searchNodeSp.innerHTML = "<span style='font-size:x-small;'>Search SP</span>";
			searchNodeSp.innerHTML = "Search SP";
            searchNodeSp.style.cssText=smallstyle; 
      		
            var searchNodeGs = document.createElement("a");
		    searchNodeGs.href = "https://scholar.google.de/scholar?hl=de&q=" + encodeURIComponent(subjectName) + "+-wikipedia.org";
			searchNodeGs.target = "_blank";
			searchNodeGs.innerHTML = "GS";
            searchNodeGs.style.cssText=smallstyle; 

			var fh=document.getElementById("firstHeading");
			fh.appendChild(spacer);
			fh.appendChild(searchNodeSp);
			fh.appendChild(spacer.cloneNode(true));//https://developer.mozilla.org/en-US/docs/Web/API/Node/cloneNode
			fh.appendChild(searchNodeGs);
		}
/*       else {
               //console.log("Browsing in " + mw.config.get( 'wgCanonicalNamespace' ) + " namespace so SpTitle.js will not do much.");
               return;
        }*/
});