(hiddenCommentHeader: HTMLElement)
| 9 | import observe from '../helpers/selector-observer.js'; |
| 10 | |
| 11 | function preview(hiddenCommentHeader: HTMLElement): void { |
| 12 | const details = closestElement('details', hiddenCommentHeader); |
| 13 | details.classList.add('rgh-preview-hidden-comments'); // Used in CSS |
| 14 | |
| 15 | const comment = $('.comment-body', details); |
| 16 | const commentText = comment.textContent.trim(); |
| 17 | if (commentText.length === 0) { |
| 18 | return; |
| 19 | } |
| 20 | |
| 21 | const commentHeader = hiddenCommentHeader.textContent; |
| 22 | if (/disruptive|spam/.test(commentHeader)) { |
| 23 | return; |
| 24 | } |
| 25 | |
| 26 | // The reason is missing/lost in some cases |
| 27 | const reason = /duplicate|outdated|off-topic|hidden/.exec(commentHeader)?.[0]; |
| 28 | hiddenCommentHeader.classList.add('css-truncate', 'css-truncate-overflow', 'mr-2'); |
| 29 | hiddenCommentHeader.append( |
| 30 | <span className="Details-content--open">{hiddenCommentHeader.firstChild}</span>, |
| 31 | <span className="Details-content--closed"> |
| 32 | {reason && <span className="Label mr-2 tmp-mr-2">{upperCaseFirst(reason)}</span>} |
| 33 | {commentText.slice(0, 100)} |
| 34 | </span>, |
| 35 | ); |
| 36 | } |
| 37 | |
| 38 | function init(signal: AbortSignal): void { |
| 39 | // `.timeline-comment-group` excludes review comments, which are always loaded on click, so it's not possible to preview them |
nothing calls this directly
no test coverage detected