import { commentHrefToIds } from '../commentHrefToIds' ; returns export const saveComment = ( userCommentAnchor , savedComments ) => { const commentBody = userCommentAnchor . closest ( '.comment-body' ) ! ; const dateElm = commentBody . querySelector < HTMLElement > ( '.relativetime-clean' ) ! ; const timestamp = new Date ( dateElm . title . match ( /^[^,]+?(?= ?, License)/ ) ! [ 0 ] ) . getTime ( ) ; const commentHTML = commentBody . querySelector ( '.comment-copy' ) ! . innerHTML ; const questionAnchor = document . querySelector ( '#question-header > h1 > a' ) ; if ( ! questionAnchor ) { return false ; } const questionTitle = questionAnchor . textContent ! ; const commentHrefAttrib = commentBody . querySelector ( 'a.comment-link' ) ! . getAttribute ( 'href' ) ! ; const commentHref = window . location . origin + window . location . pathname + commentHrefAttrib ; const { commentId } = commentHrefToIds ( commentHref ) ; const newCommentObj = { commentHTML , commentHref , questionTitle , timestamp , } ; if ( JSON . stringify ( newCommentObj ) !== JSON . stringify ( savedComments [ commentId ] ) ) { savedComments [ commentId ] = newCommentObj ; return true ; } return false ; } ;