Jump to content

User:Enterprisey/mark-join-date.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Enterprisey (talk | contribs) at 03:17, 15 August 2018 (magic number was wrong). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
$( function() {
    if( mw.config.get( "wgPageName" ).indexOf( "Wikipedia:Sockpuppet_investigations/" ) >= 0 ) {
        var allLinks = Array.from( document.querySelectorAll( "a[href^='//en.wikipedia.org/wiki/User:'].external" ) );
        var CHUNK_SIZE = 10;
        for( var i = 0; i < allLinks.length; i += CHUNK_SIZE ) {
            fetchAndDisplayDates( allLinks.slice( i, i + CHUNK_SIZE ) );
        }

        // Make an API call to fetch all registration dates for users in this chunk
        function fetchAndDisplayDates( links ) {

            // Make the "ususers" parameter for the query;
            // must be pipe-separated URL-encoded usernames
            var usersParam = links.map( function ( link ) {
                    return encodeURIComponent( link.href.substr( 35 ) ); } )
                .join( "|" );

            // Perform query
            ( new mw.Api() ).get( {
                "list": "users",
                "ususers": usersParam,
                "usprop": "registration"
            } ).done( function ( res ) {
                console.log(res);
            } );
        }
    }
} );