MediaWiki:Gadget-UserID.js:修订间差异
外观
![]() OctoberSama(留言 | 贡献) (创建页面,内容为“$(function() { // 检查所有条件: // 1. 用户命名空间(NS_USER = 2) // 2. 主页面(非子页面) // 3. 浏览模式(action=view) if ( mw.config.get('wgNamespaceNumber') !== 2 || mw.config.get('wgTitle').includes('/') || !document.body.classList.contains('action-view') ) return; // 从页面标题获取用户名 var username = mw.config.get('wgTitle'); // 创建占位…”) |
![]() OctoberSama(留言 | 贡献) 小 |
||
第5行: | 第5行: | ||
// 3. 浏览模式(action=view) | // 3. 浏览模式(action=view) | ||
if ( | if ( | ||
mw.config.get('wgNamespaceNumber') !== 2 || | mw.config.get('wgNamespaceNumber') !== 2 || | ||
mw.config.get('wgTitle').includes('/') || | mw.config.get('wgTitle').includes('/') || | ||
!document.body.classList.contains('action-view') | !document.body.classList.contains('action-view') | ||
) return; | ) return; | ||
第12行: | 第12行: | ||
// 从页面标题获取用户名 | // 从页面标题获取用户名 | ||
var username = mw.config.get('wgTitle'); | var username = mw.config.get('wgTitle'); | ||
// 根据当前皮肤选择不同的显示方式 | |||
var currentSkin = mw.config.get('skin'); | |||
var isCitizenSkin = currentSkin === 'citizen'; | |||
// 创建占位元素 | // 创建占位元素 | ||
var | var uidElement; | ||
var containerSelector; | |||
// | if (isCitizenSkin) { | ||
// Citizen皮肤 - 添加到现有容器 | |||
uidElement = $('<span id="citizen-tagline-user-uid">UID:加载中...</span>'); | |||
containerSelector = '#citizen-tagline-user'; | |||
$(containerSelector).append(uidElement); | |||
} else { | |||
// 其他皮肤 - 在内容顶部添加新容器 | |||
uidElement = $('<div id="user-id-display">UID:加载中...</div>') | |||
containerSelector = '#mw-content-text'; | |||
$(containerSelector).prepend(uidElement); | |||
} | |||
// 通过API获取用户ID | // 通过API获取用户ID | ||
第29行: | 第44行: | ||
var user = data.query.users[0]; | var user = data.query.users[0]; | ||
if (user && user.userid) { | if (user && user.userid) { | ||
$( | $(uidElement).text('UID:' + user.userid); | ||
} else { | } else { | ||
$( | $(uidElement).text('⚠️ 用户ID获取失败'); | ||
} | } | ||
}).fail(function() { | }).fail(function() { | ||
$( | $(uidElement).text('⚠️ API请求失败'); | ||
}); | }); | ||
}); | }); |
2025年6月7日 (六) 03:45的版本
$(function() { // 检查所有条件: // 1. 用户命名空间(NS_USER = 2) // 2. 主页面(非子页面) // 3. 浏览模式(action=view) if ( mw.config.get('wgNamespaceNumber') !== 2 || mw.config.get('wgTitle').includes('/') || !document.body.classList.contains('action-view') ) return; // 从页面标题获取用户名 var username = mw.config.get('wgTitle'); // 根据当前皮肤选择不同的显示方式 var currentSkin = mw.config.get('skin'); var isCitizenSkin = currentSkin === 'citizen'; // 创建占位元素 var uidElement; var containerSelector; if (isCitizenSkin) { // Citizen皮肤 - 添加到现有容器 uidElement = $('<span id="citizen-tagline-user-uid">UID:加载中...</span>'); containerSelector = '#citizen-tagline-user'; $(containerSelector).append(uidElement); } else { // 其他皮肤 - 在内容顶部添加新容器 uidElement = $('<div id="user-id-display">UID:加载中...</div>') containerSelector = '#mw-content-text'; $(containerSelector).prepend(uidElement); } // 通过API获取用户ID new mw.Api().get({ action: 'query', list: 'users', ususers: username, usprop: 'userid', formatversion: 2 }).done(function(data) { var user = data.query.users[0]; if (user && user.userid) { $(uidElement).text('UID:' + user.userid); } else { $(uidElement).text('⚠️ 用户ID获取失败'); } }).fail(function() { $(uidElement).text('⚠️ API请求失败'); }); });