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 { 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, {
|
||||
|
|
@ -21,11 +21,11 @@ const context = await firefox.launchPersistentContext(cfg.dir.browser, {
|
|||
handleSIGINT: false, // have to handle ourselves and call context.close(), otherwise recordings from above won't be saved
|
||||
userAgent: fingerprint.navigator.userAgent,
|
||||
viewport: {
|
||||
width: fingerprint.screen.width,
|
||||
height: fingerprint.screen.height,
|
||||
width: fingerprint.screen.width,
|
||||
height: fingerprint.screen.height,
|
||||
},
|
||||
extraHTTPHeaders: {
|
||||
'accept-language': headers['accept-language'],
|
||||
'accept-language': headers['accept-language'],
|
||||
},
|
||||
});
|
||||
handleSIGINT(context);
|
||||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -15,7 +15,10 @@ export default [
|
|||
{
|
||||
// files: ['*.js'],
|
||||
languageOptions: {
|
||||
globals: globals.node,
|
||||
globals: {
|
||||
...globals.node,
|
||||
...globals.browser,
|
||||
},
|
||||
},
|
||||
plugins: {
|
||||
'@stylistic/js': stylistic,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -145,11 +147,11 @@ try {
|
|||
const [p, isNew] = await sameOrNewPage(url);
|
||||
const dueDateOrg = await p.locator('.availability-date .tw-bold').innerText();
|
||||
const dueDate = new Date(Date.parse(dueDateOrg + ' 17:00'));
|
||||
const daysLeft = (dueDate.getTime() - Date.now())/1000/60/60/24;
|
||||
const daysLeft = (dueDate.getTime() - Date.now()) / 1000 / 60 / 60 / 24;
|
||||
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());
|
||||
|
||||
|
|
|
|||
|
|
@ -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, {
|
||||
|
|
@ -22,11 +22,11 @@ const context = await firefox.launchPersistentContext(cfg.dir.browser, {
|
|||
locale: 'en-US', // ignore OS locale to be sure to have english text for locators -> done via /en in URL
|
||||
userAgent: fingerprint.navigator.userAgent,
|
||||
viewport: {
|
||||
width: fingerprint.screen.width,
|
||||
height: fingerprint.screen.height,
|
||||
width: fingerprint.screen.width,
|
||||
height: fingerprint.screen.height,
|
||||
},
|
||||
extraHTTPHeaders: {
|
||||
'accept-language': headers['accept-language'],
|
||||
'accept-language': headers['accept-language'],
|
||||
},
|
||||
});
|
||||
// await stealth(context);
|
||||
|
|
|
|||
|
|
@ -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...
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
// });
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue