run eslint --fix .
This commit is contained in:
parent
011eddf97a
commit
0832ae57f5
10 changed files with 259 additions and 263 deletions
|
|
@ -16,7 +16,7 @@ const db = await jsonDb('prime-gaming.json', {});
|
|||
const context = await firefox.launchPersistentContext(cfg.dir.browser, {
|
||||
headless: cfg.headless,
|
||||
viewport: { width: cfg.width, height: cfg.height },
|
||||
locale: "en-US", // ignore OS locale to be sure to have english text for locators
|
||||
locale: 'en-US', // ignore OS locale to be sure to have english text for locators
|
||||
recordVideo: cfg.record ? { dir: 'data/record/', size: { width: cfg.width, height: cfg.height } } : undefined, // will record a .webm video for each page navigated; without size, video would be scaled down to fit 800x800
|
||||
recordHar: cfg.record ? { path: `data/record/pg-${datetime()}.har` } : undefined, // will record a HAR file with network requests and responses; can be imported in Chrome devtools
|
||||
handleSIGINT: false, // have to handle ourselves and call context.close(), otherwise recordings from above won't be saved
|
||||
|
|
@ -44,11 +44,11 @@ try {
|
|||
console.error('Not signed in anymore.');
|
||||
await page.click('button:has-text("Sign in")');
|
||||
if (!cfg.debug) context.setDefaultTimeout(cfg.login_timeout); // give user some extra time to log in
|
||||
console.info(`Login timeout is ${cfg.login_timeout/1000} seconds!`);
|
||||
console.info(`Login timeout is ${cfg.login_timeout / 1000} seconds!`);
|
||||
if (cfg.pg_email && cfg.pg_password) console.info('Using email and password from environment.');
|
||||
else console.info('Press ESC to skip the prompts if you want to login in the browser (not possible in headless mode).');
|
||||
const email = cfg.pg_email || await prompt({message: 'Enter email'});
|
||||
const password = email && (cfg.pg_password || await prompt({type: 'password', message: 'Enter password'}));
|
||||
const email = cfg.pg_email || await prompt({ message: 'Enter email' });
|
||||
const password = email && (cfg.pg_password || await prompt({ type: 'password', message: 'Enter password' }));
|
||||
if (email && password) {
|
||||
await page.fill('[name=email]', email);
|
||||
await page.fill('[name=password]', password);
|
||||
|
|
@ -66,7 +66,7 @@ try {
|
|||
page.waitForURL('**/ap/mfa**').then(async () => {
|
||||
console.log('Two-Step Verification - enter the One Time Password (OTP), e.g. generated by your Authenticator App');
|
||||
await page.check('[name=rememberDevice]');
|
||||
const otp = cfg.pg_otpkey && authenticator.generate(cfg.pg_otpkey) || await prompt({type: 'text', message: 'Enter two-factor sign in code', validate: n => n.toString().length == 6 || 'The code must be 6 digits!'}); // can't use type: 'number' since it strips away leading zeros and codes sometimes have them
|
||||
const otp = cfg.pg_otpkey && authenticator.generate(cfg.pg_otpkey) || await prompt({ type: 'text', message: 'Enter two-factor sign in code', validate: n => n.toString().length == 6 || 'The code must be 6 digits!' }); // can't use type: 'number' since it strips away leading zeros and codes sometimes have them
|
||||
await page.locator('input[name=otpCode]').pressSequentially(otp.toString());
|
||||
await page.click('input[type="submit"]');
|
||||
}).catch(_ => { });
|
||||
|
|
@ -128,10 +128,10 @@ try {
|
|||
const slug = await card.locator('a:has-text("Claim")').first().getAttribute('href');
|
||||
const url = 'https://gaming.amazon.com' + slug.split('?')[0];
|
||||
// await (await card.$('text=Claim')).click(); // goes to URL of game, no need to wait
|
||||
external_info.push({title, url});
|
||||
external_info.push({ title, url });
|
||||
}
|
||||
for (const {title, url} of external_info) {
|
||||
console.log('Current free game:', title); //, url);
|
||||
for (const { title, url } of external_info) {
|
||||
console.log('Current free game:', title); // , url);
|
||||
await page.goto(url, { waitUntil: 'domcontentloaded' });
|
||||
if (cfg.debug) await page.pause();
|
||||
if (cfg.dryrun) continue;
|
||||
|
|
@ -224,9 +224,9 @@ try {
|
|||
await page2.click('[type="submit"]'); // click Redeem
|
||||
const r2t = await (await r2).text();
|
||||
if (r2t == '{}') {
|
||||
redeem_action = 'redeemed';
|
||||
console.log(' Redeemed successfully.');
|
||||
db.data[user][title].status = 'claimed and redeemed';
|
||||
redeem_action = 'redeemed';
|
||||
console.log(' Redeemed successfully.');
|
||||
db.data[user][title].status = 'claimed and redeemed';
|
||||
} else {
|
||||
console.debug(` Response 2: ${r2t}`);
|
||||
console.log(' Unknown Response 2 - please report in https://github.com/vogler/free-games-claimer/issues/5');
|
||||
|
|
@ -298,7 +298,7 @@ try {
|
|||
await page.keyboard.press('End'); // scroll to bottom to show all games
|
||||
await page.waitForTimeout(1000); // wait for fade in animation
|
||||
const viewportSize = page.viewportSize(); // current viewport size
|
||||
await page.setViewportSize({...viewportSize, height: 3000}); // increase height, otherwise element screenshot is cut off at the top and bottom
|
||||
await page.setViewportSize({ ...viewportSize, height: 3000 }); // increase height, otherwise element screenshot is cut off at the top and bottom
|
||||
await games.screenshot({ path: p }); // screenshot of all claimed games
|
||||
}
|
||||
|
||||
|
|
@ -357,7 +357,7 @@ try {
|
|||
console.debug(' LinkAccountButton label:', unlinked_store);
|
||||
const match = unlinked_store.match(/Link (.*) account/);
|
||||
if (match && match.length == 2) unlinked_store = match[1];
|
||||
} else if(await page.locator('text=Link game account').count()) { // epic-games only?
|
||||
} else if (await page.locator('text=Link game account').count()) { // epic-games only?
|
||||
console.error(' Missing account linking (epic-games specific button?):', await page.locator('button[data-a-target="gms-cta"]').innerText()); // TODO needed?
|
||||
unlinked_store = 'epic-games';
|
||||
}
|
||||
|
|
@ -386,8 +386,7 @@ try {
|
|||
process.exitCode ||= 1;
|
||||
console.error('--- Exception:');
|
||||
console.error(error); // .toString()?
|
||||
if (error.message && process.exitCode != 130)
|
||||
notify(`prime-gaming failed: ${error.message.split('\n')[0]}`);
|
||||
if (error.message && process.exitCode != 130) notify(`prime-gaming failed: ${error.message.split('\n')[0]}`);
|
||||
} finally {
|
||||
await db.write(); // write out json db
|
||||
if (notify_games.length) { // list should only include claimed games
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue