pg: experimental PG_CLAIMDLC, WIP #55
This commit is contained in:
parent
a5f42a9609
commit
b51547a376
2 changed files with 50 additions and 1 deletions
|
|
@ -37,4 +37,5 @@ export const cfg = {
|
|||
|
||||
// experimmental - likely to change
|
||||
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
|
||||
};
|
||||
|
|
|
|||
|
|
@ -233,7 +233,55 @@ try {
|
|||
} while (n);
|
||||
const p = path.resolve(cfg.dir.screenshots, 'prime-gaming', `${filenamify(datetime())}.png`);
|
||||
// await page.screenshot({ path: p, fullPage: true });
|
||||
await page.locator(games_sel).screenshot({ path: p });
|
||||
if (!cfg.dryrun) await page.locator(games_sel).screenshot({ path: p });
|
||||
|
||||
if (cfg.pg_claimdlc) {
|
||||
console.log('Trying to claim in-game content...');
|
||||
await page.click('button[data-type="InGameLoot"]');
|
||||
const loot_sel = 'div[data-a-target="offer-list-IN_GAME_LOOT"]';
|
||||
await page.waitForSelector(loot_sel);
|
||||
console.log('Number of already claimed DLC:', await page.locator(`${loot_sel} p:has-text("Collected")`).count());
|
||||
|
||||
const cards = await page.locator(`${loot_sel} [data-a-target="item-card"]:has(p:text-is("Claim"))`).all();
|
||||
console.log('Number of unclaimed DLC:', cards.length);
|
||||
const dlcs = await Promise.all(cards.map(async card => ({
|
||||
game: await card.locator('.item-card-details__body p').innerText(),
|
||||
title: await card.locator('.item-card-details__body__primary').innerText(),
|
||||
url: 'https://gaming.amazon.com' + await card.locator('a').getAttribute('href'),
|
||||
})));
|
||||
// console.log(dlcs);
|
||||
|
||||
for (const dlc of dlcs) {
|
||||
const title = `${dlc.game} - ${dlc.title}`;
|
||||
const url = dlc.url;
|
||||
console.log('Current DLC:', title);
|
||||
// if (cfg.dryrun) continue;
|
||||
db.data[user][title] ||= { title, time: datetime(), store: 'DLC', status: 'failed: need account linking' };
|
||||
const notify_game = { title, url };
|
||||
notify_games.push(notify_game); // status is updated below
|
||||
await page.goto(url, { waitUntil: 'domcontentloaded' });
|
||||
// most games have a button 'Get in-game content'
|
||||
// epic-games: Fall Guys: Claim now -> Continue -> Go to Epic Games (despite account linked and logged into epic-games) -> not tied to account but via some cookie?
|
||||
await Promise.any([page.click('button:has-text("Get in-game content")'), page.click('button:has-text("Claim your gift")'), page.click('button:has-text("Claim now")').then(() => page.click('button:has-text("Continue")'))]);
|
||||
page.click('button:has-text("Continue")').catch(_ => { });
|
||||
const linkAccountModal = page.locator('[data-a-target="LinkAccountModal"]');
|
||||
const linkAccountButton = linkAccountModal.locator('[data-a-target="LinkAccountButton"]');
|
||||
if (await linkAccountButton.count()) {
|
||||
console.error(' Missing account linking:', await linkAccountButton.innerText());
|
||||
} else if(await page.locator('text=Link game account').count()) { // epic-games only?
|
||||
console.error(' Missing account linking:', await page.locator('button[data-a-target="gms-cta"]').innerText());
|
||||
} else {
|
||||
const code = await page.inputValue('input[type="text"]');
|
||||
console.log(' Code to redeem game:', code);
|
||||
db.data[user][title].code = code;
|
||||
db.data[user][title].status = 'claimed';
|
||||
// notify_game.status = `<a href="${redeem[store]}">${redeem_action}</a> ${code} on ${store}`;
|
||||
}
|
||||
// await page.pause();
|
||||
await page.goto(URL_CLAIM, { waitUntil: 'domcontentloaded' });
|
||||
await page.click('button[data-type="InGameLoot"]');
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error); // .toString()?
|
||||
process.exitCode ||= 1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue