✨🎊 Postal Wiki 三周年! 🎊✨
🎂 2026.09.11 — 邮路三载,百科同行

用户:Hehua/common.js:修订间差异

来自Postal Wiki
无编辑摘要
无编辑摘要
 
(未显示同一用户的19个中间版本)
第1行: 第1行:
mw.loader.load('https://wikiplus-app.com/Main.js');
mw.loader.load('https://cdn.jsdelivr.net/npm/wikiplus-core@latest/dist/Main.js');
mw.loader.load('https://cdn.jsdelivr.net/npm/gadget-hotcat-plus-zhwiki@1.2.0/HotCat-zh-plus.js');
importScript('User:Hehua/hotcat.js');
importScript('User:Hehua/filepreview.js');
// InPageEdit NEXT
// InPageEdit NEXT
document.body.append(
document.body.append(
   Object.assign(document.createElement('script'), {
   Object.assign(document.createElement('script'), {
     src: 'https://cdn.jsdelivr.net/npm/@inpageedit/core/dist/index.js',
     src: 'https://gcore.jsdelivr.net/npm/@inpageedit/core/dist/index.js',
     type: 'module',
     type: 'module',
   })
   })
)
);
// User:Hehua/common.js
// 这段代码只有你自己能看到
if (true) {
    console.log('Hehua的个人JS已加载,正在添加UTC时钟...');
   
    // 等待所需模块
    mw.loader.using(['mediawiki.util', 'mediawiki.api', 'jquery']).then(function() {
       
        function addPersonalClock() {
            // 避免重复添加
            if ($('#utcdate-hehua').length) return true;
           
            // 添加到个人工具栏
            var node = mw.util.addPortletLink(
                'p-personal',
                mw.util.getUrl(mw.config.get('wgPageName'), {action: 'purge'}),
                '加载中...',
                'utcdate-hehua',
                'UTC时间(个人版)- 点击刷新页面'
            );
           
            if (!node) {
                console.log('无法添加时钟到个人工具栏');
                return false;
            }
           
            // 样式
            $(node).find('a').css({
                'font-weight': 'bold',
                'font-size': '110%',
                'color': '#36c', // 蓝色,便于识别
                'border-left': '1px solid #ccc',
                'padding-left': '10px'
            });
           
            // 点击事件
            $(node).on('click', function(e) {
                e.preventDefault();
                new mw.Api().post({
                    action: 'purge',
                    titles: mw.config.get('wgPageName')
                }).then(function() {
                    location.reload();
                }, function() {
                    mw.notify('刷新失败', {type: 'error'});
                });
            });
           
            // 更新时间函数
            function updateClock() {
                var now = new Date();
                var hh = now.getUTCHours().toString().padStart(2, '0');
                var mm = now.getUTCMinutes().toString().padStart(2, '0');
                var ss = now.getUTCSeconds().toString().padStart(2, '0');
                $(node).find('a').text(hh + ':' + mm + ':' + ss + ' UTC');
               
                // 精确计时
                setTimeout(updateClock, 1000 - now.getUTCMilliseconds());
            }
           
            updateClock();
            console.log('个人版UTC时钟添加成功');
            return true;
        }
       
        // 尝试添加(Timeless可能延迟加载DOM)
        var attempts = 0;
        var interval = setInterval(function() {
            if (addPersonalClock() || attempts >= 8) {
                clearInterval(interval);
                if (attempts >= 8) {
                    console.log('添加个人时钟失败,尝试8次后放弃');
                }
            }
            attempts++;
        }, 500);
       
    }).catch(function(err) {
        console.error('加载依赖模块失败:', err);
    });
};
//[T - Sunny00217]
if ( [ "zh-hant", "zh-tw", "zh-hk", "zh-mo" ].indexOf( mw.config.get( "wgUserLanguage" ) ) !== -1 ) {
$( "#pt-mycontris a" ).text( "我的貢獻 (" + mw.config.get( "wgUserEditCount" ) + ")" );
} else if ( [ "zh", "zh-hans", "zh-cn", "zh-my", "zh-sg" ].indexOf( mw.config.get( "wgUserLanguage" ) ) !== -1 ) {
$( "#pt-mycontris a" ).text( "我的贡献 (" + mw.config.get( "wgUserEditCount" ) + ")" );
} else if ( mw.config.get( "wgUserLanguage" ) === "qqx" ) {
$( "#pt-mycontris a" ).text( "(mycontris)-(wgUserEditCount)" );
} else {
$( "#pt-mycontris a" ).text( $( "#pt-mycontris a" ).text() + "(" + mw.config.get( "wgUserEditCount" ) + ")" );
}
/* 贡献排行(纯前端版) */
$(function () {
    var $box = $('#contrib-board');
    if (!$box.length) return;
    var api = new mw.Api();
 
    function esc(s) { return String(s).replace(/[&<>"]/g, function (c) {
        return { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c]; }); }
    function link(u) { return '<a href="' + mw.util.getUrl('User:' + u) + '">' + esc(u) + '</a>'; }
 
    var users = [], week = {};
    function getUsers(cont) {
        return api.get($.extend({ action: 'query', list: 'allusers',
            aulimit: '500', auprop: 'editcount|groups' }, cont || {}))
        .then(function (r) {
            r.query.allusers.forEach(function (u) {
                if (u.editcount > 0 && u.groups.indexOf('bot') === -1) users.push(u);
            });
            return r.continue ? getUsers(r.continue) : null;
        });
    }
    function getWeek(end, cont) {
        return api.get($.extend({ action: 'query', list: 'recentchanges',
            rcend: end, rclimit: 'max', rcprop: 'user|title', rctype: 'edit|new' }, cont || {}))
        .then(function (r) {
            r.query.recentchanges.forEach(function (c) {
                var s = week[c.user] || (week[c.user] = { edits: 0, pages: {} });
                s.edits++; s.pages[c.title] = 1;
            });
            return r.continue ? getWeek(end, r.continue) : null;
        });
    }
 
    $.when(getUsers(), getWeek(new Date(Date.now() - 7 * 864e5).toISOString()))
    .fail(function () { $box.text('数据加载失败'); })
    .then(function () {
        function score(u) {
            var w = week[u.name], pn = Object.keys(w.pages).length;
            return Math.round(pn + 2 * Math.sqrt(Math.max(0, w.edits - pn)));
        }
        var wk = users.filter(function (u) { return week[u.name]; })
                      .sort(function (a, b) { return score(b) - score(a); }).slice(0, 10);
        var all = users.slice().sort(function (a, b) { return b.editcount - a.editcount; }).slice(0, 20);
        var h = '<h3>本周贡献榜</h3><table class="wikitable"><tr><th>#</th><th>用户</th><th>编辑</th><th>涉及页面</th><th>分数</th></tr>';
        wk.forEach(function (u, i) {
            var w = week[u.name];
            h += '<tr><td>' + (i + 1) + '</td><td>' + link(u.name) + '</td><td>' + w.edits +
                '</td><td>' + Object.keys(w.pages).length + '</td><td>' + score(u) + '</td></tr>';
        });
        h += '</table><h3>总编辑排行</h3><table class="wikitable"><tr><th>#</th><th>用户</th><th>累计编辑</th></tr>';
        all.forEach(function (u, i) {
            h += '<tr><td>' + (i + 1) + '</td><td>' + link(u.name) + '</td><td>' + u.editcount + '</td></tr>';
        });
        h += '</table><p style="font-size:90%;color:#888">实时调用 API 统计;分数 = 页面数 + 2√(编辑−页面),与公版 ContributionScores 同公式</p>';
        $box.html(h);
    });
});

