User:DodoMan/justatest.js

From Test Wiki
Revision as of 17:12, 9 April 2024 by DodoMan (talk | contribs) (Created page with "// Create portlet link var portletLinkOnline = mw.util.addPortletLink( 'p-personal', '#', 'ia', 't-onlineia', 'Seek help from ia.', '', '#pt-userpage' ); var rcstart, rcend, time; var users = []; var ia= [], var api = new mw.Api(); // Bind click handler $(portletLinkOnline).click(function(e) { e.preventDefault(); users = []; var usersExt = []; admins = []; bureaucrats = [];...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
// Create portlet link
var portletLinkOnline = mw.util.addPortletLink(
    'p-personal',
    '#',
    'ia',
    't-onlineia',
    'Seek help from ia.',
    '',
    '#pt-userpage'
);
    var rcstart, rcend, time;
    var users = [];
    var ia= [],
    var api = new mw.Api();

    // Bind click handler
    $(portletLinkOnline).click(function(e) {
        e.preventDefault();

        users = [];
        var usersExt = [];
        admins = [];
        bureaucrats = [];
        stewards = [];

        //Recent edit within 30 minutes
        time = new Date();
        rcstart = time.toISOString();
        time.setMinutes(time.getMinutes() - 30);
        rcend = time.toISOString();

        //API:RecentChanges
        api.get({
            format: 'json',
            action: 'query',
            list: 'recentchanges',
            rcprop: 'user',
            rcstart: rcstart,
            rcend: rcend,
            rcshow: '!bot|!anon',
            rclimit: 500
        }).done(function(data) {
            $.each(data.query.recentchanges, function(i, item) {
                users[i] = item.user;
            });
            api.get({
                format: 'json',
                action: 'query',
                list: 'logevents',
                leprop: 'user',
                lestart: rcstart,
                leend: rcend,
                lelimit: 500
            }).done(function(data) {
                $.each(data.query.logevents, function(i, item) {
                    usersExt[i] = item.user;
                });
                Array.prototype.push.apply(users, usersExt);
                users = $.unique(users.sort());
                var promises = [];
                var mark = function(data) {
                    $.each(data.query.users, function(i, user) {
                        if ($.inArray('bot', user.groups) === -1) {
                            if ($.inArray('interface administrator', user.groups) > -1) {
                                bureaucrats[i] = user.name;
                            }
                        }
                    });
                };
                for (var i=0; i<(users.length+50)/50; i++) {
                    promises.push(api.get({
                        format: 'json',
                        action: 'query',
                        list: 'users',
                        ususers: users.slice(i*50, (i+1)*50).join('|'),
                        usprop: 'groups'
                    }).done(mark));
                }
                $.when.apply($, promises).done(function () {
                    var filter = function(n) {
                        return n;
                    };
                    ia = interface administrator.filter(filter);
                    var userlink = function(user) {
                        var user2 = user.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&lt;');
                        return '<br><a href="/wiki/User:' + user2 + '" target="_blank">' + user2 + '</a>&nbsp;<small style="opacity:.75;">(<a href="/wiki/User talk:' + user2 + '" target="_blank">Talk</a>)</small> ';
                    };
                    if (bureaucrats.length > 0) {
                        var adminsstring = ['<center><p><b>IA Online:</b></p></center>'];
                        if (interface administrator.length > 0) {
                            adminsstring.push('<p style="word-break:break-all;">There are currently ' + interface administrator.length + ' ia<br>online:');
                            $.each(interface administrator, function(i, e) {
                                adminsstring.push(userlink(e));
                            });
                            adminsstring.push('</p>');
                        }
                        mw.notify($(adminsstring.join('')));
                    } else {
                        mw.notify('Sorry! There are no IA online');
                    }
                }).fail(function () {
                    mw.notify('Error 404');
                });
            });
        });
    });