User:BZPN/MassRollback2.js: Difference between revisions
From Test Wiki
Content deleted Content added
No edit summary |
No edit summary |
||
| Line 560: | Line 560: | ||
title = ($plink.attr('title') || '').trim(); |
title = ($plink.attr('title') || '').trim(); |
||
} |
} |
||
// Try to get username from the RC line |
// Try to get username (author of the edit) from the RC line |
||
let user = |
let user = ''; |
||
// Prefer the direct user page link, not talk/contribs |
|||
const $userAnchor = $line.find('a.mw-userlink[href*="/wiki/User:"]:not([href*="User_talk"]):not([href*="Special:Contributions"])').first(); |
|||
if ($userAnchor.length) { |
|||
user = ($userAnchor.find('bdi').text() || $userAnchor.text() || '').trim(); |
|||
} |
|||
// Fallback: from talk link href |
|||
if (!user) { |
|||
const $talk = $line.find('a[href*="/wiki/User_talk:"]').first(); |
|||
if ($talk.length) { |
|||
const href = $talk.attr('href'); |
|||
const m = href && href.match(/User_talk:([^?#]+)/); |
|||
if (m) user = decodeURIComponent(m[1]); |
|||
} |
|||
} |
|||
// Fallback: from Special:Contributions link href |
|||
if (!user) { |
if (!user) { |
||
const $ |
const $contribs = $line.find('a[href*="Special:Contributions/"]').first(); |
||
if ($contribs.length) { |
|||
const href = $contribs.attr('href'); |
|||
const m = href && href.match(/Special:Contributions\/([^?#]+)/); |
|||
if (m) user = decodeURIComponent(m[1]); |
|||
} |
|||
} |
} |
||
user = user || null; |
|||
if (revid && parentid && title) { |
if (revid && parentid && title) { |
||
return { title: title, revid: revid, parentid: parentid, timestamp: new Date().toISOString(), user: user || null }; |
return { title: title, revid: revid, parentid: parentid, timestamp: new Date().toISOString(), user: user || null }; |
||