|
|
| 第18行: |
第18行: |
| }); | | }); |
| })(); | | })(); |
|
| |
| $(function() {
| |
| // 仅在内容页面运行
| |
| if (mw.config.get('wgNamespaceNumber') === 0 && mw.config.get('wgAction') === 'view') {
| |
| var pageTitle = mw.config.get('wgPageName');
| |
| var apiUrl = mw.util.wikiScript('api');
| |
| var maxDisplayUsers = 3; // 直接显示的最大用户数
| |
| var creditsLink = mw.util.getUrl(pageTitle, { action: 'credits' });
| |
|
| |
| // 获取修订历史
| |
| $.getJSON(apiUrl, {
| |
| format: 'json',
| |
| action: 'query',
| |
| prop: 'revisions',
| |
| rvprop: 'timestamp|user',
| |
| rvlimit: 50,
| |
| titles: pageTitle,
| |
| rvdir: 'newer' // 从旧到新排序
| |
| }, function(data) {
| |
| var revisions = data.query.pages[0].revisions;
| |
| if (!revisions) return;
| |
|
| |
| // 处理修订数据
| |
| var editors = [];
| |
| revisions.forEach(function(rev) {
| |
| if (rev.user && !editors.includes(rev.user)) {
| |
| editors.unshift(rev.user); // 倒序插入保持最新在前
| |
| }
| |
| });
| |
|
| |
| if (editors.length === 0) return;
| |
|
| |
| // 提取最后编辑信息
| |
| var lastRev = revisions[revisions.length - 1];
| |
| var lastUser = lastRev.user;
| |
| var lastDate = new Date(lastRev.timestamp);
| |
| var formattedDate = lastDate.toLocaleDateString('en-GB', {
| |
| day: 'numeric',
| |
| month: 'long',
| |
| year: 'numeric'
| |
| });
| |
| var formattedTime = lastDate.toLocaleTimeString('en-GB', {
| |
| hour: '2-digit',
| |
| minute: '2-digit'
| |
| });
| |
|
| |
| // 构建用户列表
| |
| var displayedUsers = editors.slice(0, maxDisplayUsers);
| |
| var otherUsers = editors.slice(maxDisplayUsers);
| |
| var userList = [];
| |
|
| |
| if (displayedUsers.length > 1) {
| |
| var lastUser = displayedUsers.pop();
| |
| userList.push(
| |
| displayedUsers.join(', '),
| |
| ' and ' + lastUser
| |
| );
| |
| } else {
| |
| userList.push(displayedUsers[0]);
| |
| }
| |
|
| |
| // 构建完整文本
| |
| var creditText = document.createElement('div');
| |
| creditText.className = 'page-credits';
| |
| creditText.innerHTML = 'This page was last edited ' +
| |
| formattedTime + ', ' + formattedDate +
| |
| ' by ' + mw.config.get('wgSiteName') + ' user ' + lastUser +
| |
| '. Based on work by ';
| |
|
| |
| if (otherUsers.length > 0) {
| |
| var creditLink = document.createElement('a');
| |
| creditLink.href = creditsLink;
| |
| creditLink.textContent = 'others';
| |
|
| |
| var usersSpan = document.createElement('span');
| |
| usersSpan.innerHTML = userList.join('') +
| |
| (otherUsers.length > 0 ? ', ' : '') +
| |
| creditLink.outerHTML;
| |
|
| |
| creditText.appendChild(usersSpan);
| |
| } else {
| |
| creditText.innerHTML += userList.join('');
| |
| }
| |
|
| |
| // 插入到页面底部
| |
| var footer = document.getElementById('footer-info');
| |
| if (footer) {
| |
| footer.appendChild(creditText);
| |
| }
| |
| });
| |
| }
| |
| });
| |