|
1 | 1 | import { CHROME_SYNC_STORAGE_THEME_KEY, getStorage } from "../common/storage"; |
2 | | -import { THEMES } from "../common/themes"; |
| 2 | +import { CLASSNAMES, THEMES } from "../common/themes"; |
3 | 3 |
|
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 | +}; |
7 | 22 |
|
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); |
20 | 31 |
|
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]); |
30 | 34 |
|
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); |
33 | 44 | } catch { |
34 | 45 | clearInterval(intervalId); |
35 | 46 | console.info( |
|
0 commit comments