User:GeneralNotability/edit-filter-hit-analyzer.js

//

// @ts-check

// More information on how an edit filter was tripped

importStylesheet('w:en:User:GeneralNotability/edit-filter-hit-analyzer.css' );

/**

* @typedef EditFilterLine

* @type {Object}

* @property {string} text Text of the line

* @property {string} normedText Text with some modifications applied for parsing

* @property {string[]} variables Variables found in the line

* @property {number} indentation how far to indent the line

*/

const efa_knownVars = {};

const efa_PAGE_NAME_RE = /Special:AbuseLog\/\d+/;

const efa_FILTER_PAGE_RE = /\/wiki\/(Special:AbuseFilter\/(\d+))/;

// Vars in this list shouldn't have their full content displayed because they're usually really big

const efa_HIDDEN_VARS = [ 'old_wikitext', 'new_wikitext', 'edit_diff', 'all_links', 'added_lines', 'removed_lines', 'new_html' ];

// Parser regexes

const efa_REGEX_ASSIGNMENT_RE = /(\w+)\s*:=\s*"(.*)"/;

const efa_RLIKE_RE = /\b(.*)\s*(i?rlike|regex)\s*(\w+|".*")/;

// Future reference: if we want to do ccnorm ourselves, we can pull the conversion list

// from https://phab.wmfusercontent.org/file/data/jcoued3dziiwwwdr53lp/PHID-FILE-lkxia6juxnhqt263dbrj/equivset.json

async function efa_main() {

// populate knownVars with built-in values

Object.entries(mw.config.get('wgAbuseFilterVariables')).forEach(([ key, value ]) => {

efa_knownVars[key] = value;

});

const $actionParams = $('h3:contains("Action parameters")', document);

$('

').text('Filter rule analysis').insertBefore($actionParams);

const $ruleAnchor = $('