@@ -5,11 +5,12 @@ import { commentHrefToIds } from '../commentHrefToIds';
55 * @returns True if the database was changed, otherwise false
66 */
77export const saveComment = ( userCommentAnchor : HTMLAnchorElement , savedComments : SavedComments ) => {
8- const dateElm = userCommentAnchor . nextElementSibling ! . querySelector < HTMLElement > ( '.relativetime-clean' ) ! ;
8+ const commentBody = userCommentAnchor . closest ( '.comment-body' ) ! ;
9+ const dateElm = commentBody . querySelector < HTMLElement > ( '.relativetime-clean' ) ! ;
910 // The title will be something like: "2020-05-12 16:08:33Z , License: CC BY-SA 4.0"
1011 const timestamp = new Date ( dateElm . title . match ( / ^ [ ^ , ] + ?(? = ? , L i c e n s e ) / ) ! [ 0 ] ) . getTime ( ) ;
1112 // Some sites have a MathJax preview which is the first child of the body, rather than the comment-copy being the first child
12- const commentHTML = userCommentAnchor . closest ( '.comment-body' ) ! . querySelector ( '.comment-copy' ) ! . innerHTML ;
13+ const commentHTML = commentBody . querySelector ( '.comment-copy' ) ! . innerHTML ;
1314 const questionAnchor = document . querySelector ( '#question-header > h1 > a' ) ;
1415 if ( ! questionAnchor ) {
1516 // Spam/rude question - it's likely already in the database, just don't try to update it
@@ -18,7 +19,7 @@ export const saveComment = (userCommentAnchor: HTMLAnchorElement, savedComments:
1819 const questionTitle = questionAnchor . textContent ! ;
1920 // Cannot just use .href of the comment-link below,
2021 // because there may be a query string which comes between the /question-title and the #commentID_postID
21- const commentHrefAttrib = userCommentAnchor . parentElement ! . querySelector ( 'a.comment-link' ) ! . getAttribute ( 'href' ) ! ;
22+ const commentHrefAttrib = commentBody . querySelector ( 'a.comment-link' ) ! . getAttribute ( 'href' ) ! ;
2223 const commentHref = window . location . origin + window . location . pathname + commentHrefAttrib ;
2324 const { commentId } = commentHrefToIds ( commentHref ) ;
2425 const newCommentObj = {
0 commit comments