diff --git a/src/shared.ts b/src/shared.ts index fbd8edd..e5a0a10 100644 --- a/src/shared.ts +++ b/src/shared.ts @@ -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 { diff --git a/src/tab.ts b/src/tab.ts index 789aec2..46c8030 100644 --- a/src/tab.ts +++ b/src/tab.ts @@ -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(); } @@ -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( + LinkedInCssSelector.SendInMailsModalDismissButton + ); + + if (sendInMailsModalDismissButton) { + focusAndClickElement(sendInMailsModalDismissButton); + } + const sendButton = document.querySelector(LinkedInCssSelector.SendButtonFromSendInviteModal); - sendButton?.click(); + if (sendButton) { + focusAndClickElement(sendButton); + } - if (sendButton || ++attempts > maximumAttemptsForFindingHtmlElements) { + if ( + sendButton || + sendInMailsModalDismissButton || + closeSendInMailsModalButton || + ++attempts > maximumAttemptsForFindingHtmlElements + ) { clearInterval(interval); resolve(null); }