Skip to content

Commit

Permalink
Close Send InMails dialogs, which appear when "message" buttons are c…
Browse files Browse the repository at this point in the history
…licked (#668)
  • Loading branch information
felladrin authored Dec 3, 2024
1 parent d84ca16 commit 5274baf
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ export interface ChromePortMessage {
export enum LinkedInCssSelector {
NextPageButton = "button.artdeco-pagination__button--next",
ConnectButtonFromMyNetworkPage = "div.discover-entity-type-card__bottom-container button.ember-view:enabled:not(.artdeco-button--muted):not(.artdeco-button--full)",
ConnectButtonFromSearchPage = "div.search-results-container div > button.ember-view:enabled:not(.artdeco-button--muted)",
ConnectButtonFromSearchPage = "div.search-results-container button.ember-view:enabled:not(.artdeco-button--muted)",
SendButtonFromSendInviteModal = "div.send-invite button.artdeco-button--primary",
SendInMailsModalDismissButton = "#artdeco-modal-outlet .artdeco-modal__dismiss",
CloseSendInMailsModalButton = '.msg-overlay-bubble-header__control .artdeco-button__icon[data-test-icon="close-small"]',
}

export enum LinkedInPage {
Expand Down
35 changes: 31 additions & 4 deletions src/tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ const [emitButtonClicksCount, onButtonClicksCountUpdated, getButtonClicksCount]
const [emitCurrentLinkedInPage, , getCurrentLinkedInPage] = createPubSub(LinkedInPage.Unidentified);
const [emitIsRunning, onIsRunningUpdated, getIsRunning] = createPubSub(false);

function focusAndClickElement(element: HTMLElement) {
element.focus();
element.click();
}

function clickConnectButton(button: HTMLButtonElement) {
button.focus();
button.click();
focusAndClickElement(button);
button.setAttribute("disabled", "disabled");
emitConnectButtonClicked();
}
Expand All @@ -47,11 +51,34 @@ function confirmSendInviteModal() {
let attempts = 0;

const interval = setInterval(() => {
const closeSendInMailsModalButton = document.querySelector(
LinkedInCssSelector.CloseSendInMailsModalButton
)?.parentElement;

if (closeSendInMailsModalButton) {
focusAndClickElement(closeSendInMailsModalButton);
}

const sendInMailsModalDismissButton = document.querySelector<HTMLButtonElement>(
LinkedInCssSelector.SendInMailsModalDismissButton
);

if (sendInMailsModalDismissButton) {
focusAndClickElement(sendInMailsModalDismissButton);
}

const sendButton = document.querySelector<HTMLButtonElement>(LinkedInCssSelector.SendButtonFromSendInviteModal);

sendButton?.click();
if (sendButton) {
focusAndClickElement(sendButton);
}

if (sendButton || ++attempts > maximumAttemptsForFindingHtmlElements) {
if (
sendButton ||
sendInMailsModalDismissButton ||
closeSendInMailsModalButton ||
++attempts > maximumAttemptsForFindingHtmlElements
) {
clearInterval(interval);
resolve(null);
}
Expand Down

0 comments on commit 5274baf

Please sign in to comment.