User:Polygnotus/Scripts/XC.js: Difference between revisions

Content deleted Content added
No edit summary
Tag: Reverted
No edit summary
 
(6 intermediate revisions by the same user not shown)
Line 1:
// <nowiki>
// ExtendedConfirmedChecker.js
// Adds indicators next to usernames on talk pages showing extended confirmed status
// License: MITcopyleft
 
$(function() {
Line 46 ⟶ 45:
}
}
 
// Define advanced groups that imply extended confirmed status
const ADVANCED_GROUPS = new Set([
'sysop', // Administrators
'bot', // Bots
'checkuser', // CheckUsers
'oversight', // Oversighters
'founder', // Founders
'steward', // Stewards
'staff', // Wikimedia staff
'bureaucrat', // Bureaucrats
'extendedconfirmed' // Explicitly extended confirmed
]);
 
const processedUsers = new Set();
const userGroups = loadCache();
// Check if a URL path is a subpage
function isSubpage(path) {
// First decode the URL to handle any encoded characters
const decodedPath = decodeURIComponent(path);
// Remove any URL parameters or fragments
const cleanPath = decodedPath.split(/[?#]/)[0];
// Check if there's a slash after "User:"
return /User:[^/]+\//.test(cleanPath);
}
// Find all user links in signatures
function findUserLinks() {
// Find userboth pageregular user links butand excluderedlinks, subpages andexcluding talk pages and user subpages
const links = $('#content a[href^="/wiki/User:"]:not([href*="/User:/"]'):not.filter([href*="/"]):notfunction([href*="talk"]):not([data-ec-checked]), ' +{
const href = $(this).attr('href');
'#content a[href^="/w/index.php?title=User:"]:not([href*="/User:/"]):not([href*="/"]):not([href*="talk"]):not([data-ec-checked])');
// Basic check for user page links
if (!href || (!href.startsWith('/wiki/User:') && !href.startsWith('/w/index.php?title=User:'))) {
return false;
}
// Exclude talk pages
if (href.includes('talk')) {
return false;
}
// Exclude already processed links
if ($(this).attr('data-ec-checked')) {
return false;
}
// Check for subpages
if (href.startsWith('/wiki/')) {
if (isSubpage(href)) {
return false;
}
} else {
// For redlinks, check the title parameter
const url = new URL(href, window.___location.origin);
const title = url.searchParams.get('title');
if (title && isSubpage(title)) {
return false;
}
}
return true;
});
console.log('Found user links:', links.length);
links.each((_, link) => console.log('User link:', $(link).text(), $(link).attr('href')));{
const username = getUsernameFromLink(link);
console.log('User link:', $(link).text(), '→', username, $(link).attr('href'));
});
return links;
}
Line 63 ⟶ 120:
function getUsernameFromLink(link) {
const href = $(link).attr('href');
constlet match = href.match(/User:([^/?&]+)/);
return match ? match[1] : null;
// Handle both regular wiki links and redlinks
if (href.startsWith('/wiki/')) {
match = decodeURIComponent(href).match(/User:([^/?&#]+)/);
} else {
// For redlinks, check the title parameter
const url = new URL(href, window.___location.origin);
const title = url.searchParams.get('title');
if (title) {
match = decodeURIComponent(title).match(/User:([^/?&#]+)/);
}
}
if (match) {
// Remove any subpage part if it somehow got through
const username = match[1].split('/')[0];
return username.replace(/_/g, ' ');
}
return null;
}
 
// Check if user has any advanced group
function hasAdvancedGroup(groups) {
return groups.some(group => ADVANCED_GROUPS.has(group));
}
 
Line 112 ⟶ 192:
} else {
const groups = user.groups || [];
status// =Check groups.includes('extendedconfirmed')if ?user 'extended'has :any 'normal';advanced group
status = hasAdvancedGroup(groups) ? 'extended' : 'normal';
}
userGroups.set(user.name, status);
Line 194 ⟶ 275:
userLinks.each((_, link) => {
const username = getUsernameFromLink(link);
if (username && !processedUsers.has(username)) {
users.push(username);
processedUsers.add(username);
Line 218 ⟶ 299:
mw.hook('wikipage.content').add(processPage);
});
// </nowiki>