User:Username/BlockAbuser.js: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
Let me just test this out |
edit |
||
| Line 1: | Line 1: | ||
mw.loader.using( [ |
mw.loader.using( [ 'mediawiki.util' ] ).then( function () { |
||
// Only run on Special:AbuseFilter |
|||
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) !== ' |
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) !== 'AbuseFilter' ) { |
||
return; |
return; |
||
} |
} |
||
const |
const seenUsers = new Set(); |
||
| ⚫ | |||
// Very strict IPv4 / IPv6 detection |
|||
| ⚫ | |||
const ipRegex = /^(?:\d{1,3}\.){3}\d{1,3}$|:/; |
|||
.text( 'Generate spambot block summary' ) |
|||
| ⚫ | |||
| ⚫ | |||
padding: '6px 10px', |
|||
| ⚫ | |||
| ⚫ | |||
// Find all links inside the abuse log table/content |
|||
$content.prepend( $btn ); |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
if ( !href || !text ) { |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
const params = new URLSearchParams( window.location.search ); |
|||
if ( !href.includes( '/wiki/User:' ) ) { |
|||
| ⚫ | |||
alert( 'Open Special:AbuseLog filtered to a single user first.' ); |
|||
return; |
return; |
||
} |
} |
||
const username = decodeURIComponent( |
|||
// 1 |
href.split( '/wiki/User:' )[1] |
||
| ⚫ | |||
| ⚫ | |||
action: 'query', |
|||
list: 'users', |
|||
ususers: username, |
|||
usprop: 'editcount' |
|||
| ⚫ | |||
| ⚫ | |||
const user = userInfo.query.users[0]; |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
// Only one checkbox per user |
|||
| ⚫ | |||
alert( 'This account has edits. Script only applies to 0-edit accounts.' ); |
|||
return; |
|||
} |
|||
seenUsers.add( username ); |
|||
// Create checkbox |
|||
const $checkbox = $( '<input>' ) |
|||
| ⚫ | |||
type: 'checkbox', |
|||
'data-username': username |
|||
} ) |
|||
.css( { |
|||
marginRight: '4px', |
|||
verticalAlign: 'middle' |
|||
} ); |
} ); |
||
// Insert checkbox before the username link |
|||
const logs = abuseData.query.abuselog; |
|||
$link.before( $checkbox ); |
|||
| ⚫ | |||
if ( !logs.length ) { |
|||
alert( 'No recent AbuseFilter hits found.' ); |
|||
return; |
|||
| ⚫ | |||
const mostRecent = logs[0]; |
|||
| ⚫ | |||
let summary = |
|||
'Spambot or spam-only account. The following cites the action they committed ' + |
|||
'[[Special:AbuseLog/' + mostRecent.id + ']]'; |
|||
| ⚫ | |||
summary += |
|||
' (+[[Special:AbuseLog/' + username + '|' + extraHits + ']])'; |
|||
} |
|||
// 3. Display output |
|||
mw.notify( |
|||
$( '<pre>' ).text( summary ), |
|||
{ autoHide: false } |
|||
| ⚫ | |||
} catch ( e ) { |
|||
console.error( e ); |
|||
alert( 'Failed to generate summary. See console.' ); |
|||
| ⚫ | |||
| ⚫ | |||
} ); |
} ); |
||
Revision as of 02:10, 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;
}
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 );
} );
} );