Jump to content

User:EstherLoer/hide path.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.
// This script hides the path to a sub page, and only shows the sub page's title. The path can still be seen below the title.
	// Not compatible with other title-modifying scripts like distinguish_title.js .

var firstHeading = document.getElementById("firstHeading");

if (
	RLCONF.wgAction == "view" // checks whether the user is in viewing mode, as opposed to editing, history, or others.
	&& firstHeading.innerHTML.search("/") > -1 // checks whether the title contains a slash
	)	
{
	// gets the name of the sub page using a negative lookahead regular expression
	var subpage_title = firstHeading.innerHTML.substring(firstHeading.innerHTML.search(/(\/)(?:.(?!(\/)))+$/)+1 );
	firstHeading.innerHTML = subpage_title;
}

// [[Category:Wikipedia scripts]]