import { saveDeletedComment } from './saveDeletedComment' ; export const watchForSelfDeletedComments = ( ) => { const responseJSONHasSuccessProp = ( responseJSON ) : responseJSON is { Success : unknown ; } => 'Success' in responseJSON ; window . $ ( document ) . ajaxComplete ( ( _ , jqXHR , ajaxOptions ) => { if ( ! ajaxOptions || ! ajaxOptions . url ) { return ; } const commentIdMatch = ajaxOptions . url . match ( /^\/posts\/comments\/(\d+)\/vote\/10$/ ) ; if ( ! commentIdMatch ) { return ; } const deletedCommentId = Number ( commentIdMatch [ 1 ] ) ; const responseJSON = jqXHR . responseJSON as unknown ; if ( typeof responseJSON !== 'object' || responseJSON === null ) { return ; } if ( responseJSONHasSuccessProp ( responseJSON ) && responseJSON . Success === true ) { window . setTimeout ( saveDeletedComment , 0 , deletedCommentId ) ; } } ) ; } ;