-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
inviteToOpenSauced.ts
45 lines (38 loc) · 1.52 KB
/
inviteToOpenSauced.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
41
42
43
44
45
import { GITHUB_PROFILE_MENU_SELECTOR } from "../../constants";
import { InviteToOpenSaucedButton } from "../../content-scripts/components/InviteToOpenSauced/InviteToOpenSaucedButton";
import { InviteToOpenSaucedModal } from "../../content-scripts/components/InviteToOpenSauced/InviteToOpenSaucedModal";
import { getTwitterUsername, getLinkedInUsername } from "../urlMatchers";
const injectOpenSaucedInviteButton = (username: string) => {
const emailAddress = document
.querySelector(`a[href^="mailto:"]`)
?.getAttribute("href")
?.replace("mailto:", "");
const twitterUrl = document
.querySelector(`a[href*="twitter.com"]`)
?.getAttribute("href");
const linkedInUrl = document
.querySelector(`a[href*="linkedin.com"]`)
?.getAttribute("href");
if (!(emailAddress || twitterUrl || linkedInUrl)) {
return;
}
const twitterUsername = twitterUrl && getTwitterUsername(twitterUrl);
const linkedInUsername = linkedInUrl && getLinkedInUsername(linkedInUrl);
const inviteToOpenSaucedButton = InviteToOpenSaucedButton();
const inviteToOpenSaucedModal = InviteToOpenSaucedModal(
username,
{
emailAddress,
twitterUsername,
linkedInUsername,
},
inviteToOpenSaucedButton,
);
const userBio = document.querySelector(GITHUB_PROFILE_MENU_SELECTOR);
if (userBio?.lastChild?.isEqualNode(inviteToOpenSaucedButton)) {
return;
}
userBio?.append(inviteToOpenSaucedButton);
document.body.appendChild(inviteToOpenSaucedModal);
};
export default injectOpenSaucedInviteButton;