Skip to content

Commit 9ec327e

Browse files
committed
Remove highlight from replied comments
1 parent 87f340f commit 9ec327e

3 files changed

Lines changed: 45 additions & 28 deletions

File tree

src/background/index.js

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,46 @@
11
import { CHROME_SYNC_STORAGE_THEME_KEY, getStorage } from "../common/storage";
2-
import { THEMES } from "../common/themes";
2+
import { CLASSNAMES, THEMES } from "../common/themes";
33

4-
const intervalId = setInterval(async function () {
5-
try {
6-
const selectedTheme = await getStorage(CHROME_SYNC_STORAGE_THEME_KEY);
4+
const removeClassnames = (parent) => {
5+
parent.classList.remove(
6+
CLASSNAMES[THEMES.leftBorder],
7+
CLASSNAMES[THEMES.pulsating],
8+
CLASSNAMES[THEMES.backgroundColor]
9+
);
10+
};
11+
12+
const removeHighlightFromRepliedComments = () => {
13+
Array.from(document.querySelectorAll(".js-comments-holder"))
14+
.filter((parent) => {
15+
const commentDivs = parent.querySelectorAll(".js-comment");
16+
return commentDivs.length > 1;
17+
})
18+
.forEach((parent) => {
19+
removeClassnames(parent);
20+
});
21+
};
722

8-
Array.from(document.querySelectorAll(".js-comments-holder"))
9-
.filter((parent) => {
10-
const commentDivs = parent.querySelectorAll(".js-comment");
11-
return commentDivs.length === 1;
12-
})
13-
.forEach((parent) => {
14-
const themeClassnames = ["github-unreplied-comments"];
15-
parent.classList.remove(
16-
"github-unreplied-comments-leftBorder-theme",
17-
"github-unreplied-comments-pulsating-theme",
18-
"github-unreplied-comments-backgroundcolor-theme"
19-
);
23+
const addHighlightToUnrepliedComments = (selectedTheme) => {
24+
Array.from(document.querySelectorAll(".js-comments-holder"))
25+
.filter((parent) => {
26+
const commentDivs = parent.querySelectorAll(".js-comment");
27+
return commentDivs.length === 1;
28+
})
29+
.forEach((parent) => {
30+
removeClassnames(parent);
2031

21-
if (selectedTheme === THEMES.leftBorder) {
22-
themeClassnames.push("github-unreplied-comments-leftBorder-theme");
23-
} else if (selectedTheme === THEMES.pulsating) {
24-
themeClassnames.push("github-unreplied-comments-pulsating-theme");
25-
} else if (selectedTheme === THEMES.backgroundColor) {
26-
themeClassnames.push(
27-
"github-unreplied-comments-backgroundcolor-theme"
28-
);
29-
}
32+
const themeClassnames = ["github-unreplied-comments"];
33+
themeClassnames.push(CLASSNAMES[selectedTheme]);
3034

31-
parent.classList.add(...themeClassnames);
32-
});
35+
parent.classList.add(...themeClassnames);
36+
});
37+
};
38+
39+
const intervalId = setInterval(async function () {
40+
try {
41+
const selectedTheme = await getStorage(CHROME_SYNC_STORAGE_THEME_KEY);
42+
removeHighlightFromRepliedComments();
43+
addHighlightToUnrepliedComments(selectedTheme);
3344
} catch {
3445
clearInterval(intervalId);
3546
console.info(

src/common/themes.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@ export const THEMES = {
33
leftBorder: "leftBorder",
44
pulsating: "pulsating",
55
};
6+
7+
export const CLASSNAMES = {
8+
[THEMES.backgroundColor]: "github-unreplied-comments-backgroundcolor-theme",
9+
[THEMES.leftBorder]: "github-unreplied-comments-leftBorder-theme",
10+
[THEMES.pulsating]: "github-unreplied-comments-pulsating-theme",
11+
};

src/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"manifest_version": 3,
33
"name": "GitHub Unreplied Comments Indicator",
44
"description": "Highlights GitHub pull request comments with no replies, helping you spot unresolved feedback instantly.",
5-
"version": "0.0.1",
5+
"version": "0.0.2",
66
"author": "Clyde D'Souza",
77
"homepage_url": "https://github.com/ClydeDz/github-unreplied-comments-indicator-chrome-extension",
88
"icons": {

0 commit comments

Comments
 (0)