fix eslint errors
This commit is contained in:
parent
1dbbfaf3ad
commit
6d9a3ad140
7 changed files with 59 additions and 51 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
import { firefox } from 'playwright-firefox'; // stealth plugin needs no outdated playwright-extra
|
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';
|
import { cfg } from './src/config.js';
|
||||||
|
|
||||||
// using https://github.com/apify/fingerprint-suite worked, but has no launchPersistentContext...
|
// 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';
|
import { FingerprintGenerator } from 'fingerprint-generator';
|
||||||
|
|
||||||
const { fingerprint, headers } = new FingerprintGenerator().getFingerprint({
|
const { fingerprint, headers } = new FingerprintGenerator().getFingerprint({
|
||||||
devices: ["mobile"],
|
devices: ['mobile'],
|
||||||
operatingSystems: ["android"],
|
operatingSystems: ['android'],
|
||||||
});
|
});
|
||||||
|
|
||||||
const context = await firefox.launchPersistentContext(cfg.dir.browser, {
|
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 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);
|
console.log('auth', url);
|
||||||
await page.goto(url, { waitUntil: 'domcontentloaded' });
|
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
|
// 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());
|
console.log('Tomorrow:', await page.locator('.addcoin').innerText());
|
||||||
};
|
};
|
||||||
|
|
||||||
const grow = async () => {
|
// const grow = async () => {
|
||||||
await page.pause();
|
// await page.pause();
|
||||||
};
|
// };
|
||||||
|
//
|
||||||
const gogo = async () => {
|
// const gogo = async () => {
|
||||||
await page.pause();
|
// await page.pause();
|
||||||
};
|
// };
|
||||||
|
//
|
||||||
const euro = async () => {
|
// const euro = async () => {
|
||||||
await page.pause();
|
// await page.pause();
|
||||||
};
|
// };
|
||||||
|
//
|
||||||
const merge = async () => {
|
// const merge = async () => {
|
||||||
await page.pause();
|
// await page.pause();
|
||||||
};
|
// };
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// await coins();
|
// await coins();
|
||||||
await [
|
await [
|
||||||
// coins,
|
coins,
|
||||||
// grow,
|
// grow,
|
||||||
// gogo,
|
// gogo,
|
||||||
// euro,
|
// euro,
|
||||||
merge,
|
// merge,
|
||||||
].reduce((a, f) => a.then(async _ => { await auth(urls[f.name]); await f(); console.log() }), Promise.resolve());
|
].reduce((a, f) => a.then(async _ => {
|
||||||
|
await auth(urls[f.name]);
|
||||||
|
await f();
|
||||||
|
console.log();
|
||||||
|
}), Promise.resolve());
|
||||||
|
|
||||||
// await page.pause();
|
// await page.pause();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
|
|
@ -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
|
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)
|
// 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) 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) {
|
if (cfg.debug_network) {
|
||||||
// const filter = _ => true;
|
// const filter = _ => true;
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,10 @@ export default [
|
||||||
{
|
{
|
||||||
// files: ['*.js'],
|
// files: ['*.js'],
|
||||||
languageOptions: {
|
languageOptions: {
|
||||||
globals: globals.node,
|
globals: {
|
||||||
|
...globals.node,
|
||||||
|
...globals.browser,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
plugins: {
|
plugins: {
|
||||||
'@stylistic/js': stylistic,
|
'@stylistic/js': stylistic,
|
||||||
|
|
|
||||||
|
|
@ -131,6 +131,8 @@ try {
|
||||||
// bottom to top: oldest to newest games
|
// bottom to top: oldest to newest games
|
||||||
internal.reverse();
|
internal.reverse();
|
||||||
external.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 sameOrNewPage = async url => new Promise(async (resolve, _reject) => {
|
||||||
const isNew = page.url() != url;
|
const isNew = page.url() != url;
|
||||||
let p = page;
|
let p = page;
|
||||||
|
|
@ -149,7 +151,7 @@ try {
|
||||||
console.log(' ', await p.locator('.availability-date').innerText(), '->', daysLeft.toFixed(2));
|
console.log(' ', await p.locator('.availability-date').innerText(), '->', daysLeft.toFixed(2));
|
||||||
if (isNew) await p.close();
|
if (isNew) await p.close();
|
||||||
return daysLeft > cfg.pg_timeLeft;
|
return daysLeft > cfg.pg_timeLeft;
|
||||||
}
|
};
|
||||||
console.log('\nNumber of free unclaimed games (Prime Gaming):', internal.length);
|
console.log('\nNumber of free unclaimed games (Prime Gaming):', internal.length);
|
||||||
// claim games in internal store
|
// claim games in internal store
|
||||||
for (const card of internal) {
|
for (const card of internal) {
|
||||||
|
|
@ -300,7 +302,7 @@ try {
|
||||||
if (j?.events?.cart.length && j.events.cart[0]?.data?.reason == 'UserAlreadyOwnsContent') {
|
if (j?.events?.cart.length && j.events.cart[0]?.data?.reason == 'UserAlreadyOwnsContent') {
|
||||||
redeem_action = 'already redeemed';
|
redeem_action = 'already redeemed';
|
||||||
console.error(' error: UserAlreadyOwnsContent');
|
console.error(' error: UserAlreadyOwnsContent');
|
||||||
} else if (true) { // TODO what's returned on success?
|
} else { // TODO what's returned on success?
|
||||||
redeem_action = 'redeemed';
|
redeem_action = 'redeemed';
|
||||||
db.data[user][title].status = 'claimed and 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');
|
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();
|
await loot.waitFor();
|
||||||
|
|
||||||
process.stdout.write('Loading all DLCs on page...');
|
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());
|
console.log('\nNumber of already claimed DLC:', await loot.locator('p:has-text("Collected")').count());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,8 @@ import { FingerprintInjector } from 'fingerprint-injector';
|
||||||
import { FingerprintGenerator } from 'fingerprint-generator';
|
import { FingerprintGenerator } from 'fingerprint-generator';
|
||||||
|
|
||||||
const { fingerprint, headers } = new FingerprintGenerator().getFingerprint({
|
const { fingerprint, headers } = new FingerprintGenerator().getFingerprint({
|
||||||
devices: ["desktop"],
|
devices: ['desktop'],
|
||||||
operatingSystems: ["windows"],
|
operatingSystems: ['windows'],
|
||||||
});
|
});
|
||||||
|
|
||||||
const context = await firefox.launchPersistentContext(cfg.dir.browser, {
|
const context = await firefox.launchPersistentContext(cfg.dir.browser, {
|
||||||
|
|
|
||||||
|
|
@ -12,10 +12,10 @@ function onRawSIGINT(fn) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
console.log(1)
|
console.log(1);
|
||||||
onRawSIGINT(() => {
|
onRawSIGINT(() => {
|
||||||
console.log('raw'); process.exit(1);
|
console.log('raw'); process.exit(1);
|
||||||
});
|
});
|
||||||
console.log(2)
|
console.log(2);
|
||||||
|
|
||||||
// onRawSIGINT workaround for enquirer keeps the process from exiting here...
|
// onRawSIGINT workaround for enquirer keeps the process from exiting here...
|
||||||
|
|
|
||||||
|
|
@ -7,19 +7,19 @@ import { prompt, handleSIGINT } from '../src/util.js';
|
||||||
// });
|
// });
|
||||||
handleSIGINT();
|
handleSIGINT();
|
||||||
|
|
||||||
function onRawSIGINT(fn) {
|
// function onRawSIGINT(fn) {
|
||||||
const { stdin, stdout } = process;
|
// const { stdin, stdout } = process;
|
||||||
stdin.setRawMode(true);
|
// stdin.setRawMode(true);
|
||||||
stdin.resume();
|
// stdin.resume();
|
||||||
stdin.on('data', data => {
|
// stdin.on('data', data => {
|
||||||
const key = data.toString('utf-8');
|
// const key = data.toString('utf-8');
|
||||||
if (key === '\u0003') { // ctrl + c
|
// if (key === '\u0003') { // ctrl + c
|
||||||
fn();
|
// fn();
|
||||||
} else {
|
// } else {
|
||||||
stdout.write(key);
|
// stdout.write(key);
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
// onRawSIGINT(() => {
|
// onRawSIGINT(() => {
|
||||||
// console.log('raw'); process.exit(1);
|
// console.log('raw'); process.exit(1);
|
||||||
// });
|
// });
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue