User:Nthep/googletitle.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
This user script seems to have a documentation page at User:Nthep/googletitle. |
//Add Google search - modified from User:Writ Keeper/Scripts/googleTitle.js to include articles in Draft namespace//
$(googleTitle);
function googleTitle()
{
if(mw.config.get('wgCanonicalNamespace') === ""||mw.config.get('wgCanonicalNamespace') =='Draft')
{
var subjectName;
if(mw.config.get('wgPageName').charAt(mw.config.get('wgPageName').length - 1) == ")")
{
subjectName = mw.config.get('wgPageName').substring(0, mw.config.get('wgPageName').lastIndexOf("(") - 1);
}
else
{
subjectName = mw.config.get('wgPageName');
}
if(mw.config.get('wgCanonicalNamespace') =='Draft') // this if statement strips Draft: from the start of the search string //
{
subjectName = mw.config.get('wgPageName').substring(6);
}
var searchNode = document.createElement("a");
searchNode.href = "https://www.google.com/search?q=" + encodeURIComponent(subjectName.replace(/_/g, " ")) + "+-wikipedia.org";
searchNode.target = "_blank";
searchNode.innerHTML = "<span style='font-size:x-small;'> Search Google</span>";
document.getElementById("firstHeading").appendChild(searchNode);
}
}