User:MSchottlender-WMF/GadgetEchoMarkAllRead.js

From mediawiki.org

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/**
 * Experimental! This gadget will mark all notifications as read when the popup opens.
 * Currently set to only mark 'alerts' as read.
 * 
 * Depends on merging and deploying https://gerrit.wikimedia.org/r/#/c/312940/
 */
$(function () {
	mw.hook( 'ext.echo.popup.onInitialize' ).add( function ( type, controller ) {
		if ( type === 'alert' ) {
			// If you copy this gadget, please keep this on; if errors occur, it is useful to see when and
			// how the gadget ran on the popup
			window.console.log( 'Gadget running: Marking all notifications of type "' + type + '" as read.' );

			// Add pending animation for consistency
			$( '#pt-notifications-alert .oo-ui-popupWidget-head' ).addClass( 'oo-ui-pendingElement-pending' );
			controller.markAllRead( 'local' )
				.always( function () {
					// Remove pending aninmation
					$( '#pt-notifications-alert .oo-ui-popupWidget-head' ).removeClass( 'oo-ui-pendingElement-pending' );
				} );
		}
	} );
} );