Browse Source

Add module script

master
KaKi87 2 months ago
parent
commit
a2459ec27f
  1. 49
      main.js
  2. 49
      mod.js
  3. 2
      package.json

49
main.js

@ -1,42 +1,9 @@
const
puppeteer = require('puppeteer'),
totp = require('totp-generator');
const run = require('./mod.js');
(async () => {
const
browser = await puppeteer.launch({
headless: false,
defaultViewport: null,
args: ['--start-maximized']
}),
page = await (await browser.createIncognitoBrowserContext()).newPage();
await page.goto(`https://gaming.amazon.com/loot/${process.env.LOOT_ID}`);
const steps = [
async () => await (await page.waitForSelector('[data-a-target="AvailableButton"]')).click(),
async () => await (await page.waitForSelector('[data-a-target="gms-info-container"] [data-a-target="sign-in-button"]')).click(),
async () => await (await page.waitForSelector('input[type="email"]')).type(process.env.EMAIL),
async () => await page.type('input[type="password"]', process.env.PASSWORD),
async () => await page.click('input[type="submit"]'),
async () => await (await page.waitForSelector('input[type="tel"]')).type(totp(process.env.TOTP)),
async () => await page.click('input[type="submit"]'),
async () => await (await page.waitForSelector('[data-a-target="gms-cta"]')).click(),
async () => await page.waitForSelector('.gms-success-modal-container')
].map((step, index, { length }) => async () => {
console.log(`Running step ${index+1}/${length}`);
await step();
});
for(let i = 0; i < steps.length; i++){
const
currentStep = steps[i],
previousStep = steps[i-1];
try {
await currentStep();
}
catch {
if(previousStep)
try { await previousStep(); } catch {}
await currentStep();
}
}
await browser.close();
})();
run({
lootId: process.env.LOOT_ID,
email: process.env.EMAIL,
password: process.env.PASSWORD,
totpKey: process.env.TOTP,
onStep: (index, length) => console.log(`Running step ${index+1}/${length}`)
}).then(() => console.log('Done')).catch(console.error);

49
mod.js

@ -0,0 +1,49 @@
const
puppeteer = require('puppeteer'),
totp = require('totp-generator');
module.exports = async ({
lootId,
email,
password,
totpKey,
onStep
}) => {
const
browser = await puppeteer.launch({
headless: false,
defaultViewport: null,
args: ['--start-maximized']
}),
page = await (await browser.createIncognitoBrowserContext()).newPage();
await page.goto(`https://gaming.amazon.com/loot/${lootId}`);
const steps = [
async () => await (await page.waitForSelector('[data-a-target="AvailableButton"]')).click(),
async () => await (await page.waitForSelector('[data-a-target="gms-info-container"] [data-a-target="sign-in-button"]')).click(),
async () => await (await page.waitForSelector('input[type="email"]')).type(email),
async () => await page.type('input[type="password"]', password),
async () => await page.click('input[type="submit"]'),
async () => await (await page.waitForSelector('input[type="tel"]')).type(totp(totpKey)),
async () => await page.click('input[type="submit"]'),
async () => await (await page.waitForSelector('[data-a-target="gms-cta"]')).click(),
async () => await page.waitForSelector('.gms-success-modal-container')
].map((step, index, { length }) => async () => {
if(onStep)
onStep(index, length);
await step();
});
for(let i = 0; i < steps.length; i++){
const
currentStep = steps[i],
previousStep = steps[i-1];
try {
await currentStep();
}
catch {
if(previousStep)
try { await previousStep(); } catch {}
await currentStep();
}
}
await browser.close();
};

2
package.json

@ -1,7 +1,7 @@
{
"name": "primegaming-loot-autocollect",
"version": "0.1.0",
"main": "main.js",
"main": "mod.js",
"repository": "ssh://kaki@git.kaki87.net:3021/KaKi87/primegraming-lol-autocollect.git",
"author": "KaKi87 <KaKi87@pm.me>",
"license": "WTFPL",

Loading…
Cancel
Save