-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgpuBot.js
156 lines (148 loc) · 4.85 KB
/
gpuBot.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
// import puppeteer from "puppeteer";
const puppeteer = require("puppeteer");
require("dotenv").config();
// uncomment below once it is ready to mount as chrome extension
const init = document.querySelector(".start");
let urlLink = document.getElementById("url");
let notifEl = document.querySelector(".notification");
// add URL here
const gpu_URL =
"https://www.bestbuy.com/site/insignia-8-oz-cleaning-dusters-2-pack/8045009.p?skuId=8045009";
// DOM needs to load and go to the product page
const startBrowser = async (url) => {
const browser = await puppeteer.launch({
headless: false,
defaultViewport: { width: 1366, height: 768 },
});
const page = await browser.newPage();
await page.goto(url);
return page;
};
const addToCart = async (page) => {
await page.waitForTimeout(3000);
try {
console.log("Adding item to cart");
notifEl.innerHTML = `Adding item to cart`;
await page.$eval(
"[class='btn btn-primary btn-lg btn-block btn-leading-ficon add-to-cart-button']",
(element) => {
element.click();
}
);
await page.waitForTimeout(2000);
// another page to add to go to cart
console.log("Adding item to cart");
notifEl.innerHTML = `Adding item to cart`;
await page.$eval(
"[class='btn btn-secondary btn-sm btn-block ']",
(element) => element.click()
);
await page.waitForTimeout(2500);
console.log("Checking out");
notifEl.innerHTML = `Checking out`;
await page.$eval("[class='btn btn-lg btn-block btn-primary']", (element) =>
element.click()
);
await page.waitForTimeout(3500);
console.log("proceeding as guest");
notifEl.innerHTML = `proceeding as guest`;
await page.$eval(
"[class='btn btn-secondary btn-lg cia-guest-content__continue guest']",
(element) => element.click()
);
await page.waitForTimeout(3000);
notifEl.innerHTML = `add to cart function successfull proceeding to filling up info`;
} catch (error) {
console.log(error + " out of stock");
notifEl.innerHTML = `out of stock - reloading page`;
await page.reload();
await addToCart(page);
}
};
const fillInfo = async (page) => {
await page.waitForTimeout(3000);
try {
notifEl.innerHTML = `filling up info`;
await page.waitForTimeout(2000);
// personal info section
await page.type(
"[id='consolidatedAddresses.ui_address_2.firstName']",
process.env.NAME
);
await page.type(
"[id='consolidatedAddresses.ui_address_2.lastName']",
process.env.LASTNAME
);
await page.type(
"[id='consolidatedAddresses.ui_address_2.street']",
process.env.STADDRESS
);
await page.type(
"[id='consolidatedAddresses.ui_address_2.city']",
process.env.CITY
);
await page.select(
"[id='consolidatedAddresses.ui_address_2.state']",
process.env.STATE
);
await page.type(
"[id='consolidatedAddresses.ui_address_2.zipcode']",
process.env.ZIP
);
await page.type("[id='user.emailAddress']", process.env.EMAIL);
await page.type("[id='user.phone']", process.env.PHONE);
await page.waitForTimeout(1000);
await page.$eval(
"[class='btn btn-lg btn-block btn-secondary']",
(element) => element.click()
);
notifEl.innerHTML = `success proceeding to adding card info`;
// end personal info and go to credit card page
} catch (error) {
console.log("running fill info again");
notifEl.innerHTML = `running fill info again - reloading`;
await page.reload();
await fillInfo(page);
}
};
const fillCard = async (page) => {
try {
await page.waitForTimeout(3000);
console.log("filling up credit");
notifEl.innerHTML = `filling up credit information`;
// fake credit card info selected and checks out the item
await page.type("[id='optimized-cc-card-number']", process.env.CREDIT);
await page.waitForTimeout(1500);
await page.select("[name='expiration-month']", process.env.MONTH);
await page.select("[name='expiration-year']", process.env.YEAR);
await page.type("[id='credit-card-cvv']", process.env.CVV);
await page.waitForTimeout(1000);
await page.$eval("[class='btn btn-lg btn-block btn-primary']", (element) =>
element.click()
);
notifEl.innerHTML = `congrats purchase Complete`;
} catch (error) {
console.log("running fill card info again");
notifEl.innerHTML = `running fill card info again`;
await page.reload();
await fillCard(page);
}
};
// start to start the scalping
init.addEventListener("click", function (e) {
e.preventDefault();
notifEl.innerHTML = `${urlLink.value}`;
console.log(urlLink.value);
testInit(urlLink.value);
});
const testInit = async (link) => {
try {
const page = await startBrowser(link);
await addToCart(page);
await fillInfo(page);
await fillCard(page);
} catch (error) {
console.log(error);
}
};
// testInit();