-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
91 lines (64 loc) · 2.92 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
const { spawn } = require('child_process');
const { chromium } = require ('playwright');
//Update browser path to use the desired browser
const browserPath = '/Applications/Brave Browser.app/Contents/MacOS/Brave Browser';
const browserProcess = spawn(browserPath, ['--remote-debugging-port=9222'], { detached: true });
const wait = ms => new Promise(resolve => setTimeout(resolve, ms));
(async () => {
await wait(3000);
let isGetSticker = true;
let isGetCard = true;
process.argv.forEach( arg => {
if (arg === '-c') //Only get card
isGetSticker = false;
if (arg === '-s') //Only get sticker
isGetCard = false;
}
);
const browser = await chromium.connectOverCDP('http://localhost:9222', {
headless: false,
});
const defaultContext = browser.contexts()[0];
const page = defaultContext.pages()[0];
if (isGetSticker) {
await page.goto('https://store.steampowered.com/category/action');
//Get sticker button
const button = "#SaleSection_512062 > div > div > button";
await page.waitForLoadState("load");
await page.locator(button).click();
//Close button
const closeButton = "body > div.FullModalOverlay > div.ModalOverlayContent.active > div > div > div.DialogContent._DialogLayout.GenericConfirmDialog._DialogCenterVertically > div > form > div.DialogBody.Panel.Focusable > div.DialogFooter > button"
await page.locator(closeButton).click();
}
if (isGetCard) {
await page.goto('https://store.steampowered.com');
//Open queue
const selector = "#discovery_queue_start_link";
await page.locator(selector).click();
await page.waitForLoadState("load");
//10 times for queue length
for (let i = 0; i < 12; i++) {
//Next button
const nextButton = "#nextInDiscoveryQueue > div.btn_next_in_queue.btn_next_in_queue_trigger";
//Next button for age restriction
const nextButtonForAge = "#app_agegate > div.main_content_ctn > div.agegate_text_container.btns > div > a.btn_next_in_queue.btn_next_in_queue_trigger > div";
await page.waitForLoadState("load");
await wait(2000);
const button = page.locator(nextButton);
try {
await button.waitFor({
timeout: 1000,
});
await page.click(nextButton);
} catch (e) {
await page.click(nextButtonForAge);
}
}
}
//One more wait for the road
await wait(2000);
await page.close();
await defaultContext.close();
await browser.close();
process.kill(-browserProcess.pid, 'SIGTERM');
})();