channel-worker 2.5.36 → 2.5.37
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/scripts/upload_facebook_photo.js +39 -12
package/package.json
CHANGED
|
@@ -221,22 +221,34 @@ async function run({ page, payload, log }) {
|
|
|
221
221
|
|
|
222
222
|
// 6) Click "Đăng".
|
|
223
223
|
log('info', '[fbphoto] clicking publish…');
|
|
224
|
-
// Tag the first
|
|
225
|
-
//
|
|
224
|
+
// Tag the first VISIBLE + ENABLED button matching `verbs`. Mirrors the
|
|
225
|
+
// proven upload_facebook.js findByVerbs: searches ALL [role='dialog']
|
|
226
|
+
// (not just the first — FB renders extra hidden dialogs), matches
|
|
227
|
+
// innerText||textContent (button label often lives in a nested span), then
|
|
228
|
+
// falls back to the whole document. Returns the matched verb, or null.
|
|
226
229
|
const tagCta = async (verbs) => page.evaluate((vbs) => {
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
const r =
|
|
230
|
+
const tryScope = (roots, verb) => {
|
|
231
|
+
for (const root of roots) {
|
|
232
|
+
let best = null;
|
|
233
|
+
for (const el of root.querySelectorAll("button, [role='button']")) {
|
|
234
|
+
const t = (el.innerText || el.textContent || '').trim();
|
|
235
|
+
const a = (el.getAttribute('aria-label') || '').trim();
|
|
236
|
+
if (t !== verb && a !== verb) continue;
|
|
237
|
+
const r = el.getBoundingClientRect();
|
|
235
238
|
if (r.width < 8 || r.height < 8) continue;
|
|
236
|
-
|
|
237
|
-
|
|
239
|
+
const cs = getComputedStyle(el);
|
|
240
|
+
if (cs.visibility === 'hidden' || cs.display === 'none' || cs.opacity === '0') continue;
|
|
241
|
+
if (el.getAttribute('aria-disabled') === 'true' || el.disabled) continue;
|
|
242
|
+
best = el;
|
|
238
243
|
}
|
|
244
|
+
if (best) return best;
|
|
239
245
|
}
|
|
246
|
+
return null;
|
|
247
|
+
};
|
|
248
|
+
for (const v of vbs) {
|
|
249
|
+
const dlgs = Array.from(document.querySelectorAll("[role='dialog']"));
|
|
250
|
+
let el = tryScope(dlgs, v) || tryScope([document], v);
|
|
251
|
+
if (el) { el.setAttribute('__fbphoto_cta__', '1'); return v; }
|
|
240
252
|
}
|
|
241
253
|
return null;
|
|
242
254
|
}, verbs).catch(() => null);
|
|
@@ -260,6 +272,21 @@ async function run({ page, payload, log }) {
|
|
|
260
272
|
if (nextHit) { log('info', `[fbphoto] advance via "${nextHit}" (step ${step + 1})`); await clickTaggedCta(); await page.waitForTimeout(2800); stalls = 0; continue; }
|
|
261
273
|
// Neither publish nor Tiếp enabled — FB still ingesting the photo. Wait.
|
|
262
274
|
if (++stalls > 10) break; // ~30s of no CTA → give up
|
|
275
|
+
if (stalls === 1 || stalls === 6) {
|
|
276
|
+
// Diagnostic: what buttons ARE in the composer right now?
|
|
277
|
+
const btns = await page.evaluate(() => {
|
|
278
|
+
const out = [];
|
|
279
|
+
for (const dlg of document.querySelectorAll("[role='dialog']")) {
|
|
280
|
+
for (const el of dlg.querySelectorAll("button, [role='button']")) {
|
|
281
|
+
const t = (el.innerText || el.textContent || '').trim().slice(0, 30);
|
|
282
|
+
const r = el.getBoundingClientRect();
|
|
283
|
+
if (t && r.width > 20 && r.height > 8) out.push(`${t}${el.getAttribute('aria-disabled') === 'true' ? '(disabled)' : ''}`);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
return [...new Set(out)].slice(0, 20);
|
|
287
|
+
}).catch(() => []);
|
|
288
|
+
log('info', `[fbphoto] composer buttons: ${JSON.stringify(btns)}`);
|
|
289
|
+
}
|
|
263
290
|
log('info', `[fbphoto] no CTA yet at step ${step + 1} — waiting…`);
|
|
264
291
|
step--; // don't count a pure wait against the step budget
|
|
265
292
|
await page.waitForTimeout(3000);
|