Advertisement
Guest User

Untitled

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