-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathNeweggBot.js
139 lines (128 loc) · 3.8 KB
/
NeweggBot.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
const puppeteer = require('puppeteer')
const config = require('./config.json')
async function report (log) {
currentTime = new Date();
console.log(currentTime.toString().split('G')[0] + ': ' + log)
}
async function check_cart (page) {
await page.waitForTimeout(250)
try {
await page.waitForSelector('span.amount' , { timeout: 1000 })
var element = await page.$('span.amount')
var text = await page.evaluate(element => element.textContent, element);
if (parseInt(text.split('$')[1]) > config.price_limit) {
await report("Price exceeds limit, removing from cart")
var button = await page.$$('button.btn.btn-mini');
while (true) {
try {
await button[1].click()
} catch (err) {
break
}
}
return false
}
await report("Card added to cart, attempting to purchase")
return true
} catch (err) {
await report("Card not in stock")
await page.waitForTimeout(config.refresh_time * 1000)
return false
}
}
async function run () {
await report("Started")
const browser = await puppeteer.launch({
headless: false,
product: 'firefox',
defaultViewport: { width: 1366, height: 768 }
})
const page = await browser.newPage()
while (true) {
await page.goto('https://secure.newegg.com/NewMyAccount/AccountLogin.aspx?nextpage=https%3a%2f%2fwww.newegg.com%2f' , {waitUntil: 'load' })
if (page.url().includes('signin')) {
await page.waitForSelector('button.btn.btn-orange')
await page.type('#labeled-input-signEmail', config.email)
await page.click('button.btn.btn-orange')
await page.waitForTimeout(1500)
try {
await page.waitForSelector('#labeled-input-signEmail', {timeout: 500})
} catch (err) {
try {
await page.waitForSelector('#labeled-input-password' , {timeout: 2500})
await page.waitForSelector('button.btn.btn-orange')
await page.type('#labeled-input-password', config.password)
await page.click('button.btn.btn-orange')
await page.waitForTimeout(1500)
try {
await page.waitForSelector('#labeled-input-password', {timeout: 500})
} catch (err) {
break
}
} catch (err) {
report("Manual authorization code required by Newegg. This should only happen once.")
while (page.url().includes('signin'))
{
await page.waitForTimeout(500)
}
break
}
}
} else if (page.url().includes("areyouahuman")) {
await page.waitForTimeout(1000)
}
}
await report("Logged in")
await report("Checking for card")
while (true)
{
try {
await page.goto('https://secure.newegg.com/Shopping/AddtoCart.aspx?Submit=ADD&ItemList=' + config.item_number, { waitUntil: 'load' })
if (page.url().includes("ShoppingCart")) {
var check = await check_cart(page)
if (check) {
break
}
} else if (page.url().includes("ShoppingItem")) {
await page.goto('https://secure.newegg.com/Shopping/ShoppingCart.aspx', { waitUntil: 'load' })
var check = await check_cart(page)
if (check){
break
}
} else if (page.url().includes("areyouahuman")) {
await page.waitForTimeout(1000)
}
} catch (err) {
continue
}
}
try {
await page.goto('javascript:attachDelegateEvent((function(){Biz.GlobalShopping.ShoppingCart.checkOut(\'True\')}))', {timeout: 500})
} catch (err) {
}
while (true) {
try {
await page.waitForSelector('#cvv2Code' , {timeout: 500})
await page.type('#cvv2Code', config.cv2)
break
} catch (err) {
}
try {
await page.waitForSelector('#creditCardCVV2' , {timeout: 500})
await page.type('#creditCardCVV2', config.cv2)
break
} catch (err) {
}
}
try {
await page.waitForSelector('#term' , {timeout: 5000})
await page.click('#term')
} catch (err) {
}
if (config.auto_submit == 'true') {
await page.click('#SubmitOrder')
}
await report("Completed purchase")
//await browser.close()
}
run()