Skip to content

Commit f713d77

Browse files
committedDec 28, 2017
sizes
1 parent 95df6cc commit f713d77

File tree

7 files changed

+109
-56
lines changed

7 files changed

+109
-56
lines changed
 

‎README.md

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,45 +9,42 @@ Autofill script for hot stores
99

1010
### Configure
1111
`config.json` (./config.json)
12+
* **proxy**: Set up the proxy.
1213
* **userAgent**: Customize your user agent which you want to use during autocheckout.
1314
* **gCookies**: An array of cookies, do not leave empty, it will cause program to crash. See this repo for explanation on how to build the array. Used properly this will let you through captcha without solving 10 times.
1415

15-
**kith.com** (shopId:1003)
16+
**kith.com** `1003`
1617
`kith_com.json` (./shops/configs/kith_com.json)
17-
* **size**: Select size which you want to checkout (this option is not supported yet).
18+
* **sizes**: Select sizes which you want to checkout with priority by order.
19+
* **strictSizes**: Do not buy checkout if not matched in sizes.
1820
* **pauseBetweenSteps**: Pause between steps (ms).
1921
* **customerInformation**: Information you want to use in autofill.
2022
+ **paymentMethod**: 1 = PayPal, 2 = Card (it is not necessary to fill in an unused method).
2123

22-
**supremenewyork.com** (shopId:6026)
24+
**supremenewyork.com** `6026`
2325
`supremenewyork_com.json` (./shops/configs/supremenewyork_com.json)
24-
* **size**: Select size which you want to checkout (this option is not supported yet).
26+
* **sizes**: Select sizes which you want to checkout with priority by order.
27+
* **strictSizes**: Do not buy checkout if not matched in sizes.
2528
* **pauseBetweenSteps**: Pause between steps (ms).
2629
* **gmail**: Setting up the login to a gmail account before starting an autofill (entry to gmail reduces the likelihood of captcha).
2730
+ **enabled**: use/not use.
2831
* **customerInformation**: Information you want to use in autofill.
29-
+ **paymentMethod**: 1 = Visa (Card), 2 = American Express (Card), 3 = Mastercard (Card), 4 = Solo (Card), 5 = Paypal (it is not necessary to fill in an unused method).
32+
+ **paymentMethod**: 1 = Visa, 2 = American Express, 3 = Mastercard, 4 = Solo, 5 = Paypal (it is not necessary to fill in an unused method).
3033

3134
### Proxy
3235
The script supports the following proxy format: { hostPort: "xxx.xxx.xxx.xxx:xxxx", login: "login", password: "password" }.
3336

