Jump to content

User:Technical 13/Scripts/ACCHelp/Creation log.js

From Wikipedia, the free encyclopedia
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.
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Log' && $( 'h1#firstHeading' ).text() === 'User creation log' ) {
    var mwUser = mw.config.get( 'wgUserName' );
    if ( $( 'p:contains( "No matching items in log." )' ).html() !== undefined ) {
        $( 'p:contains( "No matching items in log." )' ).addClass( 'error' );
        $( 'h1#firstHeading' ).html( tickGood + ' ' + $( 'h1#firstHeading' ).html() );
        document.title = Ucheck + document.title;
    } else {
        var limit = 0;
        if ( document.location.href.search( '&limit=' ) !== -1 ) {
            limit = parseInt( document.location.href.substr( document.location.href.search( '&limit=' ) + 7 ), 10 );
        }
        if ( $( 'p:contains( "No matching items in log." )' ).html() === undefined && $( 'input#mw-log-page' ).val().substr( 5 ) !== '' && limit === 1 ) {
            $( 'h1#firstHeading' ).html(tickBad + ' ' + $( 'h1#firstHeading' ).html() );
            document.title = Ucheck + document.title;
            alert( 'WARNING!\n\t\tThere is a local account for:\n\n\t\t' + $( 'input#mw-log-page' ).val().substr( 5 ).replace( '_', ' ' ));
        }
        else if ( $( 'input#mw-log-user' ).val().replace( '_', ' ' ) === mwUser && limit !== 1000 ) {
            setTimeout(function() { location += '&limit=1000'; }, 1 );
        }
        else if ( $( 'input#mw-log-user' ).val().replace( '_', ' ' ) === mwUser ) {
            $( 'li.mw-logline-newusers' ).closest( 'ul' ).replaceWith( '<ol reverse="reverse">\n' + $( 'li.mw-logline-newusers' ).closest( 'ul' ).html() + '\n</ol>' );
//            $( 'li.mw-logline-newusers' ).css( 'list-style-image', '/* none */' );
//            $( 'li.mw-logline-newusers' ).css( 'list-style-type', 'decimal' );
            $( 'li.mw-logline-newusers' ).each( function() {
                $( this ).html( $( this ).html().replace( ' by <a href="/wiki/User:' + mwUser.replace( ' ', '_' ) + '" title="User:' + mwUser + '" class="mw-userlink">' + mwUser + '</a> <span class="mw-usertoollinks">(<a href="/wiki/User_talk:' + mwUser.replace( ' ', '_' ) + '" title="User talk:' + mwUser + '">talk</a>&nbsp;| <a href="/wiki/Special:Contributions/' + mwUser.replace( ' ', '_' ) + '" title="Special:Contributions/' + mwUser + '">contribs</a>)</span>', '' ) );
            } );
        }
        $( 'li.mw-logline-newusers' ).find( 'span.comment' ).each( function() {
            if ( parseInt( $( this ).html().lastIndexOf( 'WP:ACC</a>' ), 10 ) !== -1 ) {
                var ACC = $( this ).html().substr( ( parseInt( $( this ).html().lastIndexOf( '#' ), 10 ) + 1 ), ( parseInt( $( this ).html().match( /#[\d]*/ )[ 0 ].length, 10 ) - 1 ) );// ACC zoom number
                $( this ).html( $( this ).html().replace( 'Requested account at <a href="/wiki/Wikipedia:ACC" class="mw-redirect" title="Wikipedia:ACC">WP:ACC</a>, request #' + ACC, '<a href="/wiki/Wikipedia:Request an account" class="mw-redirect" title="Wikipedia:Request an account">ACC</a> request <a href="//accounts.wmflabs.org/acc.php?action=zoom&id=' + ACC + '" title="Account Creation Interface\n\tRequest: #' + ACC + '">#' + ACC + '</a>' ) );
            }
        } );
        $( 'span.mw-usertoollinks' ).each( function( i ) {
            var thisUser = $( this ).prev( 'a' ).text();
            var thisUserToolLinks = '';
            var thisUserInfo = { groups: [ ], blocked: { isBlocked: false } };
            new mw.Api().get( {
                action: 'query',
                list: 'users',
                usprop: [ 'blockinfo', 'groups', 'editcount', 'emailable', 'gender' ],
                ususers: encodeURIComponent( thisUser ),
                continue: ''
            } ).done( function( userInfoQuery ) {
                /* Create an object with all the data for the current user */
                thisUserInfo.editCount = userInfoQuery.query.users[ 0 ].editcount;
                thisUserInfo.groups = userInfoQuery.query.users[ 0 ].groups;
                if ( userInfoQuery.query.users[ 0 ].blockid ) {
                    thisUserInfo.blocked.isBlocked = true;
                    thisUserInfo.blocked.isBlockedBy = userInfoQuery.query.users[ 0 ].blockedby;
                    thisUserInfo.blocked.isBlockedTimestamp = userInfoQuery.query.users[ 0 ].blockedtimestamp;
                    thisUserInfo.blocked.isBlockedReason = userInfoQuery.query.users[ 0 ].blockreason;
                    thisUserInfo.blocked.isBlockedExpiry = userInfoQuery.query.users[ 0 ].blockexpiry;
                }
                thisUserInfo.gender = userInfoQuery.query.users[ 0 ].gender;
                thisUserInfo.emailable = ( userInfoQuery.query.users[ 0 ].emailable === undefined ) ? false : true;
                
                /* Create the replacement text */
                var thisUserTalk = '<a href="//en.wikipedia.org/wiki/User_talk:' + encodeURIComponent( thisUser ) + '" title="leave a message on ' + thisUser + '\'s talk page"';
                if( $( this ).find( 'span.mw-usertoollinks a.new:first' ) ) {
                    thisUserTalk += ' class"new"';
                }
                thisUserTalk += '>t</a>';
                var thisUserEmail = '';
                if ( thisUserInfo.emailable ) {
                    thisUserEmail = '&thinsp;|&thinsp;<a href="//en.wikipedia.org/wiki/Special:EmailUser/' + encodeURIComponent( thisUser ) + '" title="send ' + thisUser + ' an email">e</a>';
                }
                var thisUserContribClass = '';
                if ( thisUserInfo.editCount <= 0 ){
                    thisUserContribClass = 'class="new"';
                } else if ( thisUserInfo.editCount === 'NaN' ) {
                    thisUserContribClass = 'class="new error"';
                }
                var thisUserContribs = '&thinsp;|&thinsp;<a' + thisUserContribClass + ' href="//en.wikipedia.org/wiki/Special:Contributions/' + encodeURIComponent( thisUser ) + '" title="view all contributions for ' + thisUser + '">' + thisUserInfo.editCount + '</a>';
                var thisUserLogs = '&thinsp;|&thinsp;<a href="//en.wikipedia.org/wiki/Special:Logs/' + encodeURIComponent( thisUser ) + '" title="view all logs for ' + thisUser + '">l</a>';
                var thisUserWel = '&thinsp;|&thinsp;<a href="#" title="send ' + thisUser + ' a welcome to the English Wikipedia">wel</a>';
                var thisUserTH = '&thinsp;|&thinsp;<a href="#" title="send ' + thisUser + ' an invitation to the Teahouse">th</a>';
                var thisUserBlocked = '';
                if( thisUserInfo.blocked.isBlocked === false ){
                    var thisUserSPI = '&thinsp;|&thinsp;<a href="#" title="report ' + thisUser + ' to SPI">SPI</a>';
                    var thisUserAIV = '&thinsp;|&thinsp;<a href="#" title="report ' + thisUser + ' to AIV">AIV</a>';
                    var thisUserUAA = '&thinsp;|&thinsp;<a href="#" title="report ' + thisUser + ' to UAA">UAA</a>';
                    thisUserBlocked = thisUserSPI + thisUserAIV + thisUserUAA;
                } else {
                    thisUserBlocked = '&thinsp;|&thinsp;<a href="" class="error" style="font-variant: small-caps;" title="' + thisUser + ' was bad.  ' + thisUserInfo.gender.replace( 'male', 'He was' ).replace( 'female', 'She was' ).replace( 'unspecified', 'They were' ) + ' blocked for ' + thisUserInfo.blocked.isBlockedExpiry.replace( 'infinity', 'forever' ) + ' by ' + thisUserInfo.blocked.isBlockedBy + ' with a reason of:\n\t' + thisUserInfo.blocked.isBlockedReason + '">Blocked</a>';
                }
                thisUserToolLinks = '<span class="mw-usertoollinks" style="font-family: monospace;">(&thinsp;' + thisUserTalk + thisUserEmail + thisUserContribs + thisUserLogs/* +  thisUserWel + thisUserTH*/ + thisUserBlocked + '&thinsp;)</span>';
                
                /* Apply the replacement text */
                $( 'span.mw-usertoollinks' ).eq( i ).replaceWith( thisUserToolLinks );
            } );
        } );
    }
}