Advertisement
Guest User

Untitled

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