User:DannyS712 test/filters.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | Documentation for this user script can be added at User:DannyS712 test/filters. |
// Install with:
// <code><nowiki> {{subst:Iusc|User:DannyS712/Filter links.js}} </nowiki></code>
// or with
// <code><nowiki> importScript( 'User:DannyS712/Filter links.js' ); // Backlink: [[User:DannyS712/Filter links.js]] </nowiki></code>
//
// If forking this script, please note my contributions / give me credit
//<nowiki>
$(function() {
var FL_config = {
name: '[[User:DannyS712/Filter links|Filter links.js]]',
version: 1.2,
debug: true
};
mw.loader.using( 'mediawiki.util', function () {
$(document).ready( function () {
var page = mw.config.get('wgPageName');
if (page && page === 'Special:AbuseLog'){
FilterLinks();
}
} );
} );
function FilterLinks(){
var filters = get_filters(1);
var entries = $('li');
var description, filter_id;
if (FL_config.debug) console.log( entries );
entries.each( function() {
if (this.innerHTML.indexOf('triggered an edit filter') > -1){
if (FL_config.debug) console.log( this.innerText );
description = this.innerText.replace(/.*?Filter description: /, '');
description = description.replace(/ \(diff\)/, '');
if (FL_config.debug) console.log( description );
for (var iii = 0; iii < filters.length; iii++){
if (description === filters[iii].description){
filter_id = filters[iii].id;
if (FL_config.debug) console.log( filters[iii]);
this.innerHTML = this.innerHTML.replace(/triggered an edit filter/, 'triggered <a href="/wiki/Special:AbuseFilter/' + filter_id + '" title="Special:AbuseFilter/' + filter_id + '">private filter ' + filter_id + '</a>');
}
}
}
});
}
function get_filters( start ){
var scriptUrl = mw.config.get( 'wgScriptPath' ) + '/api.php';
var getter = {
action: 'query',
list: 'abusefilters',
abfshow: 'private',
abflimit: 'max',
abfprop: 'id|description',
abfstartid: start,
format: 'json',
formatversion: 2
};
var result = null;
$.ajax({
url: scriptUrl,
type: 'get',
data: getter,
dataType: 'json',
async: false,
success: function( response ) {
if (FL_config.debug) console.log( response );
result = response.query.abusefilters;
if (response.continue){
result = result.concat( get_filters( response.continue.abfstartid) );
}
if (FL_config.debug) console.log( result );
}
});
return result;
}
});
//</nowiki>