Advertisement
Chiesonski

scriptSupreme

Apr 14th, 2019
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.00 KB | None | 0 0
  1. //Insert data before "<--"
  2. //LEAVE ' or "
  3.  
  4. (function () {
  5. let keyWord ='+textured';//<--
  6. //Insert keywords which you need to cop the item that you want such as "+work,+pant,-bear"
  7. let categories = ["Jackets", "Coats", "Shirts", "Tops/Sweaters", "Sweatshirts", "Pants", "Shorts", "T-Shirts", "Hats", "Bags", "Accessories", "Shoes", "Skate"]
  8. // 0 -> "Jackets", 1 -> "Coats", 2-> "Shirts", 3 -> "Tops/Sweaters", 4 ->"Sweatshirts", 5->"Pants", 6->"Shorts", 7->"T-Shirts",8-> "Hats", 9->"Bags", 10->"Accessories", 11->"Shoes", 12->"Skate"
  9. let category = categories[3];//<--
  10. //Enter the Number of the category, stated above
  11. let preferredSize = ''//<--
  12. //If you don’t have the size, you will choose the default size
  13. let preferColor = '';//<--
  14. //Insert the colourway, insert "any" for any colour
  15. let autoCheckout = true;//<--
  16. //Insert "true" for automatic check
  17. let checkout_delay = 2500;//<--
  18. //Checkout delay setting, 2500 = 2.5 seconds
  19.  
  20. //-------------+
  21. //Address info |
  22. //-------------+
  23. let billing_name = "lorenzo chiesa";//<--
  24. let order_email = "lo@gmail.com";//<--
  25. let order_tel = "3479773839394";//<--
  26. let order_address = "via dai coglioni 943";//<--
  27. let order_billing_address_2 = "";//<--
  28. let order_billing_zip = "58036";//<--
  29. let order_billing_city = "eudnsk";//<--
  30. let order_billing_state = "CA"; //<--
  31. let order_billing_country = "IT";//<--
  32. // USA, CANADA,EU:GB, FR European countries capitalized abbreviation
  33.  
  34. //-------------+
  35. //Payment info |
  36. //-------------+
  37. let credit_card_type = "master";
  38. //EUROPE:visa, american_express, master, solo
  39. let cnb = "534232djfnd";
  40. //Card numeber
  41. let month = "10";
  42. //Insert data before "<--"
  43. //LEAVE ' or "
  44.  
  45. let year = "2090";
  46. let vval = "040"; //cvv//
  47.  
  48. =======================================================================================================
  49.  
  50. let startTime = null;
  51. let respondJSON = null;
  52. let isNew = true;
  53. let item_selected = false;
  54.  
  55. let mobile_stock_api = "https://www.supremenewyork.com/mobile_stock.json";
  56. let event = document.createEvent('Event');
  57. event.initEvent('change', true, true);
  58.  
  59. let notifyHeader = document.createElement('p');
  60. notifyHeader.style.cssText = "padding-left:120px;margin: auto;width: 100%;background-color: #70de4c;";
  61. let refresh_count = 0;
  62. document.getElementsByTagName('header')[0].appendChild(notifyHeader);
  63.  
  64. let retryFetch = async (url, options=null, retry=0) => {
  65. if (retry >= 4) return Promise.resolve(1);
  66. let res = await fetch(url, options);
  67. if (res.status !== 200) {
  68. await sleep(Math.min(retry * 500, 2 * 1000));
  69. return await retryFetch(url, options, retry + 1);
  70. } else {
  71. return await res.json();
  72. }
  73. };
  74.  
  75. function matchKeyWord (itemName, keyWords) {
  76. let name = itemName.toLowerCase().trim();
  77. let keyWordsList = keyWords.toLowerCase().split(",");
  78. for (let i = 0; i < keyWordsList.length; i ++) {
  79. let word = keyWordsList[i].trim();
  80. if ((word.includes('+') && !name.includes(word.substr(1))) ||
  81. (word.includes('-') && name.includes(word.substr(1)))) {
  82. return false;
  83. }
  84. }
  85. return true;
  86. };
  87.  
  88. let sleep = (ms) => {
  89. return new Promise(resolve => setTimeout(resolve, ms));
  90. };
  91.  
  92. async function mobileAPIRefreshed(respond) {
  93. if (respond['products_and_categories'] == null || respond['products_and_categories']['new'] == null) {
  94. return false;
  95. }
  96. let newProducts = respond['products_and_categories']['new'];
  97. for (let index = 0; index < newProducts.length; index ++) {
  98. let item =newProducts[index];
  99. if (item != null && item['name'] != null && matchKeyWord(item['name'], keyWord)) {
  100. isNew = true;
  101. return true;
  102. }
  103. }
  104.  
  105. let categoryProduct = respond['products_and_categories'][category];
  106. if (categoryProduct != undefined) {
  107. for (let index = 0; index < categoryProduct.length; index ++) {
  108. let item =categoryProduct[index];
  109. if (item != null && item['name'] != null && matchKeyWord(item['name'], keyWord)) {
  110. isNew = false;
  111. return true;
  112. }
  113. }
  114. }
  115. return false;
  116. }
  117.  
  118. async function monitor() {
  119. if (!item_selected) {
  120. notifyHeader.innerHTML = 'Wait new shit...' + refresh_count;
  121. refresh_count ++;
  122. let refreshed = false;
  123.  
  124. let respond = await retryFetch(mobile_stock_api);
  125. refreshed = respond == null ? false : await mobileAPIRefreshed(respond);
  126. if (refreshed) {
  127. respondJSON = respond;
  128. startTime = new Date();
  129. console.log("Detect Page refreshed with mobile endpoint at: " + startTime.toISOString());
  130. notifyHeader.innerHTML = "New items are already online. . . If the page does not jump to the product page, please manually refresh and restart the program"
  131. window.location.href = isNew? 'https://www.supremenewyork.com/mobile/#categories/new' : ('https://www.supremenewyork.com/mobile/#categories/' + category);
  132. await sleep(300);
  133. start();
  134. return;
  135. } else {
  136. console.log("Not refreshed, retrying ...")
  137. await sleep(1000);
  138. await monitor();
  139. return;
  140. }
  141. }
  142. }
  143.  
  144.  
  145. let start = () => {
  146. console.log("start!!");
  147. let items = document.getElementsByClassName("name");
  148. let selectedItem = null;
  149. if (items.length > 0) {
  150. notifyHeader.innerHTML = "Looking for the corresponding item. . . If it doesn't work, please manually click on the product image.";
  151. for (item of items) {
  152. let name = item.innerHTML;
  153.  
  154. if (matchKeyWord(name, keyWord)) {
  155. startTime = new Date().getTime();
  156. selectedItem =item;
  157. selectedItem.click();
  158. break;
  159. }
  160. }
  161.  
  162. if (selectedItem !== null) {
  163. (function waitTillItemClick() {
  164. items = document.getElementsByClassName("name");
  165. if (items.length > 0) {
  166. console.log('wait item click ...');
  167. selectedItem.click();
  168. setTimeout(function(){ waitTillItemClick(); }, 150);
  169. } else {
  170. return;
  171. }
  172. })();
  173. } else {
  174. sleep(50).then(start);
  175. }
  176. } else {
  177. sleep(150).then(start);
  178. }
  179. }
  180.  
  181. (function waitTillArticlePageIsOpen() {
  182. console.log('wait item page ...');
  183. let atcBtn = document.getElementsByClassName("cart-button")[0];
  184. if (atcBtn) {
  185. addToCart();
  186. } else {
  187. setTimeout(function(){ waitTillArticlePageIsOpen(); }, 150);
  188. }
  189. return;
  190. })();
  191.  
  192.  
  193.  
  194. async function addToCart(){
  195. if (document.getElementById('cart-update').children[0].innerHTML === "remove") {
  196. checkout();
  197. return;
  198. }
  199. notifyHeader.innerHTML = "Selecting the color. . .";
  200. await chooseColor();
  201. notifyHeader.innerHTML = "The color selection is complete. . .";
  202. await sleep(70);
  203. notifyHeader.innerHTML = "Selecting the size. . .";
  204. chooseSize();
  205. notifyHeader.innerHTML = "The size is selected. . .";
  206. await sleep(70);
  207. let atcBtn = document.getElementsByClassName("cart-button")[0];
  208. atcBtn.click();
  209. item_selected = true;
  210.  
  211. (function waitTillCartUpdates() {
  212. let cart = document.getElementById("goto-cart-link").innerHTML;
  213. if (cart == '' || cart == 0) {
  214. setTimeout(function(){ waitTillCartUpdates(); }, 150);
  215. return;
  216. } else {
  217. // Click checkout button
  218. notifyHeader.innerHTML = "Already added to the shopping cart";
  219. checkout()
  220. return;
  221. }
  222. })();
  223. }
  224.  
  225.  
  226. async function chooseColor() {
  227. let image;
  228. let url = "/shop/"+window.location.hash.split("/")[1]+".json";
  229. let res = await fetch(url);
  230. let myJson = await res.json();
  231. for (item of myJson.styles){
  232. let color = item.name;
  233. if (checkAvaliability(item.sizes)) {
  234. let id = item.id;
  235. let imageID = "style-"+id;
  236. image = document.getElementById(imageID).getElementsByClassName("style-thumb")[0];
  237. if (color.toLowerCase().includes(preferColor.toLowerCase()) || preferColor.toLowerCase() === 'any') {
  238. image.click();
  239. break;
  240. }
  241. }
  242. }
  243. if (image !== undefined) {
  244. image.click();
  245. }
  246. }
  247.  
  248. function checkAvaliability(sizes) {
  249. for (size of sizes) {
  250. if (size['stock_level'] > 0) {
  251. return true;
  252. }
  253. }
  254. return false;
  255. }
  256.  
  257. function chooseSize(){
  258. let sizeOpts = document.getElementsByTagName("option");
  259. let sizeVal = sizeOpts[0].value
  260. for (let option of sizeOpts){
  261. let size = option.text.toLowerCase();
  262. if (size === preferredSize.toLowerCase() || size === 'N/A'){
  263. sizeVal = option.value;
  264. break;
  265. }
  266. }
  267. sizeOpts = document.getElementsByTagName("select")[0].value = sizeVal;
  268.  
  269. }
  270.  
  271. function checkout(){
  272. window.location.href = 'https://www.supremenewyork.com/mobile/#checkout';
  273. let checkoutBtn = document.getElementById("submit_button");
  274. waitTillCheckoutPageIsOpen();
  275. }
  276.  
  277. async function waitTillCheckoutPageIsOpen() {
  278.  
  279. checkoutBtn = document.getElementById("submit_button");
  280. if (checkoutBtn) {
  281. notifyHeader.innerHTML = "Filling in personal information. . .";
  282. await sleep(50);
  283. document.getElementById("order_billing_name").focus();
  284. document.getElementById("order_billing_name").value = billing_name;
  285.  
  286. await sleep(50);
  287. document.getElementById("order_email").focus();
  288. document.getElementById("order_email").value = order_email;
  289. await sleep(50);
  290. document.getElementById("order_tel").focus();
  291. document.getElementById("order_tel").value = order_tel;
  292. await sleep(50);
  293. document.getElementById("order_billing_address").focus();
  294. document.getElementById("order_billing_address").value = order_address;
  295.  
  296. if (document.getElementById("order_billing_address_2")) {
  297. await sleep(50);
  298. document.getElementById("order_billing_address_2").focus();
  299. document.getElementById("order_billing_address_2").value = order_billing_address_2;
  300. }
  301.  
  302.  
  303. if (document.getElementById("obz")) {
  304. await sleep(50);
  305. document.getElementById("obz").focus();
  306. document.getElementById("obz").value = order_billing_zip;
  307. }
  308. if (document.getElementById("order_billing_zip")) {
  309. await sleep(50);
  310. document.getElementById("order_billing_zip").focus();
  311. document.getElementById("order_billing_zip").value = order_billing_zip;
  312. }
  313. await sleep(50);
  314.  
  315. document.getElementById("order_billing_city").focus();
  316. document.getElementById("order_billing_city").value = order_billing_city;
  317.  
  318. if (document.getElementById("order_billing_country")) {
  319. await sleep(50);
  320. document.getElementById("order_billing_country").value = order_billing_country;
  321. document.getElementById("order_billing_country").dispatchEvent(event);
  322. }
  323.  
  324. if (document.getElementById("order_billing_state")) {
  325. await sleep(50);
  326. document.getElementById("order_billing_state").focus();
  327. document.getElementById("order_billing_state").value = order_billing_state;
  328. document.getElementById("order_billing_state").dispatchEvent(event);
  329. }
  330.  
  331. if (document.getElementById("credit_card_type")) {
  332. await sleep(50);
  333. document.getElementById("credit_card_type").value = credit_card_type;
  334. document.getElementById("credit_card_type").dispatchEvent(event);
  335. }
  336. if (document.getElementById("credit_card_n")) {
  337. await sleep(50);
  338. document.getElementById("credit_card_n").focus();
  339. document.getElementById("credit_card_n").value = cnb;
  340. }
  341. if (document.getElementById("credit_card_month")) {
  342. await sleep(50);
  343. document.getElementById("credit_card_month").focus();
  344. document.getElementById("credit_card_month").value = month;
  345. document.getElementById("credit_card_month").dispatchEvent(event);
  346. }
  347. if (document.getElementById("credit_card_year")) {
  348. await sleep(50);
  349. document.getElementById("credit_card_year").focus();
  350. document.getElementById("credit_card_year").value = year;
  351. document.getElementById("credit_card_year").dispatchEvent(event);
  352. }
  353. if (document.getElementById("cav")) {
  354. await sleep(50);
  355. document.getElementById("cav").focus();
  356. document.getElementById("cav").value = vval;
  357. }
  358. if (document.getElementById("credit_card_cvv")) {
  359. await sleep(50);
  360. document.getElementById("credit_card_cvv").focus();
  361. document.getElementById("credit_card_cvv").value = vval;
  362. }
  363.  
  364. await sleep(50);
  365. document.getElementById("order_terms").click();
  366.  
  367. notifyHeader.innerHTML = "Fill out, please checkout. . .";
  368. if (autoCheckout){
  369. notifyHeader.innerHTML = "Automatic checkout. . .";
  370. await sleep(checkout_delay);
  371. document.getElementById("hidden_cursor_capture").click();
  372. }
  373. console.log('paymentTime: ' + (new Date().getTime() - startTime) + ' ms');
  374. notifyHeader.remove();
  375. return;
  376. } else {
  377. setTimeout(async function(){ await waitTillCheckoutPageIsOpen(); }, 200);
  378. console.log("waiting to Chekcout...");
  379. }
  380. }
  381.  
  382. monitor()
  383. })()
  384.  
  385. completion()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement