打开/关闭菜单
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

MediaWiki:Gadget-ShowContributors.js:修订间差异

MediaWiki界面页面
第1行: 第1行:
(function() {
(function() {
     "use strict";
     "use strict";
     $((() => (async () => {
     $(function() {
        if (
        (async function() {
            ![0, 2, 4, 10, 12, 14, 828, 274].includes(mw.config.get("wgNamespaceNumber")) ||
            if (
            0 === mw.config.get("wgArticleId") ||
                ![0, 2, 4, 10, 12, 14, 828, 274].includes(mw.config.get("wgNamespaceNumber")) ||
            !["view", "history"].includes(mw.config.get("wgAction"))
                0 === mw.config.get("wgArticleId") ||
        )
                !["view", "history"].includes(mw.config.get("wgAction"))
            return;
            )
       
                return;
        mw.loader.addStyleTag(`
           
            #show-contributor-button {
            mw.loader.addStyleTag(`
                float: right;
                #show-contributor-button {
                margin-left: .5em;
                    float: right;
                margin-right: 0;
                    margin-left: .5em;
            }
                    margin-right: 0;
            #show-contributor-header {
                }
                background: #fff;
                #show-contributor-header {
                border-bottom: 1px solid #aaa;
                    background: #fff;
                font-weight: 600;
                    border-bottom: 1px solid #aaa;
                padding: .3em;
                    font-weight: 600;
                position: sticky;
                    padding: .3em;
                text-align: center;
                    position: sticky;
                top: 0;
                    text-align: center;
            }
                    top: 0;
            #show-contributor-headline {
                }
                font-size: 1.3em;
                #show-contributor-headline {
            }
                    font-size: 1.3em;
            #show-contributor-close {
                }
                border-radius: 50%;
                #show-contributor-close {
                cursor: pointer;
                    border-radius: 50%;
                position: absolute;
                    cursor: pointer;
                right: 5px;
                    position: absolute;
                top: 5px;
                    right: 5px;
            }
                    top: 5px;
            #show-contributor-close:hover {
                }
                background-color: #eee;
                #show-contributor-close:hover {
            }
                    background-color: #eee;
            #show-contributor-table {
                }
                margin: 0;
                #show-contributor-table {
                width: 100%;
                    margin: 0;
            }
                    width: 100%;
            #show-contributor-table .user-avatar {
                }
                border-radius: 50%;
                #show-contributor-table .user-avatar {
                height: 20px;
                    border-radius: 50%;
                width: 20px;
                    height: 20px;
            }
                    width: 20px;
            .skin-citizen #show-contributor-button {
                }
                float: none;
                .skin-citizen #show-contributor-button {
                margin: 0 0.5em 0 0;
                    float: none;
                display: inline-flex;
                    margin: 0 0.5em 0 0;
                align-items: center;
                    display: inline-flex;
                vertical-align: middle;
            }
            @media (min-width: 1120px) {
                .skin-citizen .citizen-page-header-inner {
                    display: flex;
                    justify-content: space-between;
                     align-items: center;
                     align-items: center;
                    vertical-align: middle;
                 }
                 }
                 .skin-citizen .citizen-page-heading {
                 @media (min-width: 1120px) {
                    flex-grow: 1;
                    .skin-citizen .citizen-page-header-inner {
                        display: flex;
                        justify-content: space-between;
                        align-items: center;
                    }
                    .skin-citizen .citizen-page-heading {
                        flex-grow: 1;
                    }
                 }
                 }
            }
                @media (max-width: 1119px) {
            @media (max-width: 1119px) {
                    .skin-citizen #show-contributor-button {
                .skin-citizen #show-contributor-button {
                        margin: 0.5em 0;
                    margin: 0.5em 0;
                        display: block;
                    display: block;
                    }
                 }
                 }
             }
             `);
        `);


        await mw.loader.using([
            await mw.loader.using([
            "mediawiki.api",
                "mediawiki.api",
            "mediawiki.notification",
                "mediawiki.notification",
            "oojs-ui",
                "oojs-ui",
            "oojs-ui.styles.icons-interactions",
                "oojs-ui.styles.icons-interactions",
            "jquery.tablesorter"
                "jquery.tablesorter"
        ]);
            ]);


        class t extends OO.ui.Dialog {
            class t extends OO.ui.Dialog {
            $table = $('<table id="show-contributor-table" class="wikitable" />');
                $table = $('<table id="show-contributor-table" class="wikitable" />');
            $tbody = $("<tbody />");
                $tbody = $("<tbody />");
            $body;
                $body;
            got = !1;
                got = !1;
            static static = {...super.static,name:"ShowContributor",tagName:"div"};
                static static = {...super.static,name:"ShowContributor",tagName:"div"};
            initialize() {
                initialize() {
                return super.initialize(),
                    return super.initialize(),
                this.$body.append(
                    this.$body.append(
                    $('<div id="show-contributor-header" />').append(
                        $('<div id="show-contributor-header" />').append(
                        $('<div id="show-contributor-headline">本页贡献统计</div>'),
                            $('<div id="show-contributor-headline">本页贡献统计</div>'),
                        new OO.ui.IconWidget({icon:"close",id:"show-contributor-close"}).$element.on("click",(()=>this.close()))
                            new OO.ui.IconWidget({icon:"close",id:"show-contributor-close"}).$element.on("click",(() => this.close()))
                        ),
                        this.$table.append(
                            $("<thead><th>用户</th><th>编辑数</th><th>增加字节数</th><th>删减字节数</th></thead>"),
                            this.$tbody
                        )
                     ),
                     ),
                     this.$table.append(
                     this
                         $("<thead><th>用户</th><th>编辑数</th><th>增加字节数</th><th>删减字节数</th></thead>"),
                }
                         this.$tbody
                getContributors = async () => {
                    const t = new mw.Api,
                        e = {};
                    let o = "",
                        i = 0;
                    const r = {
                        action:"query",
                        format:"json",
                        prop:"revisions",
                        titles:mw.config.get("wgPageName"),
                        rvprop:"user|size",
                        rvlimit:"max",
                        rvdir:"newer"
                    };
                    do {
                        o && (r.rvcontinue = o);
                        try {
                            const n = await t.get(r);
                            o = n.continue?.rvcontinue;
                            for (const {user:t,size:o} of Object.values(n.query.pages)[0].revisions)
                                e[t] ||= [],
                                e[t].push(o - i),
                                i = o
                        } catch (t) {
                            mw.notify(`获取编辑记录失败:${t}`,{type:"error"})
                        }
                    } while (o);
                    return e
                };
                addRow = (t,{user:e,count:o,add:i,remove:r}) => {
                    t.append(
                         $("<tr />").append(
                            $("<td />").append(
                                $(`<a href="${mw.config.get("wgArticlePath").replace("$1",`User:${e}`)}" />`).text(e)
                            ),
                            `<td>${o}</td>`,
                            `<td>${i}</td>`,
                            `<td>${r}</td>`
                         )
                     )
                     )
                ),
                this
            }
            getContributors = async () => {
                const t = new mw.Api,
                    e = {};
                let o = "",
                    i = 0;
                const r = {
                    action:"query",
                    format:"json",
                    prop:"revisions",
                    titles:mw.config.get("wgPageName"),
                    rvprop:"user|size",
                    rvlimit:"max",
                    rvdir:"newer"
                 };
                 };
                 do {
                 showContributors = t => {
                    o && (r.rvcontinue = o);
                     this.$tbody.empty();
                    try {
                    for (const e in t)
                        const n = await t.get(r);
                        this.addRow(this.$tbody, {
                        o = n.continue?.rvcontinue;
                            user:e,
                        for (const {user:t,size:o} of Object.values(n.query.pages)[0].revisions)
                            count:t[e].length,
                            e[t] ||= [],
                            add:t[e].reduce((s,n)=>n>0?s+n:s,0),
                            e[t].push(o - i),
                            remove:t[e].reduce((s,n)=>n<0?s+n:s,0)
                            i = o
                        });
                    } catch (t) {
                    this.got = !0
                        mw.notify(`获取编辑记录失败:${t}`,{type:"error"})
                }
                    }
                } while (o);
                return e
            };
            addRow = (t,{user:e,count:o,add:i,remove:r}) => {
                t.append(
                    $("<tr />").append(
                        $("<td />").append(
                            $(`<a href="${mw.config.get("wgArticlePath").replace("$1",`User:${e}`)}" />`).text(e)
                        ),
                        `<td>${o}</td>`,
                        `<td>${i}</td>`,
                        `<td>${r}</td>`
                     )
                )
            };
            showContributors = t => {
                this.$tbody.empty();
                for (const e in t)
                    this.addRow(this.$tbody, {
                        user:e,
                        count:t[e].length,
                        add:t[e].reduce((s,n)=>n>0?s+n:s,0),
                        remove:t[e].reduce((s,n)=>n<0?s+n:s,0)
                    });
                this.got = !0
             }
             }
        }


        const e = new OO.ui.WindowManager({id:"show-contributor"});
            const e = new OO.ui.WindowManager({id:"show-contributor"});
        $(document.body).append(e.$element);
            $(document.body).append(e.$element);
        const o = new t({size:"large"});
            const o = new t({size:"large"});
        e.addWindows([o]);
            e.addWindows([o]);


        const i = new OO.ui.ButtonWidget({
            const i = new OO.ui.ButtonWidget({
            label:"本页贡献者",
                label:"本页贡献者",
            icon:"search",
                icon:"search",
            flags:"progressive",
                flags:"progressive",
            id:"show-contributor-button"
                id:"show-contributor-button"
        });
            });


        const insertButton = () => {
            const insertButton = () => {
            $("#show-contributor-button").detach();
                $("#show-contributor-button").detach();
            const skin = mw.config.get("skin");
                const skin = mw.config.get("skin");
            if (skin === "citizen") {
                if (skin === "citizen") {
                if (window.innerWidth >= 1120) {
                    if (window.innerWidth >= 1120) {
                    $(".page-actions").prepend(i.$element);
                        $(".page-actions").prepend(i.$element);
                    } else {
                        $(".firstHeading-container").append(i.$element);
                    }
                } else if (skin === "vector-2022") {
                    $("header.mw-body-header.vector-page-titlebar").append(i.$element);
                 } else {
                 } else {
                     $(".firstHeading-container").append(i.$element);
                     $("#bodyContent").prepend(i.$element);
                 }
                 }
             } else if (skin === "vector-2022") {
             };
                $("header.mw-body-header.vector-page-titlebar").append(i.$element);
 
             } else {
             // 初始插入
                $("#bodyContent").prepend(i.$element);
            insertButton();
            }
        };


        // 初始插入
            // 仅在断点穿越时更新插入位置
        insertButton();
            let isWide = window.innerWidth >= 1120;
            $(window).on("resize", () => {
                clearTimeout(window.__showContributorResizeTimer);
                window.__showContributorResizeTimer = setTimeout(() => {
                    const nowWide = window.innerWidth >= 1120;
                    if (nowWide !== isWide) {
                        isWide = nowWide;
                        insertButton();
                    }
                }, 200);
            });


        // 仅在断点穿越时更新插入位置
            // 点击事件
        let isWide = window.innerWidth >= 1120;
            i.on("click", async () => {
        $(window).on("resize", () => {
                if (!o.got) {
            clearTimeout(window.__showContributorResizeTimer);
                    i.setLabel("正在查询");
            window.__showContributorResizeTimer = setTimeout(() => {
                    const t = await o.getContributors();
                const nowWide = window.innerWidth >= 1120;
                    o.showContributors(t);
                if (nowWide !== isWide) {
                     o.$table.tablesorter();
                     isWide = nowWide;
                     i.setLabel("本页贡献者");
                     insertButton();
                 }
                 }
            }, 200);
                 e.openWindow(o);
        });
             });
 
         })();
        // 点击事件
     });
        i.on("click", async () => {
            if (!o.got) {
                 i.setLabel("正在查询");
                const t = await o.getContributors();
                o.showContributors(t);
                o.$table.tablesorter();
                i.setLabel("本页贡献者");
             }
            e.openWindow(o);
         });
     })()))
})();
})();

2025年6月17日 (二) 16:42的版本

(function() {
    "use strict";
    $(function() {
        (async function() {
            if (
                ![0, 2, 4, 10, 12, 14, 828, 274].includes(mw.config.get("wgNamespaceNumber")) ||
                0 === mw.config.get("wgArticleId") ||
                !["view", "history"].includes(mw.config.get("wgAction"))
            )
                return;
            
            mw.loader.addStyleTag(`
                #show-contributor-button {
                    float: right;
                    margin-left: .5em;
                    margin-right: 0;
                }
                #show-contributor-header {
                    background: #fff;
                    border-bottom: 1px solid #aaa;
                    font-weight: 600;
                    padding: .3em;
                    position: sticky;
                    text-align: center;
                    top: 0;
                }
                #show-contributor-headline {
                    font-size: 1.3em;
                }
                #show-contributor-close {
                    border-radius: 50%;
                    cursor: pointer;
                    position: absolute;
                    right: 5px;
                    top: 5px;
                }
                #show-contributor-close:hover {
                    background-color: #eee;
                }
                #show-contributor-table {
                    margin: 0;
                    width: 100%;
                }
                #show-contributor-table .user-avatar {
                    border-radius: 50%;
                    height: 20px;
                    width: 20px;
                }
                .skin-citizen #show-contributor-button {
                    float: none;
                    margin: 0 0.5em 0 0;
                    display: inline-flex;
                    align-items: center;
                    vertical-align: middle;
                }
                @media (min-width: 1120px) {
                    .skin-citizen .citizen-page-header-inner {
                        display: flex;
                        justify-content: space-between;
                        align-items: center;
                    }
                    .skin-citizen .citizen-page-heading {
                        flex-grow: 1;
                    }
                }
                @media (max-width: 1119px) {
                    .skin-citizen #show-contributor-button {
                        margin: 0.5em 0;
                        display: block;
                    }
                }
            `);

            await mw.loader.using([
                "mediawiki.api",
                "mediawiki.notification",
                "oojs-ui",
                "oojs-ui.styles.icons-interactions",
                "jquery.tablesorter"
            ]);

            class t extends OO.ui.Dialog {
                $table = $('<table id="show-contributor-table" class="wikitable" />');
                $tbody = $("<tbody />");
                $body;
                got = !1;
                static static = {...super.static,name:"ShowContributor",tagName:"div"};
                initialize() {
                    return super.initialize(),
                    this.$body.append(
                        $('<div id="show-contributor-header" />').append(
                            $('<div id="show-contributor-headline">本页贡献统计</div>'),
                            new OO.ui.IconWidget({icon:"close",id:"show-contributor-close"}).$element.on("click",(() => this.close()))
                        ),
                        this.$table.append(
                            $("<thead><th>用户</th><th>编辑数</th><th>增加字节数</th><th>删减字节数</th></thead>"),
                            this.$tbody
                        )
                    ),
                    this
                }
                getContributors = async () => {
                    const t = new mw.Api,
                        e = {};
                    let o = "",
                        i = 0;
                    const r = {
                        action:"query",
                        format:"json",
                        prop:"revisions",
                        titles:mw.config.get("wgPageName"),
                        rvprop:"user|size",
                        rvlimit:"max",
                        rvdir:"newer"
                    };
                    do {
                        o && (r.rvcontinue = o);
                        try {
                            const n = await t.get(r);
                            o = n.continue?.rvcontinue;
                            for (const {user:t,size:o} of Object.values(n.query.pages)[0].revisions)
                                e[t] ||= [],
                                e[t].push(o - i),
                                i = o
                        } catch (t) {
                            mw.notify(`获取编辑记录失败:${t}`,{type:"error"})
                        }
                    } while (o);
                    return e
                };
                addRow = (t,{user:e,count:o,add:i,remove:r}) => {
                    t.append(
                        $("<tr />").append(
                            $("<td />").append(
                                $(`<a href="${mw.config.get("wgArticlePath").replace("$1",`User:${e}`)}" />`).text(e)
                            ),
                            `<td>${o}</td>`,
                            `<td>${i}</td>`,
                            `<td>${r}</td>`
                        )
                    )
                };
                showContributors = t => {
                    this.$tbody.empty();
                    for (const e in t)
                        this.addRow(this.$tbody, {
                            user:e,
                            count:t[e].length,
                            add:t[e].reduce((s,n)=>n>0?s+n:s,0),
                            remove:t[e].reduce((s,n)=>n<0?s+n:s,0)
                        });
                    this.got = !0
                }
            }

            const e = new OO.ui.WindowManager({id:"show-contributor"});
            $(document.body).append(e.$element);
            const o = new t({size:"large"});
            e.addWindows([o]);

            const i = new OO.ui.ButtonWidget({
                label:"本页贡献者",
                icon:"search",
                flags:"progressive",
                id:"show-contributor-button"
            });

            const insertButton = () => {
                $("#show-contributor-button").detach();
                const skin = mw.config.get("skin");
                if (skin === "citizen") {
                    if (window.innerWidth >= 1120) {
                        $(".page-actions").prepend(i.$element);
                    } else {
                        $(".firstHeading-container").append(i.$element);
                    }
                } else if (skin === "vector-2022") {
                    $("header.mw-body-header.vector-page-titlebar").append(i.$element);
                } else {
                    $("#bodyContent").prepend(i.$element);
                }
            };

            // 初始插入
            insertButton();

            // 仅在断点穿越时更新插入位置
            let isWide = window.innerWidth >= 1120;
            $(window).on("resize", () => {
                clearTimeout(window.__showContributorResizeTimer);
                window.__showContributorResizeTimer = setTimeout(() => {
                    const nowWide = window.innerWidth >= 1120;
                    if (nowWide !== isWide) {
                        isWide = nowWide;
                        insertButton();
                    }
                }, 200);
            });

            // 点击事件
            i.on("click", async () => {
                if (!o.got) {
                    i.setLabel("正在查询");
                    const t = await o.getContributors();
                    o.showContributors(t);
                    o.$table.tablesorter();
                    i.setLabel("本页贡献者");
                }
                e.openWindow(o);
            });
        })();
    });
})();