From f920aa26d0d89404a97a715c14f8f7b9400beda5 Mon Sep 17 00:00:00 2001 From: Ralf Vogler Date: Sun, 23 Jun 2024 19:18:30 +0200 Subject: [PATCH] pg: checkTimeLeft via PG_TIMELEFT=1 --- prime-gaming.js | 19 +++++++++++++++++++ src/config.js | 3 ++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/prime-gaming.js b/prime-gaming.js index ca3fcee..d8caaeb 100644 --- a/prime-gaming.js +++ b/prime-gaming.js @@ -110,6 +110,23 @@ try { // bottom to top: oldest to newest games internal.reverse(); external.reverse(); + const checkTimeLeft = async url => { + // console.log(' Checking time left for game:', url); + const check = async p => { + console.log(' ', await p.locator('.availability-date').innerText()); + const dueDateOrg = await p.locator('.availability-date .tw-bold').innerText(); + const dueDate = datetime(new Date(Date.parse(dueDateOrg + ' 17:00'))); + console.log(' Due date:', dueDate); + }; + if (page.url() == url) { + await check(page); + } else { + const p = await context.newPage(); + await p.goto(url, { waitUntil: 'domcontentloaded' }); + await check(p); + p.close(); + } + }; console.log('Number of free unclaimed games (Prime Gaming):', internal.length); // claim games in internal store for (const card of internal) { @@ -118,6 +135,7 @@ try { const slug = await (await card.$('a')).getAttribute('href'); const url = 'https://gaming.amazon.com' + slug.split('?')[0]; console.log('Current free game:', title); + if (cfg.pg_timeLeft) await checkTimeLeft(url); if (cfg.dryrun) continue; if (cfg.interactive && !await confirm()) continue; await (await card.$('.tw-button:has-text("Claim")')).click(); @@ -144,6 +162,7 @@ try { const item_text = await page.innerText('[data-a-target="DescriptionItemDetails"]'); const store = item_text.toLowerCase().replace(/.* on /, '').slice(0, -1); console.log(' External store:', store); + if (cfg.pg_timeLeft) await checkTimeLeft(url); if (cfg.dryrun) continue; if (cfg.interactive && !await confirm()) continue; await Promise.any([page.click('[data-a-target="buy-box"] .tw-button:has-text("Get game")'), page.click('[data-a-target="buy-box"] .tw-button:has-text("Claim")'), page.click('.tw-button:has-text("Complete Claim")'), page.waitForSelector('div:has-text("Link game account")'), page.waitForSelector('.thank-you-title:has-text("Success")')]); // waits for navigation diff --git a/src/config.js b/src/config.js index bd41c7d..56e42d2 100644 --- a/src/config.js +++ b/src/config.js @@ -46,7 +46,8 @@ export const cfg = { xbox_email: process.env.XBOX_EMAIL || process.env.EMAIL, xbox_password: process.env.XBOX_PASSWORD || process.env.PASSWORD, xbox_otpkey: process.env.XBOX_OTPKEY, - // experimmental - likely to change + // experimmental pg_redeem: process.env.PG_REDEEM == '1', // prime-gaming: redeem keys on external stores pg_claimdlc: process.env.PG_CLAIMDLC == '1', // prime-gaming: claim in-game content + pg_timeLeft: process.env.PG_TIMELEFT == '1', // prime-gaming: list time left to claim };