User:Euphoria/common.js: Difference between revisions
From Test Wiki
extract the username specifically from user contributions pages
(user contributions page) |
(extract the username specifically from user contributions pages) |
||
Line 3: | Line 3: | ||
// Extract the username from the current page title | // Extract the username from the current page title | ||
var pageTitle = mw.config.get('wgTitle'); | var pageTitle = mw.config.get('wgTitle'); | ||
var username = pageTitle.split('/')[0]; | var username; | ||
// Check if the current page is a user contributions page | |||
if (mw.config.get('wgCanonicalSpecialPageName') === 'Contributions') { | |||
// Extract username from the contributions page | |||
var match = pageTitle.match(/Special:Contributions\/(.+)/); | |||
username = match ? match[1] : null; | |||
} else { | |||
// Extract username from the regular page title | |||
username = pageTitle.split('/')[0]; | |||
} | |||
// Check if the current page is a user page, user talk page, or user contributions page | // Check if the current page is a user page, user talk page, or user contributions page |