User:Username/BlockAbuser.js: Difference between revisions

From Test Wiki
Jump to navigation Jump to search
Content deleted Content added
edit
No edit summary
Line 25: Line 25:
return;
return;
}
}

const username = decodeURIComponent(
href.split( '/wiki/User:' )[1]
).replace( /_/g, ' ' );

// Skip IPs
if ( ipRegex.test( username ) ) {
return;
}

// Only one checkbox per user
if ( seenUsers.has( username ) ) {
return;
}
seenUsers.add( username );

// Create checkbox
const $checkbox = $( '<input>' )
.attr( {
type: 'checkbox',
'data-username': username
} )
.css( {
marginRight: '4px',
verticalAlign: 'middle'
} );

// Insert checkbox before the username link
$link.before( $checkbox );
} );

} );

Revision as of 02:11, 21 January 2026

mw.loader.using( [ 'mediawiki.util' ] ).then( function () {

    // Only run on Special:AbuseFilter
    if ( mw.config.get( 'wgCanonicalSpecialPageName' ) !== 'AbuseFilter' ) {
        return;
    }

    const seenUsers = new Set();

    // Very strict IPv4 / IPv6 detection
    const ipRegex = /^(?:\d{1,3}\.){3}\d{1,3}$|:/;

    // Find all links inside the abuse log table/content
    $( '#mw-content-text a' ).each( function () {
        const $link = $( this );
        const href = $link.attr( 'href' );
        const text = $link.text();

        if ( !href || !text ) {
            return;
        }

        // Only User: links
        if ( !href.includes( '/wiki/User:' ) ) {
            return;
        }