add username to notification of claimed games, closes #88

This commit is contained in:
Ralf Vogler 2023-03-06 21:15:42 +01:00
parent e45c3a5dca
commit cbdea1b5d0
3 changed files with 9 additions and 6 deletions

View file

@ -47,6 +47,7 @@ const page = context.pages().length ? context.pages()[0] : await context.newPage
// console.debug('userAgent:', await page.evaluate(() => navigator.userAgent));
const notify_games = [];
let user;
try {
await context.addCookies([{name: 'OptanonAlertBoxClosed', value: new Date(Date.now() - 5*24*60*60*1000).toISOString(), domain: '.epicgames.com', path: '/'}]); // Accept cookies to get rid of banner to save space on screen. Set accept time to 5 days ago.
@ -94,7 +95,7 @@ try {
await page.waitForURL(URL_CLAIM);
if (!cfg.debug) context.setDefaultTimeout(cfg.timeout);
}
const user = await page.locator('#user span').first().innerHTML();
user = await page.locator('#user span').first().innerHTML();
console.log(`Signed in as ${user}`);
db.data[user] ||= {};
@ -195,7 +196,7 @@ try {
} finally {
await db.write(); // write out json db
if (notify_games.filter(g => g.status != 'existed').length) { // don't notify if all were already claimed
notify(`epic-games:<br>${html_game_list(notify_games)}`);
notify(`epic-games (${user}):<br>${html_game_list(notify_games)}`);
}
}
if (cfg.debug) writeFileSync(path.resolve(cfg.dir.browser, 'cookies.json'), JSON.stringify(await context.cookies()));

5
gog.js
View file

@ -27,6 +27,7 @@ const page = context.pages().length ? context.pages()[0] : await context.newPage
// console.debug('userAgent:', await page.evaluate(() => navigator.userAgent));
const notify_games = [];
let user;
try {
await context.addCookies([{name: 'CookieConsent', value: '{stamp:%274oR8MJL+bxVlG6g+kl2we5+suMJ+Tv7I4C5d4k+YY4vrnhCD+P23RQ==%27%2Cnecessary:true%2Cpreferences:true%2Cstatistics:true%2Cmarketing:true%2Cmethod:%27explicit%27%2Cver:1%2Cutc:1672331618201%2Cregion:%27de%27}', domain: 'www.gog.com', path: '/'}]); // to not waste screen space when non-headless
@ -82,7 +83,7 @@ try {
await page.waitForSelector('#menuUsername');
if (!cfg.debug) context.setDefaultTimeout(cfg.timeout);
}
const user = await page.locator('#menuUsername').first().textContent(); // innerText is uppercase due to styling!
user = await page.locator('#menuUsername').first().textContent(); // innerText is uppercase due to styling!
console.log(`Signed in as '${user}'`);
db.data[user] ||= {};
@ -140,7 +141,7 @@ try {
} finally {
await db.write(); // write out json db
if (notify_games.filter(g => g.status != 'existed').length) { // don't notify if all were already claimed
notify(`gog:<br>${html_game_list(notify_games)}`);
notify(`gog (${user}):<br>${html_game_list(notify_games)}`);
}
}
await context.close();

View file

@ -30,6 +30,7 @@ const page = context.pages().length ? context.pages()[0] : await context.newPage
// console.debug('userAgent:', await page.evaluate(() => navigator.userAgent));
const notify_games = [];
let user;
try {
await page.goto(URL_CLAIM, { waitUntil: 'domcontentloaded' }); // default 'load' takes forever
@ -78,7 +79,7 @@ try {
await page.waitForURL('https://gaming.amazon.com/home?signedIn=true');
if (!cfg.debug) context.setDefaultTimeout(cfg.timeout);
}
const user = await page.locator('[data-a-target="user-dropdown-first-name-text"]').first().innerText();
user = await page.locator('[data-a-target="user-dropdown-first-name-text"]').first().innerText();
console.log(`Signed in as ${user}`);
// await page.click('button[aria-label="User dropdown and more options"]');
// const twitch = await page.locator('[data-a-target="TwitchDisplayName"]').first().innerText();
@ -241,7 +242,7 @@ try {
} finally {
await db.write(); // write out json db
if (notify_games.length) { // list should only include claimed games
notify(`prime-gaming:<br>${html_game_list(notify_games)}`);
notify(`prime-gaming (${user}):<br>${html_game_list(notify_games)}`);
}
}
await context.close();