summaryrefslogtreecommitdiff
path: root/source/features/hide-low-quality-comments.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'source/features/hide-low-quality-comments.tsx')
-rw-r--r--source/features/hide-low-quality-comments.tsx26
1 files changed, 13 insertions, 13 deletions
diff --git a/source/features/hide-low-quality-comments.tsx b/source/features/hide-low-quality-comments.tsx
index 43d1ad0b..5271c3ee 100644
--- a/source/features/hide-low-quality-comments.tsx
+++ b/source/features/hide-low-quality-comments.tsx
@@ -1,7 +1,7 @@
import './hide-low-quality-comments.css';
import delay from 'delay';
import React from 'dom-chef';
-import select from 'select-dom';
+import {$, $$, elementExists} from 'select-dom';
import * as pageDetect from 'github-url-detection';
import delegate, {DelegateEvent} from 'delegate-it';
@@ -11,18 +11,18 @@ import isLowQualityComment from '../helpers/is-low-quality-comment.js';
export const singleParagraphCommentSelector = '.comment-body > p:only-child';
async function unhide(event: DelegateEvent): Promise<void> {
- for (const comment of select.all('.rgh-hidden-comment')) {
+ for (const comment of $$('.rgh-hidden-comment')) {
comment.hidden = false;
}
await delay(10); // "Similar comments" aren't expanded without this in Safari #3830
// Expand all "similar comments" boxes
- for (const similarCommentsExpandButton of select.all('.rgh-hidden-comment > summary')) {
+ for (const similarCommentsExpandButton of $$('.rgh-hidden-comment > summary')) {
similarCommentsExpandButton.click();
}
- select('.rgh-hidden-comment')!.scrollIntoView();
+ $('.rgh-hidden-comment')!.scrollIntoView();
event.delegateTarget.parentElement!.remove();
}
@@ -32,13 +32,13 @@ function hideComment(comment: HTMLElement): void {
}
function init(): void {
- for (const similarCommentsBox of select.all('.js-discussion .Details-element:not([data-body-version])')) {
+ for (const similarCommentsBox of $$('.js-discussion .Details-element:not([data-body-version])')) {
hideComment(similarCommentsBox);
}
- const linkedComment = location.hash.startsWith('#issuecomment-') ? select(`${location.hash} ${singleParagraphCommentSelector}`) : undefined;
+ const linkedComment = location.hash.startsWith('#issuecomment-') ? $(`${location.hash} ${singleParagraphCommentSelector}`) : undefined;
- for (const commentText of select.all(singleParagraphCommentSelector)) {
+ for (const commentText of $$(singleParagraphCommentSelector)) {
// Exclude explicitely linked comments #5363
if (commentText === linkedComment) {
continue;
@@ -51,22 +51,22 @@ function init(): void {
// Comments that contain useful images or links shouldn't be removed
// Images are wrapped in <a> tags on GitHub hence included in the selector
// TODO: use :has()
- if (select.exists('a', commentText)) {
+ if (elementExists('a', commentText)) {
continue;
}
// Ensure that they're not by VIPs (owner, collaborators, etc)
// TODO: use :has()
const comment = commentText.closest('.js-timeline-item')!;
- if (select.exists('.Label', comment)) {
+ if (elementExists('.Label', comment)) {
continue;
}
// If the person is having a conversation, then don't hide it
- const author = select('.author', comment)!.getAttribute('href')!;
+ const author = $('.author', comment)!.getAttribute('href')!;
// If the first comment left by the author isn't a low quality comment
// (previously hidden or about to be hidden), then leave this one as well
- const previousComment = select(`.js-timeline-item:not([hidden]) .unminimized-comment .author[href="${author}"]`);
+ const previousComment = $(`.js-timeline-item:not([hidden]) .unminimized-comment .author[href="${author}"]`);
if (previousComment?.closest('.js-timeline-item') !== comment) {
continue;
}
@@ -74,9 +74,9 @@ function init(): void {
hideComment(comment);
}
- const lowQualityCount = select.all('.rgh-hidden-comment').length;
+ const lowQualityCount = $$('.rgh-hidden-comment').length;
if (lowQualityCount > 0) {
- select('.discussion-timeline-actions')!.prepend(
+ $('.discussion-timeline-actions')!.prepend(
<p className="rgh-low-quality-comments-note">
{`${lowQualityCount} unhelpful comment${lowQualityCount > 1 ? 's were' : ' was'} automatically hidden. `}
<button className="btn-link text-emphasized rgh-unhide-low-quality-comments" type="button">Show</button>