coffeeinabit 0.0.9 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/tools/send_connection_request.js +47 -24
package/package.json
CHANGED
|
@@ -38,7 +38,7 @@ async function detectConnectionStatus(page, username) {
|
|
|
38
38
|
moreActionsSelectors = await getButtonByText(page, 'More actions', inMain);
|
|
39
39
|
}
|
|
40
40
|
if (moreActionsSelectors && (await moreActionsSelectors.isVisible())) {
|
|
41
|
-
await moreActionsSelectors
|
|
41
|
+
await clickWithRetries(moreActionsSelectors);
|
|
42
42
|
await new Promise(resolve => setTimeout(resolve, Math.floor(Math.random() * 1000) + 500));
|
|
43
43
|
}
|
|
44
44
|
let removeConnectionButton = await getButtonByText(page, 'Remove Connection', inMain);
|
|
@@ -81,7 +81,7 @@ async function handleConnectButtonClick(page, username, inMain = true, handleSen
|
|
|
81
81
|
|
|
82
82
|
if (connectButton && (await connectButton.isVisible())) {
|
|
83
83
|
try {
|
|
84
|
-
await connectButton
|
|
84
|
+
await clickWithRetries(connectButton);
|
|
85
85
|
|
|
86
86
|
if (handleSendWithoutNote) {
|
|
87
87
|
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
@@ -96,7 +96,7 @@ async function handleConnectButtonClick(page, username, inMain = true, handleSen
|
|
|
96
96
|
|
|
97
97
|
if (sendWithoutNoteButton && (await sendWithoutNoteButton.isVisible())) {
|
|
98
98
|
try {
|
|
99
|
-
await sendWithoutNoteButton
|
|
99
|
+
await clickWithRetries(sendWithoutNoteButton);
|
|
100
100
|
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
101
101
|
return { status: 'success', message: `Connection request sent successfully to ${username}` };
|
|
102
102
|
} catch (error) {
|
|
@@ -123,33 +123,56 @@ async function handleConnectButtonClick(page, username, inMain = true, handleSen
|
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
async function getButtonByText(page, text, inMain = false) {
|
|
126
|
-
|
|
127
|
-
|
|
126
|
+
const candidates = Array.isArray(text) ? text : [text];
|
|
127
|
+
let elements = [];
|
|
128
128
|
if (inMain) {
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
129
|
+
const main = page.locator('main');
|
|
130
|
+
elements = [
|
|
131
|
+
...(await main.locator('button').all()),
|
|
132
|
+
...(await main.locator('[role="button"]').all()),
|
|
133
|
+
...(await main.locator('[aria-label]').all())
|
|
134
|
+
];
|
|
133
135
|
} else {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
136
|
+
elements = [
|
|
137
|
+
...(await page.locator('button').all()),
|
|
138
|
+
...(await page.locator('[role="button"]').all()),
|
|
139
|
+
...(await page.locator('[aria-label]').all())
|
|
140
|
+
];
|
|
141
|
+
}
|
|
142
|
+
for (let i = 0; i < elements.length; i++) {
|
|
143
|
+
const el = elements[i];
|
|
141
144
|
try {
|
|
142
|
-
if (!(await
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
145
|
+
if (!(await el.isVisible())) continue;
|
|
146
|
+
const textContent = (await el.textContent()) || '';
|
|
147
|
+
const innerText = (await el.innerText()) || '';
|
|
148
|
+
const ariaLabel = (await el.getAttribute('aria-label')) || '';
|
|
149
|
+
const combined = `${textContent}\n${innerText}\n${ariaLabel}`.toLowerCase().replace(/\s+/g, ' ').trim();
|
|
150
|
+
for (const c of candidates) {
|
|
151
|
+
const needle = String(c).toLowerCase().trim();
|
|
152
|
+
if (!needle) continue;
|
|
153
|
+
if (combined === needle || combined.includes(needle)) {
|
|
154
|
+
await el.scrollIntoViewIfNeeded();
|
|
155
|
+
return el;
|
|
156
|
+
}
|
|
148
157
|
}
|
|
149
|
-
} catch (
|
|
158
|
+
} catch (_) {
|
|
150
159
|
continue;
|
|
151
160
|
}
|
|
152
161
|
}
|
|
153
|
-
|
|
154
162
|
return null;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
async function clickWithRetries(locator, retries = 3) {
|
|
166
|
+
for (let attempt = 0; attempt < retries; attempt++) {
|
|
167
|
+
try {
|
|
168
|
+
await locator.scrollIntoViewIfNeeded();
|
|
169
|
+
await locator.waitFor({ state: 'visible', timeout: 5000 });
|
|
170
|
+
await locator.click({ trial: false, timeout: 15000 });
|
|
171
|
+
return true;
|
|
172
|
+
} catch (_) {
|
|
173
|
+
await new Promise(r => setTimeout(r, 1000 * (attempt + 1)));
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
await locator.click();
|
|
177
|
+
return true;
|
|
155
178
|
}
|