Skip to content

Commit ee9375a

Browse files
fregantesindresorhus
authored andcommitted
Hide useless comments (#1526)
Closes #1478
1 parent d2079bd commit ee9375a

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

readme.md

+1
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ GitHub Enterprise is also supported. More info in the options.
148148
* New projects can still be created via the [`Create new…` menu](https://user-images.githubusercontent.com/1402241/34909214-18b6fb2e-f8cf-11e7-8556-bed748596d3b.png).
149149
- [The autocomplete on the issue search field is removed.](https://user-images.githubusercontent.com/1402241/42991841-1f057e4e-8c07-11e8-909c-b051db7a2a03.png)
150150
- [Forks are hidden from a user's Repositories list (but they can still be shown)](https://user-images.githubusercontent.com/1402241/45133648-fe21be80-b1c8-11e8-9052-e38cb443efa9.png)
151+
- [Reaction comments ("+1", "👍", …) are hidden](https://user-images.githubusercontent.com/1402241/45543717-d45f3c00-b847-11e8-84a5-8c439d0ad1a5.png) (except the maintainers') [but they can still be shown.](https://user-images.githubusercontent.com/1402241/45543720-d628ff80-b847-11e8-9fb6-758a3102e3a9.png)
151152

152153
### UI improvements
153154

source/content.css

+10
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,16 @@ body > .footer li a {
962962
font-size: 13px;
963963
}
964964

965+
/* For 'hide-useless-comments' feature */
966+
.rgh-useless-comments-note {
967+
margin: 15px 0 10px 60px;
968+
font-size: 12px;
969+
color: #586069;
970+
}
971+
.rgh-hidden-comment .timeline-comment {
972+
border-color: var(--github-red);
973+
}
974+
965975
/* For 'improve-shortcut-help' feature */
966976
:root .facebox .shortcuts {
967977
width: 908px;

source/content.js

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import addMilestoneNavigation from './features/add-milestone-navigation';
4646
import addFilterCommentsByYou from './features/add-filter-comments-by-you';
4747
import addFilterNotReviewedByYou from './features/add-filter-not-reviewed-by-you';
4848
import removeProjectsTab from './features/remove-projects-tab';
49+
import hideUselessComments from './features/hide-useless-comments';
4950
import fixSquashAndMergeTitle from './features/fix-squash-and-merge-title';
5051
import fixSquashAndMergeMessage from './features/fix-squash-and-merge-message';
5152
import addTitleToEmojis from './features/add-title-to-emojis';
@@ -193,6 +194,7 @@ function ajaxedPagesHandler() {
193194
enableFeature(addDownloadFolderButton);
194195
enableFeature(linkifyBranchRefs);
195196
enableFeature(openAllSelected);
197+
enableFeature(hideUselessComments);
196198

197199
if (pageDetect.isIssueSearch() || pageDetect.isPRSearch()) {
198200
enableFeature(addYoursMenuItem);
+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import {h} from 'dom-chef';
2+
import select from 'select-dom';
3+
import * as pageDetect from '../libs/page-detect';
4+
5+
export default function () {
6+
if (!pageDetect.isIssue() && !pageDetect.isPR()) {
7+
return;
8+
}
9+
10+
let uselessCount = 0;
11+
for (const commentText of select.all('.comment-body > p:only-child')) {
12+
// Find useless comments
13+
if (!/^([+-]\d+!*|👍|🙏|👎|👌)+$/.test(commentText.textContent.trim())) {
14+
continue;
15+
}
16+
17+
// Ensure that they're not by VIPs (owner, collaborators, etc)
18+
const comment = commentText.closest('.js-timeline-item');
19+
if (select.exists('.timeline-comment-label', comment)) {
20+
continue;
21+
}
22+
23+
// If the person is having a conversation, then don't hide it
24+
const author = select('.author', comment).getAttribute('href');
25+
// If the first comment left by the author isn't a useless comment
26+
// (previously hidden or about to be hidden), then leave this one as well
27+
const previousComment = select(`.js-timeline-item:not([hidden]) .unminimized-comment .author[href="${author}"]`);
28+
if (previousComment && previousComment.closest('.js-timeline-item') !== comment) {
29+
continue;
30+
}
31+
32+
comment.hidden = true;
33+
comment.classList.add('rgh-hidden-comment');
34+
uselessCount++;
35+
}
36+
37+
if (uselessCount > 0) {
38+
select('.discussion-timeline-actions').prepend(
39+
<p class="rgh-useless-comments-note">
40+
{`${uselessCount} useless comment${uselessCount > 1 ? 's were' : ' was'} hidden. `}
41+
<button class="btn-link text-emphasized" onClick={unhide}>Undo</button>
42+
</p>
43+
);
44+
}
45+
}
46+
47+
function unhide(event) {
48+
for (const comment of select.all('.rgh-hidden-comment')) {
49+
comment.hidden = false;
50+
}
51+
select('.rgh-hidden-comment').scrollIntoView();
52+
event.target.parentElement.remove();
53+
}

0 commit comments

Comments
 (0)