User:Mike Dillon/Scripts/username.js
From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Firefox/Mozilla/Safari: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Internet Explorer: press Ctrl-F5, Opera/Konqueror: press F5.
/* <pre><nowiki> */ function getUsernameForCurrentPage() { try { if (wgCanonicalSpecialPageName == "Contributions") { // Find the form containing the element with the id "namespace" var form = document.getElementById("namespace").form; // Extract the username from the "target" field of the form return form.target.value.replace("_", " "); } else if (wgNamespaceNumber == 2 || wgNamespaceNumber == 3) { return wgTitle.split('/')[0]; } } catch (e) { // Fall through } } /* </nowiki></pre> */