Wikipedia:WikiProject User scripts/Scripts/Get Page Name: Difference between revisions

Content deleted Content added
m should have kept in attribution
No edit summary
 
(9 intermediate revisions by 8 users not shown)
Line 1:
/*<pre>*/
/*Returns the name of the page. For example, if you were browsing the "[[foo]]" WP page, getPname() would return "foo".*/
 
<pre><nowiki>
function getPname() {
return mw.config.get('wgPageName').replace(/_/g, ' ');
z=document.getElementById("content").childNodes;
for (var n=0;n<z.length;n++) {
if (z[n].className=="firstHeading") return z[n].textContent;
};
}
/*</pre>[[Category:Wikipedia scripts]]*/
 
/* This code may be problematic when it comes to titles with ampersands, etc, which are stored as ''& amp ;'' in HTML (without the spaces).
A solution that solves this is the following:
return document.title.substr(0, document.title.lastIndexOf(' - Wikipedia, the free'));
*/
</nowiki></pre>
 
/*
This code was taken from the [[Wikipedia:WikiProject User scripts/Scripts/Show last diff|Show last diff]] code.
*/