2026年8月31日 (一) 06:12的最新版本

mw.loader.load('https://cdn.jsdelivr.net/npm/wikiplus-core@latest/dist/Main.js');
importScript('User:Hehua/hotcat.js');
importScript('User:Hehua/filepreview.js');
// InPageEdit NEXT
document.body.append(
  Object.assign(document.createElement('script'), {
    src: 'https://gcore.jsdelivr.net/npm/@inpageedit/core/dist/index.js',
    type: 'module',
  })
);
// User:Hehua/common.js
// 这段代码只有你自己能看到
if (true) {
    console.log('Hehua的个人JS已加载,正在添加UTC时钟...');
    
    // 等待所需模块
    mw.loader.using(['mediawiki.util', 'mediawiki.api', 'jquery']).then(function() {
        
        function addPersonalClock() {
            // 避免重复添加
            if ($('#utcdate-hehua').length) return true;
            
            // 添加到个人工具栏
            var node = mw.util.addPortletLink(
                'p-personal',
                mw.util.getUrl(mw.config.get('wgPageName'), {action: 'purge'}),
                '加载中...',
                'utcdate-hehua',
                'UTC时间(个人版)- 点击刷新页面'
            );
            
            if (!node) {
                console.log('无法添加时钟到个人工具栏');
                return false;
            }
            
            // 样式
            $(node).find('a').css({
                'font-weight': 'bold',
                'font-size': '110%',
                'color': '#36c', // 蓝色,便于识别
                'border-left': '1px solid #ccc',
                'padding-left': '10px'
            });
            
            // 点击事件
            $(node).on('click', function(e) {
                e.preventDefault();
                new mw.Api().post({
                    action: 'purge',
                    titles: mw.config.get('wgPageName')
                }).then(function() {
                    location.reload();
                }, function() {
                    mw.notify('刷新失败', {type: 'error'});
                });
            });
            
            // 更新时间函数
            function updateClock() {
                var now = new Date();
                var hh = now.getUTCHours().toString().padStart(2, '0');
                var mm = now.getUTCMinutes().toString().padStart(2, '0');
                var ss = now.getUTCSeconds().toString().padStart(2, '0');
                $(node).find('a').text(hh + ':' + mm + ':' + ss + ' UTC');
                
                // 精确计时
                setTimeout(updateClock, 1000 - now.getUTCMilliseconds());
            }
            
            updateClock();
            console.log('个人版UTC时钟添加成功');
            return true;
        }
        
        // 尝试添加(Timeless可能延迟加载DOM)
        var attempts = 0;
        var interval = setInterval(function() {
            if (addPersonalClock() || attempts >= 8) {
                clearInterval(interval);
                if (attempts >= 8) {
                    console.log('添加个人时钟失败,尝试8次后放弃');
                }
            }
            attempts++;
        }, 500);
        
    }).catch(function(err) {
        console.error('加载依赖模块失败:', err);
    });
};
//[T - Sunny00217] 
if ( [ "zh-hant", "zh-tw", "zh-hk", "zh-mo" ].indexOf( mw.config.get( "wgUserLanguage" ) ) !== -1 ) {
 $( "#pt-mycontris a" ).text( "我的貢獻 (" + mw.config.get( "wgUserEditCount" ) + ")" );
} else if ( [ "zh", "zh-hans", "zh-cn", "zh-my", "zh-sg" ].indexOf( mw.config.get( "wgUserLanguage" ) ) !== -1 ) {
 $( "#pt-mycontris a" ).text( "我的贡献 (" + mw.config.get( "wgUserEditCount" ) + ")" );
} else if ( mw.config.get( "wgUserLanguage" ) === "qqx" ) {
 $( "#pt-mycontris a" ).text( "(mycontris)-(wgUserEditCount)" );
} else {
 $( "#pt-mycontris a" ).text( $( "#pt-mycontris a" ).text() + "(" + mw.config.get( "wgUserEditCount" ) + ")" );
}
/* 贡献排行(纯前端版) */
$(function () {
    var $box = $('#contrib-board');
    if (!$box.length) return;
    var api = new mw.Api();

    function esc(s) { return String(s).replace(/[&<>"]/g, function (c) {
        return { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c]; }); }
    function link(u) { return '<a href="' + mw.util.getUrl('User:' + u) + '">' + esc(u) + '</a>'; }

    var users = [], week = {};
    function getUsers(cont) {
        return api.get($.extend({ action: 'query', list: 'allusers',
            aulimit: '500', auprop: 'editcount|groups' }, cont || {}))
        .then(function (r) {
            r.query.allusers.forEach(function (u) {
                if (u.editcount > 0 && u.groups.indexOf('bot') === -1) users.push(u);
            });
            return r.continue ? getUsers(r.continue) : null;
        });
    }
    function getWeek(end, cont) {
        return api.get($.extend({ action: 'query', list: 'recentchanges',
            rcend: end, rclimit: 'max', rcprop: 'user|title', rctype: 'edit|new' }, cont || {}))
        .then(function (r) {
            r.query.recentchanges.forEach(function (c) {
                var s = week[c.user] || (week[c.user] = { edits: 0, pages: {} });
                s.edits++; s.pages[c.title] = 1;
            });
            return r.continue ? getWeek(end, r.continue) : null;
        });
    }

    $.when(getUsers(), getWeek(new Date(Date.now() - 7 * 864e5).toISOString()))
    .fail(function () { $box.text('数据加载失败'); })
    .then(function () {
        function score(u) {
            var w = week[u.name], pn = Object.keys(w.pages).length;
            return Math.round(pn + 2 * Math.sqrt(Math.max(0, w.edits - pn)));
        }
        var wk = users.filter(function (u) { return week[u.name]; })
                      .sort(function (a, b) { return score(b) - score(a); }).slice(0, 10);
        var all = users.slice().sort(function (a, b) { return b.editcount - a.editcount; }).slice(0, 20);
        var h = '<h3>本周贡献榜</h3><table class="wikitable"><tr><th>#</th><th>用户</th><th>编辑</th><th>涉及页面</th><th>分数</th></tr>';
        wk.forEach(function (u, i) {
            var w = week[u.name];
            h += '<tr><td>' + (i + 1) + '</td><td>' + link(u.name) + '</td><td>' + w.edits +
                 '</td><td>' + Object.keys(w.pages).length + '</td><td>' + score(u) + '</td></tr>';
        });
        h += '</table><h3>总编辑排行</h3><table class="wikitable"><tr><th>#</th><th>用户</th><th>累计编辑</th></tr>';
        all.forEach(function (u, i) {
            h += '<tr><td>' + (i + 1) + '</td><td>' + link(u.name) + '</td><td>' + u.editcount + '</td></tr>';
        });
        h += '</table><p style="font-size:90%;color:#888">实时调用 API 统计;分数 = 页面数 + 2√(编辑−页面),与公版 ContributionScores 同公式</p>';
        $box.html(h);
    });
});