import { makeSaveAllVisibleComments } from './makeSaveAllVisibleComments' ; export const watchForNewComments = async ( ) => { const myProfile = document . querySelector < HTMLAnchorElement > ( 'a.my-profile' ) ; if ( ! myProfile ) { return ; } const userHref = myProfile . href ; const saveAllVisibleComments = makeSaveAllVisibleComments ( userHref ) ; await saveAllVisibleComments ( ) ; const ulsBeingObserved = new Set < HTMLUListElement > ( ) ; const attachObserverToUL = ( ul ) => { if ( ulsBeingObserved . has ( ul ) ) { return ; } ulsBeingObserved . add ( ul ) ; new MutationObserver ( saveAllVisibleComments ) . observe ( ul , { childList : true } ) ; } ; const attachObserverToAllULs = ( ) => { document . querySelectorAll < HTMLUListElement > ( 'ul.comments-list' ) . forEach ( attachObserverToUL ) ; } ; attachObserverToAllULs ( ) ; window . $ ( document ) . ajaxComplete ( attachObserverToAllULs ) ; } ;