prime-gaming: screenshot of claimed external game, print URL to redeem
This commit is contained in:
parent
fdf34ef218
commit
4e90fb67c6
1 changed files with 24 additions and 10 deletions
|
|
@ -50,9 +50,10 @@ while (await page.locator('button:has-text("Sign in")').count() > 0) {
|
||||||
}
|
}
|
||||||
console.log('Signed in.');
|
console.log('Signed in.');
|
||||||
await page.click('button:has-text("Games")');
|
await page.click('button:has-text("Games")');
|
||||||
await page.waitForSelector('div[data-a-target="offer-list-FGWP_FULL"]');
|
const games_sel = 'div[data-a-target="offer-list-FGWP_FULL"]';
|
||||||
console.log('Number of already claimed games (total):', await page.locator('div[data-a-target="offer-list-FGWP_FULL"] p:has-text("Claimed")').count());
|
await page.waitForSelector(games_sel);
|
||||||
const game_sel = 'div[data-a-target="offer-list-FGWP_FULL"] [data-a-target="item-card"]:has-text("Claim game")';
|
console.log('Number of already claimed games (total):', await page.locator(`${games_sel} p:has-text("Collected")`).count());
|
||||||
|
const game_sel = `${games_sel} [data-a-target="item-card"]:has-text("Claim game")`;
|
||||||
const n = await page.locator(game_sel).count();
|
const n = await page.locator(game_sel).count();
|
||||||
console.log('Number of free unclaimed games (Prime Gaming):', n);
|
console.log('Number of free unclaimed games (Prime Gaming):', n);
|
||||||
const games = await page.$$(game_sel);
|
const games = await page.$$(game_sel);
|
||||||
|
|
@ -62,12 +63,12 @@ for (const card of games) {
|
||||||
// const title = await card.locator('h3').first().innerText();
|
// const title = await card.locator('h3').first().innerText();
|
||||||
const title = await (await card.$('.item-card-details__body__primary')).innerText();
|
const title = await (await card.$('.item-card-details__body__primary')).innerText();
|
||||||
console.log('Current free game:', title);
|
console.log('Current free game:', title);
|
||||||
await (await card.$('button')).click();
|
await (await card.$('button:has-text("Claim game")')).click();
|
||||||
// await page.pause();
|
// await page.pause();
|
||||||
}
|
}
|
||||||
// claim games in linked stores. Origin: key, Epic Games Store: linked
|
// claim games in linked stores. Origin: key, Epic Games Store: linked
|
||||||
{
|
{
|
||||||
const game_sel = 'div[data-a-target="offer-list-FGWP_FULL"] [data-a-target="item-card"]:has(p:text-is("Claim"))';
|
const game_sel = `${games_sel} [data-a-target="item-card"]:has(p:text-is("Claim"))`;
|
||||||
do {
|
do {
|
||||||
let n = await page.locator(game_sel).count();
|
let n = await page.locator(game_sel).count();
|
||||||
console.log('Number of free unclaimed games (external stores):', n);
|
console.log('Number of free unclaimed games (external stores):', n);
|
||||||
|
|
@ -77,16 +78,29 @@ for (const card of games) {
|
||||||
console.log('Current free game:', title);
|
console.log('Current free game:', title);
|
||||||
await (await card.$('text=Claim')).click();
|
await (await card.$('text=Claim')).click();
|
||||||
// await page.waitForNavigation();
|
// await page.waitForNavigation();
|
||||||
await page.click('button:has-text("Claim now")');
|
await page.click('button:has-text("Claim now")'); // waits for navigation
|
||||||
console.log(await (await page.$('[data-a-target="hero-header-subtitle"]')).innerText());
|
const store_text = await (await page.$('[data-a-target="hero-header-subtitle"]')).innerText();
|
||||||
// TODO only Origin shows a key, check for 'Claimed' or code
|
// FULL GAME FOR PC ON: GOG.COM, ORIGIN, LEGACY GAMES, EPIC GAMES
|
||||||
if (await page.locator('div:has-text("Origin")').count() > 0) {
|
const store = store_text.toLowerCase().replace('full game for pc on ', '');
|
||||||
|
console.log('External store:', store);
|
||||||
|
// save screenshot of potential code just in case
|
||||||
|
const p = `screenshots/${title.replace(/[^a-z0-9]/gi, '_')}.png`;
|
||||||
|
await page.screenshot({ path: p, fullPage: true });
|
||||||
|
console.info('Saved a screenshot of page to', p);
|
||||||
|
// print code if external store is not connected
|
||||||
|
const redeem = {
|
||||||
|
'origin': 'https://www.origin.com/redeem',
|
||||||
|
'gog.com': 'https://www.gog.com/redeem',
|
||||||
|
'legacy games': 'https://www.legacygames.com/primedeal',
|
||||||
|
};
|
||||||
|
if (store in redeem) {
|
||||||
const code = await page.inputValue('input[type="text"]');
|
const code = await page.inputValue('input[type="text"]');
|
||||||
console.log('Code to redeem game:', code);
|
console.log('Code to redeem game:', code);
|
||||||
|
console.log('URL to redeem game:', redeem[store]);
|
||||||
}
|
}
|
||||||
// await page.pause();
|
// await page.pause();
|
||||||
await page.goto(URL_CLAIM, {waitUntil: 'domcontentloaded'});
|
await page.goto(URL_CLAIM, {waitUntil: 'domcontentloaded'});
|
||||||
n = await page.locator(game_sel).count();
|
await page.click('button:has-text("Games")');
|
||||||
} while (n);
|
} while (n);
|
||||||
}
|
}
|
||||||
await context.close();
|
await context.close();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue