forked from raphaelcastaneda/NeweggBot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
NeweggBot.js
186 lines (168 loc) · 5.86 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
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('li.summary-content-total span' , { timeout: 1000 })
var element = await page.$('li.summary-content-total span')
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-secondary');
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)
//await page.waitForTimeout((config.refresh_time + (Math.random() * config.refresh_time * 2)) * 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)
{
//await page.waitForTimeout((config.refresh_time + (Math.random() * config.refresh_time * 2)) * 1000)
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) {
await report(err)
continue
}
}
try {
await page.waitForSelector('button#Masks_addtocart.btn.btn-primary' , {timeout: 10000})
await page.click('button.btn[data-dismiss="modal"]')
await report('Skipped stupid mask advert')
}catch(err) {
await report('when skipping mask')
await report(err)
}
try {
await page.click('button.btn.btn-primary.btn-wide');
await report('Clicked checkout')
//await page.goto('javascript:attachDelegateEvent((function(){Biz.GlobalShopping.ShoppingCart.checkOut(\'True\')}))', {timeout: 500})
} catch (err) {
await report('when skipping going to checkout')
await report(err)
}
try {
await page.waitForSelector('div.checkout-step[data-status="add"] button.checkout-step-action-done' , {timeout: 5000, visible: true})
await page.click('div.checkout-step[data-status="add"] button.checkout-step-action-done')
//await page.evaluate(() => {
// document.getElementsByClassName('checkout-step-action')[1].children[0].click()
//} while (document.getElementsByClassName('btn btn-primary checkout-step-action-done layout-quarter')[1].textContent != 'Save ')
//});
await report('Clicked continue to payment')
} catch (err) {
await report('when going to payment')
await report(err)
}
while (true) {
try {
await page.waitForSelector('#cvv2Code' , {timeout: 500})
await page.type('#cvv2Code', config.cv2)
await report('ccv method 1')
break
} catch (err) {
}
try {
await page.waitForSelector('input.form-text.mask-cvv-4' , {timeout: 500})
await page.type('input.form-text.mask-cvv-4', config.cv2)
await report('ccv method 2')
break
} catch (err) {
}
}
await report('ccv typed')
try {
await new Promise(resolve => setTimeout(resolve, 2000));
await page.waitForSelector('div.checkout-step[data-status="add"] button.checkout-step-action-done' , {timeout: 5000, visible: true})
await page.click('div.checkout-step[data-status="add"] button.checkout-step-action-done')
await report('Clicked continue to review')
} catch (err) {
await report('when going to review')
await report(err)
}
//try {
// await page.waitForSelector('#term' , {timeout: 5000})
// await page.click('#term')
//} catch (err) {
//}
if (config.auto_submit == 'true') {
await page.click('#btnCreditCard')
await report('Clicked place order')
}
await report("Completed purchase")
//await browser.close()
}
run()