User:Liangent/Gadgets/Toolkit/historyug.js

注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google ChromeFirefoxMicrosoft EdgeSafari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
    (function($, mw) {
        if (wgAction != 'history' || wgArticleId == 0) return;
        $(function() {
            var usernames = [];
            $('#pagehistory > li .mw-userlink').each(function() {
                if (usernames.indexOf($(this).text()) == -1) {
                    usernames.push($(this).text());
                }
            });
            $('#mw-history-search').append(
                '<br />Hide revisions made by:<span id="historyug_hideoptions"> (Loading...)</span>'
            );
            $.post(mw.util.wikiScript('api'), {
                action: 'query',
                list: 'users',
                usprop: 'groups',
                ususers: usernames.join('|'),
                format: 'xml'
            }, function(xhr, status) {
                var groups = [];
                $('api>query>users>user', xhr).each(function() {
                    var xmluser = this;
                    var ugs = [];
                    $('groups>g', this).each(function() {
                        var g = $(this).text();
                        ugs.push(g);
                        if (groups.indexOf(g) == -1) {
                            groups.push(g);
                        }
                    });
                    if (ugs.length == 0) return;
                    $('#pagehistory > li').each(function() {
                        var li = $(this);
                        if ($('.mw-userlink', this).text() == $(xmluser).attr('name')) {
                            $.each(ugs, function() {
                                li.addClass('usergroup-' + this);
                            })
                        }
                    })
                });
                if (groups.length == 0) {
                    $('#historyug_hideoptions').text(' (Unavailable)');
                } else {
                    var updatehide = function() {
                        $('#pagehistory > li').show();
                        $.each(groups, function() {
                            if ($('#historyug_hidechoice_' + this + ':checked').length != 0) {
                                $('#pagehistory > li.usergroup-' + this).hide();
                            }
                        });
                    };
                    $('#historyug_hideoptions').empty();
                    $.each(groups, function() {
                        $('#historyug_hideoptions').append(' ');
                        $('<input type="checkbox" />').change(updatehide)
                            .attr('id', 'historyug_hidechoice_' + this)
                            .appendTo('#historyug_hideoptions');
                        $('<label>' + this + '</label>')
                            .attr('for', 'historyug_hidechoice_' + this)
                            .appendTo('#historyug_hideoptions');
                    })
                }
            }, function(xhr, status, err) {
                $('#historyug_hideoptions').text(' (Error)');
            });
        });
    })(jQuery, mediaWiki);