User:Mmullie (WMF)/MarkAllRead.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
var count = parseInt( $( '.mw-echo-notifications-badge' ).text() ),
	api = new mw.Api();

if ( count && confirm( 'Mark all notifications as read?' ) ) {
	api.postWithEditToken( mw.echo.desktop.appendUseLang( {
		'action' : 'echomarkread',
		'all' : true
	} ) ).done( function ( result ) {
		mw.echo.overlay.updateCount(
			result.query.echomarkread.count,
			result.query.echomarkread.rawcount
		);
		alert( 'All notifications marked as read' );
	} );
}