// <nowiki>
// Wait for page load
$( function($) {
var mwconfig = mw.config.get(['wgCanonicalSpecialPageName', 'wgServer', 'wgUserName']);
// Only for Watchlist, Recent changes, Related changes
if( !/(?:Watchlist|Recentchanges(?:linked)?)/.test(mwconfig.wgCanonicalSpecialPageName) ) {
return;
}
// Load dependencies
mw.loader.using( ['mediawiki.util'], function() {
jQuery.ajax({
dataType: 'script',
cache: false,
url: 'https:' + mwconfig.wgServer + mw.util.getUrl(
'User:' + mwconfig.wgUserName + '/WatchlistFilters.js',
{action:'raw', ctype:'text/javascript'})
}).then( function() {
// Get filters
var filters = window.watchlistFilters;
if ( filters == null ) {
mw.notify( 'Warning: custom filters not found' );
return;
} else if ( !$.isArray(filters) ) {
mw.notify( 'Warning: custom filters could not be parsed' );
return;
}
// Add a class to list items with edit summary text matching the regex filters
$('span.comment').each(function() {
for ( var i=0; i<filters.length; i++ ) {
if ( $(this).text().match(filters[i]) ) {
$(this).closest('li, tr').addClass('watchlist-customHide');
}
}
});
// Add show/hide portlets
mw.util.addPortletLink( 'p-cactions', '#', 'Hide filtered', 'ca-customFilterHide', "Hide edits matching custom filters");
mw.util.addPortletLink( 'p-cactions', '#', 'Show filtered', 'ca-customFilterShow', "Show edits matching custom filters");
// Hide the edits
$('#ca-customFilterHide').on('click', function() {
$("#ca-customFilterHide, .watchlist-customHide").hide();
$('#ca-customFilterShow').show();
});
// Show the edits
$('#ca-customFilterShow').on('click', function() {
$("#ca-customFilterHide, .watchlist-customHide").show();
$('#ca-customFilterShow').hide();
});
// Edits hidden by default
$('#ca-customFilterHide, .watchlist-customHide').hide();
});
});
});
// </nowiki>