-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
addPRToHighlights.ts
40 lines (35 loc) · 1.21 KB
/
addPRToHighlights.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { AddPRToHighlightsButton } from "../../content-scripts/components/AddPRToHighlights/AddPRToHighlightsButton";
import {
GITHUB_LOGGED_IN_USER_USERNAME_SELECTOR,
GITHUB_PR_AUTHOR_USERNAME_SELECTOR,
GITHUB_PR_COMMENT_HEADER_SELECTOR,
} from "../../constants";
import { isLoggedIn } from "../checkAuthentication";
const injectAddPRToHighlightsButton = async () => {
if (!(await isLoggedIn())) {
return;
}
const prAuthorUserName = document.getElementsByClassName(
GITHUB_PR_AUTHOR_USERNAME_SELECTOR,
)[0].textContent;
const loggedInUserUserName = document
.querySelector(GITHUB_LOGGED_IN_USER_USERNAME_SELECTOR)
?.getAttribute("content");
if (loggedInUserUserName && prAuthorUserName === loggedInUserUserName) {
const commentFormatRow = document.getElementsByClassName(
GITHUB_PR_COMMENT_HEADER_SELECTOR,
)[0];
const addPRToHighlightsButton = AddPRToHighlightsButton();
if (
!commentFormatRow.lastElementChild?.previousElementSibling?.isEqualNode(
addPRToHighlightsButton,
)
) {
commentFormatRow.insertBefore(
addPRToHighlightsButton,
commentFormatRow.lastElementChild,
);
}
}
};
export default injectAddPRToHighlightsButton;