diff --git a/epic-games.js b/epic-games.js index 8b25bcb..704bfd1 100644 --- a/epic-games.js +++ b/epic-games.js @@ -2,14 +2,9 @@ import { firefox } from 'playwright'; // stealth plugin needs no outdated playwr import { authenticator } from 'otplib'; import path from 'path'; import { existsSync, writeFileSync } from 'fs'; -import { dirs, jsonDb, datetime, stealth, filenamify, notify, html_game_list } from './util.js'; +import { dirs, jsonDb, datetime, stealth, filenamify, prompt, notify, html_game_list } from './util.js'; import { cfg } from './config.js'; -import prompts from 'prompts'; // alternatives: enquirer, inquirer -// import enquirer from 'enquirer'; const { prompt } = enquirer; -// single prompt that just returns the non-empty value instead of an object - why name things if there's just one? -const prompt = async o => (await prompts({name: 'name', type: 'text', message: 'Enter value', validate: s => s.length, ...o})).name; - const URL_CLAIM = 'https://store.epicgames.com/en-US/free-games'; const URL_LOGIN = 'https://www.epicgames.com/id/login?lang=en-US&noHostRedirect=true&redirectUrl=' + URL_CLAIM; diff --git a/gog.js b/gog.js index 2369610..feef173 100644 --- a/gog.js +++ b/gog.js @@ -1,13 +1,8 @@ import { firefox } from 'playwright'; // stealth plugin needs no outdated playwright-extra import path from 'path'; -import { dirs, jsonDb, datetime, filenamify, notify, html_game_list } from './util.js'; +import { dirs, jsonDb, datetime, filenamify, prompt, notify, html_game_list } from './util.js'; import { cfg } from './config.js'; -import prompts from 'prompts'; // alternatives: enquirer, inquirer -// import enquirer from 'enquirer'; const { prompt } = enquirer; -// single prompt that just returns the non-empty value instead of an object - why name things if there's just one? -const prompt = async o => (await prompts({name: 'name', type: 'text', message: 'Enter value', validate: s => s.length, ...o})).name; - const URL_CLAIM = 'https://www.gog.com/en'; console.log(datetime(), 'started checking gog'); diff --git a/prime-gaming.js b/prime-gaming.js index 5a5297e..d4e52ab 100644 --- a/prime-gaming.js +++ b/prime-gaming.js @@ -1,14 +1,9 @@ import { firefox } from 'playwright'; // stealth plugin needs no outdated playwright-extra import { authenticator } from 'otplib'; import path from 'path'; -import { dirs, jsonDb, datetime, stealth, filenamify, notify, html_game_list } from './util.js'; +import { dirs, jsonDb, datetime, stealth, filenamify, prompt, notify, html_game_list } from './util.js'; import { cfg } from './config.js'; -import prompts from 'prompts'; // alternatives: enquirer, inquirer -// import enquirer from 'enquirer'; const { prompt } = enquirer; -// single prompt that just returns the non-empty value instead of an object - why name things if there's just one? -const prompt = async o => (await prompts({name: 'name', type: 'text', message: 'Enter value', validate: s => s.length, ...o})).name; - // const URL_LOGIN = 'https://www.amazon.de/ap/signin'; // wrong. needs some session args to be valid? const URL_CLAIM = 'https://gaming.amazon.com/home'; diff --git a/util.js b/util.js index 47d1134..f2123a0 100644 --- a/util.js +++ b/util.js @@ -12,6 +12,8 @@ export const dirs = { screenshots: dataDir('screenshots'), }; + +// json database import { Low } from 'lowdb'; import { JSONFile } from 'lowdb/node'; export const jsonDb = async file => { @@ -20,13 +22,16 @@ export const jsonDb = async file => { return db; }; + // date and time as UTC (no timezone offset) in nicely readable and sortable format, e.g., 2022-10-06 12:05:27.313 export const datetime = (d = new Date()) => d.toISOString().replace('T', ' ').replace('Z', ''); // same as datetime() but for local timezone, e.g., UTC + 2h for the above in DE export const datetimeLocal = (d = new Date()) => datetime(new Date(d.getTime() - new Date().getTimezoneOffset() * 60000)); export const filenamify = s => s.replaceAll(':', '.').replace(/[^a-z0-9 _\-.]/gi, '_'); // alternative: https://www.npmjs.com/package/filenamify - On Unix-like systems, / is reserved. On Windows, <>:"/\|?* along with trailing periods are reserved. + // stealth with playwright: https://github.com/berstend/puppeteer-extra/issues/454#issuecomment-917437212 +// gets userAgent and then removes "Headless" from it const newStealthContext = async (browser, contextOptions = {}, debug = false) => { if (!debug) { // only need to fix userAgent in headless mode const dummyContext = await browser.newContext(); @@ -77,6 +82,13 @@ export const stealth = async (context) => { } }; + +import prompts from 'prompts'; // alternatives: enquirer, inquirer +// import enquirer from 'enquirer'; const { prompt } = enquirer; +// single prompt that just returns the non-empty value instead of an object - why name things if there's just one? +export const prompt = async o => (await prompts({name: 'name', type: 'text', message: 'Enter value', validate: s => s.length, ...o})).name; + + // notifications via apprise CLI import { exec } from 'child_process'; import { cfg } from './config.js';