Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //屠龙0.0.1
  2. var keyWord = '+Guadalupe';
  3. var categories = ["Jackets", "Coats", "Shirts", "Tops/Sweaters", "Sweatshirts", "Pants", "Shorts", "T-Shirts", "Hats", "Bags", "Accessories", "Shoes", "Skate"]
  4. // 0 -> "Jackets", 1 -> "Coats", 2-> "Shirts", 3 -> "Tops/Sweaters", 4 ->"Sweatshirts", 5->"Pants", 6->"Shorts", 7->"T-Shirts",
  5. //8-> "Hats", 9->"Bags", 10->"Accessories", 11->"Shoes", 12->"Skate"
  6. var category = categories[12] ;
  7. var preferredSize = 'M'
  8. var preferColor = 'Orange';
  9. var autoCheckout = true;
  10. var checkout_delay = 2500;
  11.  
  12. //Address info
  13. var billing_name = "John Doe";
  14. var order_email = "john-doe@gmx.ch";
  15. var order_tel = "0041771234545";
  16. var order_address = "Strasse 123";
  17. var order_billing_address_2 = "";
  18. var order_billing_zip = "1234";
  19. var order_billing_city = "Basel";
  20. var order_billing_state = "";
  21. var order_billing_country = "CH"; // USA, CANADA, EU:GB, FR
  22.  
  23. //Payment info
  24. var credit_card_type = "master";
  25. // 欧洲:visa, american_express, master, solo
  26. // 日本:visa, american_express, master, jcb, cod
  27. var cnb = "1234";
  28. var month = "12";
  29. var year = "2020";
  30. var vval = "123";
  31.  
  32. var startTime = null;
  33. var respondJSON = null;
  34. var isNew = true;
  35.  
  36. var mobile_stock_api = "https://www.supremenewyork.com/mobile_stock.json";
  37.  
  38. var event = document.createEvent('Event');
  39. event.initEvent('change', true, true);
  40.  
  41. var retryFetch = async (url, options=null, retry=0) => {
  42.     if (retry >= 4) return Promise.resolve(1);
  43.     let res = await fetch(url, options);
  44.     if (res.status !== 200) {
  45.         await sleep(Math.min(retry * 500, 2 * 1000));
  46.         return await retryFetch(url, options, retry + 1);
  47.     } else {
  48.         return await res.json();
  49.     }
  50. };
  51.  
  52. function matchKeyWord (itemName, keyWords) {
  53.     let name = itemName.toLowerCase().trim();
  54.     let keyWordsList = keyWords.toLowerCase().split(",");
  55.     for (let i = 0; i < keyWordsList.length; i ++) {
  56.         let word = keyWordsList[i].trim();
  57.         if ((word.includes('+') && !name.includes(word.substr(1))) ||
  58.             (word.includes('-') && name.includes(word.substr(1)))) {
  59.             return false;
  60.         }
  61.     }
  62.     return true;
  63. };
  64.  
  65. var sleep = (ms) => {
  66.     return new Promise(resolve => setTimeout(resolve, ms));
  67. };
  68.  
  69. async function mobileAPIRefreshed(respond) {
  70.     if (respond['products_and_categories'] == null || respond['products_and_categories']['new'] == null) {
  71.         return false;
  72.     }
  73.     let newProducts = respond['products_and_categories']['new'];
  74.     for (let index = 0; index < newProducts.length; index ++) {
  75.         let item =newProducts[index];
  76.         if (item != null && item['name'] != null && matchKeyWord(item['name'], keyWord)) {
  77.             isNew = true;
  78.             return true;
  79.         }
  80.     }
  81.  
  82.     let categoryProduct = respond['products_and_categories'][category];
  83.     if (categoryProduct != undefined) {
  84.         for (let index = 0; index < categoryProduct.length; index ++) {
  85.             let item =categoryProduct[index];
  86.             if (item != null && item['name'] != null && matchKeyWord(item['name'], keyWord)) {
  87.                 isNew = false;
  88.                 return true;
  89.             }
  90.         }
  91.     }
  92.     return false;
  93. }
  94.  
  95. async function monitor() {
  96.     refreshed = false;
  97.        
  98.     let respond = await retryFetch(mobile_stock_api);
  99.     refreshed = respond == null ? false : await mobileAPIRefreshed(respond);
  100.     if (refreshed) {
  101.         respondJSON = respond;
  102.         startTime = new Date();
  103.         console.log("Detect Page refreshed with mobile endpoint at: " + startTime.toISOString());
  104.         window.location.href = isNew? 'https://www.supremenewyork.com/mobile/#categories/new' : ('https://www.supremenewyork.com/mobile/#categories/' + category);
  105.         sleep(150).then(() => start());
  106.     } else {
  107.         console.log("Not refreshed, retrying ...")
  108.         await sleep(1000);
  109.         await monitor();
  110.     }
  111. }
  112.  
  113.  
  114. var start = () => {
  115.     var items = document.getElementsByClassName("name");
  116.     if (items.length > 0) {
  117.  
  118.         for (item of items) {
  119.             var name = item.innerHTML;
  120.  
  121.             if (matchKeyWord(name, keyWord)) {
  122.                 startTime = new Date().getTime();
  123.                 sleep(200).then(() => item.click());
  124.                 break;
  125.             }
  126.         }
  127.  
  128.         (function waitTillArticlePageIsOpen() {
  129.             let atcBtn = document.getElementsByClassName("cart-button")[0];
  130.             // check if article page has loaded by looking at main image
  131.             if (atcBtn) {
  132.                 addToCart();
  133.             } else
  134.                 setTimeout(function(){ waitTillArticlePageIsOpen(); }, 150);
  135.  
  136.             return;
  137.         })();
  138.     } else {
  139.         setTimeout(function(){ start(); }, 150);
  140.     }
  141. }
  142.  
  143.  
  144.  
  145. async function addToCart(){
  146.     if (document.getElementById('cart-update').children[0].innerHTML === "remove") {
  147.         checkout();
  148.         return;
  149.     }
  150.     await chooseColor();
  151.     await sleep(200);
  152.     chooseSize();
  153.     await sleep(200);
  154.     let atcBtn = document.getElementsByClassName("cart-button")[0];
  155.     atcBtn.click();
  156.    
  157.     (function waitTillCartUpdates() {
  158.         let cart = document.getElementById("goto-cart-link").innerHTML;
  159.         if (cart == '' || cart == 0) {
  160.             setTimeout(function(){ waitTillCartUpdates(); }, 150);
  161.             return;
  162.         } else {
  163.             // Click checkout button
  164.             checkout()
  165.             return;
  166.         }
  167.     })();
  168. }
  169.  
  170.  
  171. async function chooseColor() {
  172.     var id;
  173.     var url = "/shop/"+window.location.hash.split("/")[1]+".json";
  174.     let res = await fetch(url);
  175.     let myJson = await res.json();
  176.     for (item of myJson.styles){
  177.         let color = item.name;
  178.         if (color.toLowerCase().includes(preferColor.toLowerCase())) {
  179.             var id = item.id;
  180.             let imageID = "style-"+id;
  181.             let image = document.getElementById(imageID).getElementsByClassName("style-thumb")[0];    
  182.             image.click();
  183.             break;
  184.         }
  185.     }
  186.  
  187.  
  188. }
  189.  
  190. function chooseSize(){
  191.     var sizeOpts = document.getElementsByTagName("option");
  192.     var sizeVal = sizeOpts[0].value
  193.     for (let option of sizeOpts){
  194.         let size = option.text.toLowerCase();
  195.         if (size === preferredSize.toLowerCase() || size === 'N/A'){
  196.             sizeVal =  option.value;
  197.             break;
  198.         }
  199.     }
  200.     var sizeOpts = document.getElementsByTagName("select")[0].value = sizeVal;
  201.  
  202. }
  203.  
  204. function checkout(){
  205.     window.location.href = 'https://www.supremenewyork.com/mobile/#checkout';
  206.     var checkoutBtn = document.getElementById("submit_button");
  207.     waitTillCheckoutPageIsOpen();
  208. }
  209.  
  210. async function waitTillCheckoutPageIsOpen() {
  211.  
  212.     checkoutBtn = document.getElementById("submit_button");
  213.     if (checkoutBtn) {
  214.         await sleep(70);
  215.         document.getElementById("order_billing_name").focus();
  216.         document.getElementById("order_billing_name").value = billing_name;
  217.  
  218.         await sleep(70);
  219.         document.getElementById("order_email").focus();
  220.         document.getElementById("order_email").value = order_email;
  221.         await sleep(70);
  222.         document.getElementById("order_tel").focus();
  223.         document.getElementById("order_tel").value = order_tel;
  224.         await sleep(70);
  225.         document.getElementById("order_billing_address").focus();
  226.         document.getElementById("order_billing_address").value = order_address;
  227.  
  228.         if (document.getElementById("order_billing_address_2")) {
  229.             await sleep(70);
  230.             document.getElementById("order_billing_address_2").focus();
  231.             document.getElementById("order_billing_address_2").value = order_billing_address_2;
  232.         }
  233.    
  234.  
  235.         if (document.getElementById("obz")) {
  236.             await sleep(70);
  237.             document.getElementById("obz").focus();
  238.             document.getElementById("obz").value = order_billing_zip;
  239.         }
  240.         if (document.getElementById("order_billing_zip")) {
  241.             await sleep(70);
  242.             document.getElementById("order_billing_zip").focus();
  243.             document.getElementById("order_billing_zip").value = order_billing_zip;
  244.         }
  245.         await sleep(70);
  246.  
  247.         document.getElementById("order_billing_city").focus();
  248.         document.getElementById("order_billing_city").value = order_billing_city;
  249.  
  250.         if (document.getElementById("order_billing_country")) {
  251.             await sleep(70);
  252.             document.getElementById("order_billing_country").value = order_billing_country;
  253.             document.getElementById("order_billing_country").dispatchEvent(event);
  254.         }
  255.  
  256.         if (document.getElementById("order_billing_state")) {
  257.             await sleep(70);
  258.             document.getElementById("order_billing_state").focus();
  259.             document.getElementById("order_billing_state").value = order_billing_state;
  260.             document.getElementById("order_billing_state").dispatchEvent(event);
  261.         }
  262.    
  263.         if (document.getElementById("credit_card_type")) {
  264.             await sleep(70);
  265.             document.getElementById("credit_card_type").value = credit_card_type;
  266.             document.getElementById("credit_card_type").dispatchEvent(event);
  267.         }
  268.         if (document.getElementById("credit_card_n")) {
  269.             await sleep(70);
  270.             document.getElementById("credit_card_n").focus();
  271.             document.getElementById("credit_card_n").value = cnb;
  272.         }
  273.         if (document.getElementById("credit_card_month")) {
  274.             await sleep(70);
  275.             document.getElementById("credit_card_month").focus();
  276.             document.getElementById("credit_card_month").value = month;
  277.             document.getElementById("credit_card_month").dispatchEvent(event);
  278.         }
  279.         if (document.getElementById("credit_card_year")) {
  280.             await sleep(70);
  281.             document.getElementById("credit_card_year").focus();
  282.             document.getElementById("credit_card_year").value = year;
  283.             document.getElementById("credit_card_year").dispatchEvent(event);
  284.         }
  285.         if (document.getElementById("cav")) {
  286.             await sleep(70);
  287.             document.getElementById("cav").focus();
  288.             document.getElementById("cav").value = vval;
  289.         }
  290.         if (document.getElementById("credit_card_cvv")) {
  291.             await sleep(70);
  292.             document.getElementById("credit_card_cvv").focus();
  293.             document.getElementById("credit_card_cvv").value = vval;
  294.         }
  295.  
  296.         await sleep(70);      
  297.         document.getElementById("order_terms").click();
  298.         if (autoCheckout){
  299.             await sleep(checkout_delay);
  300.             document.getElementById("hidden_cursor_capture").click();
  301.         }
  302.         console.log('paymentTime: ' + (new Date().getTime() - startTime) + ' ms');
  303.         return;
  304.     } else {
  305.         setTimeout(async function(){ await waitTillCheckoutPageIsOpen(); }, 200);
  306.         console.log("waiting to Chekcout...");
  307.     }
  308. }
  309.  
  310. monitor()
  311.  
  312. completion()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement