Skip to content

Commit

Permalink
refactor: Refactored inviteToOpenSauced.ts to avoid "as" and "!"
Browse files Browse the repository at this point in the history
  • Loading branch information
Anush008 committed Apr 27, 2023
1 parent 93e741a commit 0eb064d
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions src/utils/dom-utils/inviteToOpenSauced.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,30 @@ import { InviteToOpenSaucedModal } from "../../content-scripts/components/Invite
import { getTwitterUsername, getLinkedInUsername } from "../urlMatchers";

const injectOpenSaucedInviteButton = (username: string) => {
const emailAddress: string | undefined = (
document.querySelector(`a[href^="mailto:"]`)!
).href.substr(7);
const twitterUrl: string | undefined = (
document.querySelector(`a[href*="twitter.com"]`)!
).href;
const linkedInUrl: string | undefined = (
document.querySelector(`a[href*="linkedin.com"]`)!
).href;
const emailAddress: string | undefined = (() => {
const element = document.querySelector(`a[href^="mailto:"]`);

if (element instanceof HTMLAnchorElement) {
return element.href;
}
return undefined;
})();
const twitterUrl: string | undefined = (() => {
const element = document.querySelector(`a[href*="twitter.com"]`);

if (element instanceof HTMLAnchorElement) {
return element.href;
}
return undefined;
})();
const linkedInUrl: string | undefined = (() => {
const element = document.querySelector(`a[href*="linkedin.com"]`);

if (element instanceof HTMLAnchorElement) {
return element.href;
}
return undefined;
})();

if (!(emailAddress || twitterUrl || linkedInUrl)) {
return;
Expand Down

0 comments on commit 0eb064d

Please sign in to comment.