3437
### Launching (Step by step)
35-
<ul>
36-
<li>1. If not installed, install [node.js] https://nodejs.org/</li>
37-
<li>2. If not installed, install [npm] https://www.npmjs.com/</li>
38-
<li>3. Open command prompt and go to the project location</li>
39-
<li>4. Install packages with command: npm install [package]
40-
<ul>
41-
<li>[nightmare]</li>
42-
<li>[nightmare-iframe-manager]</li>
43-
<li>[lodash]</li>
44-
<li>[util]</li>
45-
</ul></li>
46-
<li>5. Configure [shop].json which you want to use</li>
47-
<li>6. Run script with commands:
48-
<ul>
49-
<li>node sb_autocheckout.js [shopId] [link]</li>
50-
<li>node sb_autocheckout.js [shopId] [link] [proxy]</li>
51-
<li>node sb_autocheckout.js [shopId] [link] [proxy] [size]</li>
52-
</ul></li>
53-
</ul>
38+
* 1. If not installed, install [node.js](https://nodejs.org/)
39+
* 2. If not installed, install [npm](https://www.npmjs.com/)
40+
* 3. Open command prompt and go to the project location
41+
* 4. Install packages with command: npm install `package`
42+
+ `nightmare`
43+
+ `nightmare-iframe-manager`
44+
+ `lodash`
45+
+ `util`
46+
* 5. Configure `shop`.json which you want to use
47+
* 6. Run script with commands:
48+
+ node sb_autocheckout.js `shopId` `link`
49+
+ node sb_autocheckout.js `shopId` `link` `proxy`
50+
+ node sb_autocheckout.js `shopId` `link` `proxy` `size`

‎config.json

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
{
2-
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36",
3-
"gCookies": [
4-
{
5-
"domain": ".google.com",
6-
"name": "def",
7-
"value": "456"
8-
}
9-
]
2+
"proxy": null,
3+
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36",
4+
"gCookies": [{
5+
"domain": ".google.com",
6+
"name": "def",
7+
"value": "456"
8+
}]
109
}

‎sb_autocheckout.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,20 @@ Nightmare.action('clearCache',
4343
this.child.call('clearCache', done);
4444
});
4545

46+
Array.prototype._diff = function (arr2) {
47+
for (let i in this) {
48+
if (arr2.indexOf(this[i].text) > -1)
49+
return this[i].value;
50+
}
51+
};
52+
4653
(function readArgs() {
4754
let args = process.argv.splice(2);
4855

4956
let shopId = null;
5057
let link = null;
51-
let proxy = null;
52-
let size = null;
58+
let proxy = config.proxy;
59+
let sizes = null;
5360
switch (args.length) {
5461
case 2:
5562
shopId = args[0];
@@ -58,20 +65,20 @@ Nightmare.action('clearCache',
5865
case 3:
5966
shopId = args[0];
6067
link = args[1];
61-
proxy = args[2];
68+
proxy = args[2] || proxy;
6269
break;
6370
case 4:
6471
shopId = args[0];
6572
link = args[1];
66-
proxy = args[2];
67-
size = args[3];
73+
proxy = args[2] || proxy;
74+
sizes = args[3];
6875
break;
6976
}
7077

71-
openBrowser(shopId, link, proxy, size);
78+
openBrowser(shopId, link, proxy, sizes);
7279
})();
7380

74-
function openBrowser(shopId, link, proxy, size) {
81+
function openBrowser(shopId, link, proxy, sizes) {
7582
let checkoutBrowser = Nightmare({
7683
show: true,
7784
alwaysOnTop: false,
@@ -87,7 +94,7 @@ function openBrowser(shopId, link, proxy, size) {
8794
.clearCache()
8895
.cookies.set(cookieTransform(config.gCookies));
8996

90-
let shop = new __shops(size).getShop(shopId);
97+
let shop = new __shops(sizes).getShop(shopId);
9198

9299
setTimeout(function () {
93100
checkoutBrowser

‎shops/configs/kith_com.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
2-
"size": "8",
3-
"pauseBetweenSteps": 2000,
2+
"sizes": ["15"],
3+
"strictSizes": true,
4+
"pauseBetweenSteps": 5000,
45
"customerInformation": {
56
"email": "example@gmail.com",
67
"firstName": "firstName",

‎shops/configs/supremenewyork_com.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
2-
"size": "Medium",
3-
"pauseBetweenSteps": 2000,
2+
"sizes": ["Small", "XLarge"],
3+
"strictSizes": true,
4+
"pauseBetweenSteps": 5000,
45
"gmail": {
56
"enabled": false,
67
"email" : "example@gmail.com",

‎shops/kith_com.js

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,55 @@
11
class kith_com {
2-
constructor(size) {
2+
constructor(sizes) {
33
this.id = 1003;
44
this.homePage = 'kith.com';
55
this.shopConfig = require('./configs/kith_com.json');
6-
this.size = size || this.shopConfig.size;
6+
this.sizes = sizes || this.shopConfig.sizes;
77
this.steps = [];
88

99
//1
10+
this.steps.push(function (self, browser) {
11+
let sizeValue;
12+
browser
13+
.evaluate(function () {
14+
var options = [];
15+
$('#productSelect-option-0').children().each(function (index) {
16+
options.push({
17+
'text': $(this).text(),
18+
'value': $(this).attr('value')
19+
});
20+
});
21+
return options;
22+
})
23+
.then(function (options) {
24+
sizeValue = options._diff(self.sizes);
25+
26+
if (!sizeValue && self.shopConfig.strictSizes)
27+
throw 'Specified size not found';
28+
29+
return sizeValue ? browser
30+
.select('#productSelect-option-0', sizeValue)
31+
.click('#AddToCart')
32+
.catch(function (error) {
33+
console.error(util.inspect(error));
34+
}) :
35+
browser
36+
.click('#AddToCart')
37+
.catch(function (error) {
38+
console.error(util.inspect(error));
39+
});
40+
});
41+
});
42+
43+
//2
44+
this.steps.push(function (self, browser) {
45+
browser
46+
.click('.btn.btn--full.cart-checkout')
47+
.catch(function (error) {
48+
console.error(util.insert(error));
49+
});
50+
});
51+
52+
//3
1053
this.steps.push(function (self, browser) {
1154
browser
1255
.insert('#checkout_email', self.shopConfig.customerInformation.email)
@@ -25,7 +68,7 @@ class kith_com {
2568
});
2669
});
2770

28-
//2
71+
//4
2972
this.steps.push(function (self, browser) {
3073
browser
3174
.click('.step__footer__continue-btn.btn')
@@ -34,7 +77,7 @@ class kith_com {
3477
});
3578
});
3679

37-
//3
80+
//5
3881
this.steps.push(function (self, browser) {
3982
switch (self.shopConfig.customerInformation.paymentMethod) {
4083
case 1:
@@ -70,7 +113,7 @@ class kith_com {
70113
});
71114

72115
if (this.shopConfig.customerInformation.paymentMethod === 2) {
73-
//4
116+
//6?
74117
this.steps.push(function (self, browser) {
75118
browser
76119
.insert('#email', '')
@@ -82,7 +125,7 @@ class kith_com {
82125
});
83126
});
84127

85-
//5
128+
//7?
86129
this.steps.push(function (self, browser) {
87130
browser
88131
.click('#confirmButtonTop')

‎shops/supremenewyork_com.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
class supremenewyork_com {
2-
constructor(size) {
2+
constructor(sizes) {
33
this.id = 6026;
44
this.homePage = 'supremenewyork.com';
55
this.shopConfig = require('./configs/supremenewyork_com.json');
6-
this.size = size || this.shopConfig.size;
6+
this.sizes = sizes || this.shopConfig.sizes;
77
this.steps = [];
88

99
if (this.shopConfig.gmail.enabled) {
@@ -62,13 +62,18 @@ class supremenewyork_com {
6262
return options;
6363
})
6464
.then(function (options) {
65-
sizeValue = options.find(function (element) {
66-
return element.text == self.size;
67-
}).value;
65+
sizeValue = options._diff(self.sizes);
6866

69-
return browser
67+
if (!sizeValue && self.shopConfig.strictSizes)
68+
throw 'Specified size not found';
69+
70+
return sizeValue ? browser
7071
.select('#size', sizeValue)
7172
.click('input[value="add to basket"]')
73+
.catch(function (error) {
74+
console.error(util.inspect(error));
75+
}) : browser
76+
.click('input[value="add to basket"]')
7277
.catch(function (error) {
7378
console.error(util.inspect(error));
7479
});

0 commit comments

Comments
 (0)
Please sign in to comment.