fix eslint errors

This commit is contained in:
Ralf Vogler 2025-05-22 16:48:32 +02:00
parent 1dbbfaf3ad
commit 6d9a3ad140
7 changed files with 59 additions and 51 deletions

View file

@ -1,5 +1,5 @@
import { firefox } from 'playwright-firefox'; // stealth plugin needs no outdated playwright-extra
import { datetime, filenamify, prompt, handleSIGINT, stealth } from './src/util.js';
import { datetime, filenamify, prompt, handleSIGINT } from './src/util.js';
import { cfg } from './src/config.js';
// using https://github.com/apify/fingerprint-suite worked, but has no launchPersistentContext...
@ -8,8 +8,8 @@ import { FingerprintInjector } from 'fingerprint-injector';
import { FingerprintGenerator } from 'fingerprint-generator';
const { fingerprint, headers } = new FingerprintGenerator().getFingerprint({
devices: ["mobile"],
operatingSystems: ["android"],
devices: ['mobile'],
operatingSystems: ['android'],
});
const context = await firefox.launchPersistentContext(cfg.dir.browser, {
@ -36,7 +36,7 @@ context.setDefaultTimeout(cfg.debug ? 0 : cfg.timeout);
const page = context.pages().length ? context.pages()[0] : await context.newPage(); // should always exist
const auth = async (url) => {
const auth = async url => {
console.log('auth', url);
await page.goto(url, { waitUntil: 'domcontentloaded' });
// redirects to https://login.aliexpress.com/?return_url=https%3A%2F%2Fwww.aliexpress.com%2Fp%2Fcoin-pc-index%2Findex.html
@ -88,31 +88,35 @@ const coins = async () => {
console.log('Tomorrow:', await page.locator('.addcoin').innerText());
};
const grow = async () => {
await page.pause();
};
const gogo = async () => {
await page.pause();
};
const euro = async () => {
await page.pause();
};
const merge = async () => {
await page.pause();
};
// const grow = async () => {
// await page.pause();
// };
//
// const gogo = async () => {
// await page.pause();
// };
//
// const euro = async () => {
// await page.pause();
// };
//
// const merge = async () => {
// await page.pause();
// };
try {
// await coins();
await [
// coins,
coins,
// grow,
// gogo,
// euro,
merge,
].reduce((a, f) => a.then(async _ => { await auth(urls[f.name]); await f(); console.log() }), Promise.resolve());
// merge,
].reduce((a, f) => a.then(async _ => {
await auth(urls[f.name]);
await f();
console.log();
}), Promise.resolve());
// await page.pause();
} catch (error) {

View file

@ -53,7 +53,6 @@ const page = context.pages().length ? context.pages()[0] : await context.newPage
await page.setViewportSize({ width: cfg.width, height: cfg.height }); // TODO workaround for https://github.com/vogler/free-games-claimer/issues/277 until Playwright fixes it
// some debug info about the page (screen dimensions, user agent, platform)
// eslint-disable-next-line no-undef
if (cfg.debug) console.debug(await page.evaluate(() => [(({ width, height, availWidth, availHeight }) => ({ width, height, availWidth, availHeight }))(window.screen), navigator.userAgent, navigator.platform, navigator.vendor])); // deconstruct screen needed since `window.screen` prints {}, `window.screen.toString()` '[object Screen]', and can't use some pick function without defining it on `page`
if (cfg.debug_network) {
// const filter = _ => true;

View file

@ -15,7 +15,10 @@ export default [
{
// files: ['*.js'],
languageOptions: {
globals: globals.node,
globals: {
...globals.node,
...globals.browser,
},
},
plugins: {
'@stylistic/js': stylistic,

View file

@ -131,6 +131,8 @@ try {
// bottom to top: oldest to newest games
internal.reverse();
external.reverse();
// TODO just use async, no need for Promise? -> type error since now Page | bool instead of any
// eslint-disable-next-line no-async-promise-executor
const sameOrNewPage = async url => new Promise(async (resolve, _reject) => {
const isNew = page.url() != url;
let p = page;
@ -149,7 +151,7 @@ try {
console.log(' ', await p.locator('.availability-date').innerText(), '->', daysLeft.toFixed(2));
if (isNew) await p.close();
return daysLeft > cfg.pg_timeLeft;
}
};
console.log('\nNumber of free unclaimed games (Prime Gaming):', internal.length);
// claim games in internal store
for (const card of internal) {
@ -300,7 +302,7 @@ try {
if (j?.events?.cart.length && j.events.cart[0]?.data?.reason == 'UserAlreadyOwnsContent') {
redeem_action = 'already redeemed';
console.error(' error: UserAlreadyOwnsContent');
} else if (true) { // TODO what's returned on success?
} else { // TODO what's returned on success?
redeem_action = 'redeemed';
db.data[user][title].status = 'claimed and redeemed?';
console.log(' Redeemed successfully? Please report if not in https://github.com/vogler/free-games-claimer/issues/5');
@ -366,7 +368,7 @@ try {
await loot.waitFor();
process.stdout.write('Loading all DLCs on page...');
await scrollUntilStable(() => loot.locator('[data-a-target="item-card"]').count())
await scrollUntilStable(() => loot.locator('[data-a-target="item-card"]').count());
console.log('\nNumber of already claimed DLC:', await loot.locator('p:has-text("Collected")').count());

View file

@ -12,8 +12,8 @@ import { FingerprintInjector } from 'fingerprint-injector';
import { FingerprintGenerator } from 'fingerprint-generator';
const { fingerprint, headers } = new FingerprintGenerator().getFingerprint({
devices: ["desktop"],
operatingSystems: ["windows"],
devices: ['desktop'],
operatingSystems: ['windows'],
});
const context = await firefox.launchPersistentContext(cfg.dir.browser, {

View file

@ -12,10 +12,10 @@ function onRawSIGINT(fn) {
}
});
}
console.log(1)
console.log(1);
onRawSIGINT(() => {
console.log('raw'); process.exit(1);
});
console.log(2)
console.log(2);
// onRawSIGINT workaround for enquirer keeps the process from exiting here...

View file

@ -7,19 +7,19 @@ import { prompt, handleSIGINT } from '../src/util.js';
// });
handleSIGINT();
function onRawSIGINT(fn) {
const { stdin, stdout } = process;
stdin.setRawMode(true);
stdin.resume();
stdin.on('data', data => {
const key = data.toString('utf-8');
if (key === '\u0003') { // ctrl + c
fn();
} else {
stdout.write(key);
}
});
}
// function onRawSIGINT(fn) {
// const { stdin, stdout } = process;
// stdin.setRawMode(true);
// stdin.resume();
// stdin.on('data', data => {
// const key = data.toString('utf-8');
// if (key === '\u0003') { // ctrl + c
// fn();
// } else {
// stdout.write(key);
// }
// });
// }
// onRawSIGINT(() => {
// console.log('raw'); process.exit(1);
// });