* Format and fix sonar issues
This commit is contained in:
parent
16cb194216
commit
617229f659
3 changed files with 35 additions and 43 deletions
|
|
@ -96,7 +96,7 @@ Available options/variables and their default values:
|
||||||
| STEAM_PASSWORD | | Steam password for login. Overrides PASSWORD. |
|
| STEAM_PASSWORD | | Steam password for login. Overrides PASSWORD. |
|
||||||
| STEAM_JSON | 0 | Claims steam games from json. STEAM_JSON_URL can be defined. |
|
| STEAM_JSON | 0 | Claims steam games from json. STEAM_JSON_URL can be defined. |
|
||||||
| STEAM_JSON_URL | [steam-games.json](https://raw.githubusercontent.com/vogler/free-games-claimer/main/steam-games.json) | A list of steam urls in json format to claim the games. |
|
| STEAM_JSON_URL | [steam-games.json](https://raw.githubusercontent.com/vogler/free-games-claimer/main/steam-games.json) | A list of steam urls in json format to claim the games. |
|
||||||
| STEAM_GAMERPOWER | 1 | Claims steam games using [gamerpower api](https://www.gamerpower.com/api/giveaways?platform=steam&type=game). |
|
| STEAM_GAMERPOWER | 0 | Claims steam games using [gamerpower api](https://www.gamerpower.com/api/giveaways?platform=steam&type=game). |
|
||||||
|
|
||||||
|
|
||||||
See `config.js` for all options.
|
See `config.js` for all options.
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ export const cfg = {
|
||||||
|
|
||||||
steam_username: process.env.STEAM_USERNAME,
|
steam_username: process.env.STEAM_USERNAME,
|
||||||
steam_password: process.env.STEAM_PASSWORD || process.env.PASSWORD,
|
steam_password: process.env.STEAM_PASSWORD || process.env.PASSWORD,
|
||||||
steam_json: false || process.env.STEAM_JSON == '1',
|
steam_json: process.env.STEAM_JSON == '1',
|
||||||
steam_json_url: process.env.STEAM_JSON_URL || 'https://raw.githubusercontent.com/vogler/free-games-claimer/main/steam-games.json',
|
steam_json_url: process.env.STEAM_JSON_URL || 'https://raw.githubusercontent.com/vogler/free-games-claimer/main/steam-games.json',
|
||||||
steam_gamerpower: true || process.env.STEAM_GAMERPOWER == '1',
|
steam_gamerpower: process.env.STEAM_GAMERPOWER == '1',
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ import { resolve, jsonDb, datetime, prompt, stealth, notify, html_game_list, han
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { existsSync, writeFileSync } from 'fs';
|
import { existsSync, writeFileSync } from 'fs';
|
||||||
import { cfg } from './config.js';
|
import { cfg } from './config.js';
|
||||||
import { config } from 'dotenv';
|
|
||||||
|
|
||||||
const screenshot = (...a) => resolve(cfg.dir.screenshots, 'steam', ...a);
|
const screenshot = (...a) => resolve(cfg.dir.screenshots, 'steam', ...a);
|
||||||
|
|
||||||
|
|
@ -22,11 +21,10 @@ const context = await firefox.launchPersistentContext(cfg.dir.browser, {
|
||||||
// channel: 'chrome', // https://playwright.dev/docs/browsers#google-chrome--microsoft-edge
|
// channel: 'chrome', // https://playwright.dev/docs/browsers#google-chrome--microsoft-edge
|
||||||
headless: false,
|
headless: false,
|
||||||
viewport: { width: cfg.width, height: cfg.height },
|
viewport: { width: cfg.width, height: cfg.height },
|
||||||
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.83 Safari/537.36', // see replace of Headless in util.newStealthContext. TODO Windows UA enough to avoid 'device not supported'? update if browser is updated?
|
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.83 Safari/537.36',
|
||||||
// userAgent for firefox: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:106.0) Gecko/20100101 Firefox/106.0
|
|
||||||
locale: "en-US", // ignore OS locale to be sure to have english text for locators
|
locale: "en-US", // ignore OS locale to be sure to have english text for locators
|
||||||
recordVideo: cfg.record ? { dir: 'data/record/', size: { width: cfg.width, height: cfg.height } } : undefined, // will record a .webm video for each page navigated; without size, video would be scaled down to fit 800x800
|
recordVideo: cfg.record ? { dir: 'data/record/', size: { width: cfg.width, height: cfg.height } } : undefined,
|
||||||
recordHar: cfg.record ? { path: `data/record/eg-${datetime()}.har` } : undefined, // will record a HAR file with network requests and responses; can be imported in Chrome devtools
|
recordHar: cfg.record ? { path: `data/record/eg-${datetime()}.har` } : undefined,
|
||||||
args: [ // https://peter.sh/experiments/chromium-command-line-switches
|
args: [ // https://peter.sh/experiments/chromium-command-line-switches
|
||||||
// don't want to see bubble 'Restore pages? Chrome didn't shut down correctly.'
|
// don't want to see bubble 'Restore pages? Chrome didn't shut down correctly.'
|
||||||
// '--restore-last-session', // does not apply for crash/killed
|
// '--restore-last-session', // does not apply for crash/killed
|
||||||
|
|
@ -66,10 +64,8 @@ async function doLogin(){
|
||||||
}
|
}
|
||||||
const auth = await page.getByText('You have a mobile authenticator protecting this account.').first();
|
const auth = await page.getByText('You have a mobile authenticator protecting this account.').first();
|
||||||
let isFirstCheck = true;
|
let isFirstCheck = true;
|
||||||
while (await auth.isVisible())
|
while (await auth.isVisible()) {
|
||||||
{
|
if (isFirstCheck) {
|
||||||
if (isFirstCheck)
|
|
||||||
{
|
|
||||||
console.log("Steam requires confirmation from authenticator");
|
console.log("Steam requires confirmation from authenticator");
|
||||||
notify(`Steam requires confirmation from authenticator`);
|
notify(`Steam requires confirmation from authenticator`);
|
||||||
isFirstCheck = false;
|
isFirstCheck = false;
|
||||||
|
|
@ -108,11 +104,9 @@ async function claimJson(){
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
if (!await isClaimedUrl(item.url)) {
|
if (!await isClaimedUrl(item.url)) {
|
||||||
console.log(item);
|
console.log(item);
|
||||||
if (item.hasOwnProperty("startDate"))
|
if (item.hasOwnProperty("startDate")) {
|
||||||
{
|
|
||||||
const date = Date.parse(item.startDate);
|
const date = Date.parse(item.startDate);
|
||||||
if (date >= Date.now())
|
if (date >= Date.now()) {
|
||||||
{
|
|
||||||
console.log("game not available yet " + new Date(date));
|
console.log("game not available yet " + new Date(date));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -154,13 +148,11 @@ async function claimGame(url){
|
||||||
notify_games.push(notify_game); // status is updated below
|
notify_games.push(notify_game); // status is updated below
|
||||||
|
|
||||||
const alreadyOwned = await page.locator('.game_area_already_owned').first();
|
const alreadyOwned = await page.locator('.game_area_already_owned').first();
|
||||||
if (await alreadyOwned.isVisible())
|
if (await alreadyOwned.isVisible()) {
|
||||||
{
|
|
||||||
console.log("Game " + title + " already in library");
|
console.log("Game " + title + " already in library");
|
||||||
db.data[user][game_id].status ||= 'existed'; // does not overwrite claimed or failed
|
db.data[user][game_id].status ||= 'existed'; // does not overwrite claimed or failed
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
await page.locator(('#freeGameBtn')).click();
|
await page.locator(('#freeGameBtn')).click();
|
||||||
console.log("purchased");
|
console.log("purchased");
|
||||||
db.data[user][game_id].status = 'claimed';
|
db.data[user][game_id].status = 'claimed';
|
||||||
|
|
@ -176,7 +168,7 @@ async function isClaimedUrl(url) {
|
||||||
const pattern = "/app/";
|
const pattern = "/app/";
|
||||||
let game_id = url.substring(url.indexOf(pattern) + pattern.length);
|
let game_id = url.substring(url.indexOf(pattern) + pattern.length);
|
||||||
game_id = game_id.substring(0, game_id.indexOf("/"));
|
game_id = game_id.substring(0, game_id.indexOf("/"));
|
||||||
var status = db.data[user][game_id]["status"];
|
const status = db.data[user][game_id]["status"];
|
||||||
return status === "existed" || status === "claimed";
|
return status === "existed" || status === "claimed";
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue