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

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

MediaWiki界面页面
第6行: 第6行:
             0 === mw.config.get("wgArticleId") ||
             0 === mw.config.get("wgArticleId") ||
             !["view", "history"].includes(mw.config.get("wgAction"))
             !["view", "history"].includes(mw.config.get("wgAction"))
         ) return;
         )
            return;
          
          
         mw.loader.addStyleTag(`
         mw.loader.addStyleTag(`
#show-contributor-button {
            #show-contributor-button {
    float: right;
                float: right;
    margin-left: .5em;
                margin-left: .5em;
    margin-right: 0;
                margin-right: 0;
}
            }
#show-contributor-header {
            #show-contributor-header {
    background: #fff;
                background: #fff;
    border-bottom: 1px solid #aaa;
                border-bottom: 1px solid #aaa;
    font-weight: 600;
                font-weight: 600;
    padding: .3em;
                padding: .3em;
    position: sticky;
                position: sticky;
    text-align: center;
                text-align: center;
    top: 0;
                top: 0;
    z-index: 1;
            }
}
            #show-contributor-headline {
#show-contributor-headline {
                font-size: 1.3em;
    font-size: 1.3em;
            }
}
            #show-contributor-close {
#show-contributor-close {
                border-radius: 50%;
    border-radius: 50%;
                cursor: pointer;
    cursor: pointer;
                position: absolute;
    position: absolute;
                right: 5px;
    right: 5px;
                top: 5px;
    top: 5px;
            }
}
            #show-contributor-close:hover {
#show-contributor-close:hover {
                background-color: #eee;
    background-color: #eee;
            }
}
            #show-contributor-table {
#show-contributor-table {
                margin: 0;
    margin: 0;
                width: 100%;
    width: 100%;
            }
}
            #show-contributor-table .user-avatar {
#show-contributor-table .user-avatar {
                border-radius: 50%;
    border-radius: 50%;
                height: 20px;
    height: 20px;
                width: 20px;
    width: 20px;
            }
}
            .skin-citizen #show-contributor-button {
/* Citizen 皮肤响应式样式 */
                float: none;
.skin-citizen #show-contributor-button {
                margin: 0 0.5em 0 0;
    float: none;
                display: inline-flex;
    margin: 0 0 0 0.5em;
                align-items: center;
    display: inline-flex;
                vertical-align: middle;
    align-items: center;
            }
    vertical-align: middle;
            @media (min-width: 1120px) {
}
                .skin-citizen .citizen-page-header-inner {
@media (min-width: 1120px) {
                    display: flex;
    .skin-citizen .citizen-page-header-inner {
                    justify-content: space-between;
        display: flex;
                    align-items: center;
        justify-content: space-between;
                }
        align-items: center;
                .skin-citizen .citizen-page-heading {
    }
                    flex-grow: 1;
    .skin-citizen .citizen-page-heading {
                }
        flex-grow: 1;
            }
    }
            @media (max-width: 1119px) {
}
                .skin-citizen #show-contributor-button {
@media (max-width: 1119px) {
                    margin: 0.5em 0;
    .skin-citizen .firstHeading-container {
                    display: block;
        display: flex;
                }
        justify-content: space-between;
            }
        align-items: center;
    }
    .skin-citizen #show-contributor-button {
        margin: 0;
    }
}
         `);
         `);


第84行: 第79行:
         ]);
         ]);


         class ContributorDialog 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 />");
             got = false;
            $body;
 
             got = !1;
             static static = {
             static static = {...super.static,name:"ShowContributor",tagName:"div"};
                ...super.static,
                name: "ShowContributor",
                tagName: "div"
            };
 
             initialize() {
             initialize() {
                 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({
                         new OO.ui.IconWidget({icon:"close",id:"show-contributor-close"}).$element.on("click",(()=>this.close()))
                            icon: "close",
                            id: "show-contributor-close"
                        }).$element.on("click", () => this.close())
                     ),
                     ),
                     this.$table.append(
                     this.$table.append(
第109行: 第96行:
                         this.$tbody
                         this.$tbody
                     )
                     )
                 );
                 ),
                 return this;
                 this
             }
             }
             getContributors = async () => {
             getContributors = async () => {
                 const api = new mw.Api();
                 const t = new mw.Api,
                const users = {};
                    e = {};
                 let rvcontinue = "", lastSize = 0;
                 let o = "",
                 const params = {
                    i = 0;
                     action: "query",
                 const r = {
                     format: "json",
                     action:"query",
                     prop: "revisions",
                     format:"json",
                     titles: mw.config.get("wgPageName"),
                     prop:"revisions",
                     rvprop: "user|size",
                     titles:mw.config.get("wgPageName"),
                     rvlimit: "max",
                     rvprop:"user|size",
                     rvdir: "newer"
                     rvlimit:"max",
                     rvdir:"newer"
                 };
                 };
                 do {
                 do {
                     if (rvcontinue) params.rvcontinue = rvcontinue;
                     o && (r.rvcontinue = o);
                     try {
                     try {
                         const result = await api.get(params);
                         const n = await t.get(r);
                         rvcontinue = result.continue?.rvcontinue;
                         o = n.continue?.rvcontinue;
                         for (const { user, size } of Object.values(result.query.pages)[0].revisions) {
                         for (const {user:t,size:o} of Object.values(n.query.pages)[0].revisions)
                             users[user] ||= [];
                             e[t] ||= [],
                             users[user].push(size - lastSize);
                             e[t].push(o - i),
                             lastSize = size;
                             i = o
                        }
                     } catch (t) {
                     } catch (err) {
                         mw.notify(`获取编辑记录失败:${t}`,{type:"error"})
                         mw.notify(`获取编辑记录失败:${err}`, { type: "error" });
                        break;
                     }
                     }
                 } while (rvcontinue);
                 } while (o);
 
                 return e
                 return users;
             };
             };
 
             addRow = (t,{user:e,count:o,add:i,remove:r}) => {
             addRow = ($target, { user, count, add, remove }) => {
                 t.append(
                 $target.append(
                     $("<tr />").append(
                     $("<tr />").append(
                         $("<td />").append(
                         $("<td />").append(
                             $(`<a href="${mw.config.get("wgArticlePath").replace("$1", `User:${user}`)}" />`).append(
                             $(`<a href="${mw.config.get("wgArticlePath").replace("$1",`User:${e}`)}" />`).append(
                                 `<img class="user-avatar" src="https://commons.moegirl.org.cn/extensions/Avatar/avatar.php?user=${user}" />`,
                                 `<img class="user-avatar" src="https://commons.moegirl.org.cn/extensions/Avatar/avatar.php?user=${e}" />`,
                                 user
                                 e
                             )
                             )
                         ),
                         ),
                         `<td>${count}</td>`,
                         `<td>${o}</td>`,
                         `<td>${add}</td>`,
                         `<td>${i}</td>`,
                         `<td>${remove}</td>`
                         `<td>${r}</td>`
                     )
                     )
                 );
                 )
             };
             };
 
             showContributors = t => {
             showContributors = (data) => {
                 this.$tbody.empty();
                 this.$tbody.empty();
                 for (const user in data) {
                 for (const e in t)
                    const edits = data[user];
                     this.addRow(this.$tbody, {
                     this.addRow(this.$tbody, {
                         user,
                         user:e,
                         count: edits.length,
                         count:t[e].length,
                         add: edits.reduce((sum, n) => n > 0 ? sum + n : sum, 0),
                         add:t[e].reduce((s,n)=>n>0?s+n:s,0),
                         remove: edits.reduce((sum, n) => n < 0 ? sum + n : sum, 0)
                         remove:t[e].reduce((s,n)=>n<0?s+n:s,0)
                     });
                     });
                }
                 this.got = !0
                 this.got = true;
             }
             };
         }
         }


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


         const button = 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();
             if (mw.config.get("skin") === "citizen") {
             if (mw.config.get("skin") === "citizen") {
                 const width = window.innerWidth;
                 if (window.innerWidth >= 1120) {
                if (width >= 1120) {
                     $(".page-actions").prepend(i.$element);
                     $(".page-actions").prepend(button.$element);
                 } else {
                 } else {
                     const $heading = $(".firstHeading-container");
                     $(".firstHeading-container").append(i.$element);
                    if ($heading.length) {
                        $heading.append(button.$element);
                    }
                 }
                 }
             } else {
             } else {
                 $("#bodyContent").prepend(button.$element);
                 $("#bodyContent").prepend(i.$element);
             }
             }
         };
         };


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


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

2025年6月11日 (三) 14:00的版本

(() => {
    "use strict";
    $((() => (async () => {
        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}`)}" />`).append(
                                `<img class="user-avatar" src="https://commons.moegirl.org.cn/extensions/Avatar/avatar.php?user=${e}" />`,
                                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();
            if (mw.config.get("skin") === "citizen") {
                if (window.innerWidth >= 1120) {
                    $(".page-actions").prepend(i.$element);
                } else {
                    $(".firstHeading-container").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);
        });
    })()))
})();