Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.52 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Nike Bot v.1.0.1
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0.1
  5. // @description try to take over the world!
  6. // @author You
  7. // @match https://www.nike.com/pl/launch/t/air-max-97-plus-black-white
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11.  
  12. // @description: Use developer mode of Chrome.
  13.  
  14. // array of sizes you need to buy
  15. let iWant = [44.5, 46, 47, 40];
  16.  
  17. // your card informations for payment
  18. let cardInfo = {
  19. cardNumber: "xxxx xxxx xxxx xxxx",
  20. expirationDate: "xx/xx",
  21. cvvNumber: "xxx"
  22. };
  23.  
  24. let dropDate = {
  25. hour: 8, minutes: 59
  26. };
  27.  
  28. //flags
  29. let firstButtonClicked = false;
  30. let hasBeenAdded = false;
  31. let sendOrder = false;
  32. let clicked = 0;
  33. // end flags
  34.  
  35. //time
  36.  
  37. var getSystemDate = function () {
  38. var date = new Date();
  39. this.hour = date.getHours();
  40. this.minutes = date.getMinutes();
  41. };
  42. function compareTime() {
  43. var systemDate = new getSystemDate();
  44. if((systemDate.hour >= dropDate.hour) || (systemDate.hour === dropDate.hour && systemDate.minutes === dropDate.minutes)) {
  45. return 1;
  46. } else {
  47. console.log(systemDate);
  48. return 0;
  49. }
  50. }
  51.  
  52. //waiting for first button
  53. function waitForFirstButton () {
  54. let firstButtonLoaded = setInterval(function() {
  55. if(document.querySelectorAll(".js-size-btn")[0]) {
  56. let firstButton = document.querySelectorAll(".js-size-btn")[0];
  57. firstButton.click();
  58. clearInterval(firstButtonLoaded);
  59. console.log("firstButton has been detected...");
  60. firstButtonClicked = true;
  61. } else {
  62. console.log("firstButton is not detected...");
  63. }
  64. }, 100);
  65. }
  66.  
  67. function getSize (sizeEU) {
  68. let size = parseFloat(sizeEU.replace("EU ", ""));
  69. return size;
  70. }
  71.  
  72. function outOfStock () {
  73. let outOfStockSizing = [];
  74. let list = document.querySelectorAll(".disabled");
  75. for (let i = 0; i < list.length; i++) {
  76. let sizeEU = list[i].innerText;
  77. let size = getSize(sizeEU);
  78. outOfStockSizing[i] = size;
  79. }
  80. return outOfStockSizing;
  81. }
  82.  
  83. // checking sizes in stock, compare with outOfStock
  84. function inStock() {
  85. let inStockSizing = [];
  86. let list = document.querySelectorAll(".size");
  87. for (let i = 0; i < list.length; i++) {
  88. let sizeEU = list[i].innerText;
  89. let size = getSize(sizeEU);
  90. if (outOfStock().indexOf(size) < 0) {
  91. inStockSizing.push(size);
  92. }
  93. }
  94. return inStockSizing;
  95. }
  96.  
  97. // look for my sizing in stock
  98. function checkInStock (size) {
  99. for (let i = 0; i < inStock().length; i++) {
  100. if (size === inStock()[i]) {
  101. return true;
  102. }
  103. } return false;
  104. }
  105.  
  106.  
  107. // add to cart module
  108. function addToCart() {
  109. let list = document.querySelectorAll(".size");
  110. let addToCartButton = document.querySelector(".js-buy");
  111. if(iWant.length) {
  112. for (let i = 0; i < iWant.length; i++) {
  113. for (let j = 0; j < list.length; j++) {
  114. let sizeEU = list[j].innerText;
  115. let size = getSize(sizeEU);
  116. //console.log(size);
  117. if (iWant[i] === size && checkInStock(size) === true && hasBeenAdded === false) {
  118. console.log("I'm adding: " + size + " to cart...");
  119. list[j].click();
  120. addToCartButton.click();
  121. hasBeenAdded = true;
  122. } else if (hasBeenAdded){
  123. console.log("I have added to cart...");
  124. break;
  125. } else {
  126. //console.log("Nie udało się zakupić..." + size);
  127. }
  128. }
  129. }
  130. if(hasBeenAdded === false) {
  131. console.log("Size out of stock...");
  132. location.reload();
  133. }
  134. } else {
  135. console.log("You haven't set sizes...");
  136. }
  137. }
  138.  
  139. function payment() {
  140. if(document.querySelector(".credit-card-iframe")) {
  141. let forceInterval = setInterval(function() {
  142. let continueButton = document.querySelectorAll(".js-save-button")[2];
  143. if( continueButton.classList[15] === "disabled") {
  144. let iFrameBox = document.querySelector(".credit-card-iframe").contentDocument;
  145. let cvNumber = iFrameBox.querySelector("#cvNumber");
  146. simulate(cvNumber, "focus");
  147. cvNumber.value = cardInfo.cvvNumber;
  148. simulate(cvNumber, "blur");
  149. console.log("I'm setting cvv...");
  150. } else {
  151. console.log("continueButton is active...");
  152. continueButton.click();
  153. clearInterval(forceInterval);
  154. }
  155. }, 250);
  156. } else {
  157. if (document.querySelector(".js-creditcard")) {
  158. document.querySelector(".js-creditcard").click();
  159. let forceInterval = setInterval(function() {
  160. let continueButton = document.querySelectorAll(".js-save-button")[2];
  161. if( continueButton.classList[15] === "disabled") {
  162. if(document.querySelector(".credit-card-iframe")) {
  163. let iFrameBox = document.querySelector(".credit-card-iframe").contentDocument;
  164. let cardNumber = iFrameBox.querySelector("#creditCardNumber");
  165. let expirationDate = iFrameBox.querySelector("#expirationDate");
  166. let cvNumber = iFrameBox.querySelector("#cvNumber");
  167. simulate(cardNumber, "focus");
  168. cardNumber.value = cardInfo.cardNumber;
  169. simulate(cardNumber, "blur");
  170. simulate(expirationDate, "focus");
  171. expirationDate.value = cardInfo.expirationDate;
  172. simulate(expirationDate, "blur");
  173. simulate(cvNumber, "focus");
  174. cvNumber.value = cardInfo.cvvNumber;
  175. simulate(cvNumber, "blur");
  176. console.log("Payment informations has been filled...");
  177. continueButton.click();
  178. } else {
  179. console.log("No payment IFRAME");
  180. }
  181. } else {
  182. console.log("continueButton is active...");
  183. continueButton.click();
  184. clearInterval(forceInterval);
  185. }
  186. }, 250);
  187. } else {
  188. console.log("Button has been clicked before...");
  189. }
  190. }
  191. }
  192.  
  193. function simulate(element, eventName) {
  194. var options = extend(defaultOptions, arguments[2] || {});
  195. var oEvent, eventType = null;
  196.  
  197. for (var name in eventMatchers) {
  198. if (eventMatchers[name].test(eventName)) { eventType = name; break; }
  199. }
  200.  
  201. if (!eventType)
  202. throw new SyntaxError('Only HTMLEvents and MouseEvents interfaces are supported');
  203.  
  204. if (document.createEvent) {
  205. oEvent = document.createEvent(eventType);
  206. if (eventType == 'HTMLEvents') {
  207. oEvent.initEvent(eventName, options.bubbles, options.cancelable);
  208. } else {
  209. oEvent.initMouseEvent(eventName, options.bubbles, options.cancelable, document.defaultView,
  210. options.button, options.pointerX, options.pointerY, options.pointerX, options.pointerY,
  211. options.ctrlKey, options.altKey, options.shiftKey, options.metaKey, options.button, element);
  212. }
  213. element.dispatchEvent(oEvent);
  214. } else {
  215. options.clientX = options.pointerX;
  216. options.clientY = options.pointerY;
  217. var evt = document.createEventObject();
  218. oEvent = extend(evt, options);
  219. element.fireEvent('on' + eventName, oEvent);
  220. }
  221. return element;
  222. }
  223.  
  224. function extend(destination, source) {
  225. for (var property in source)
  226. destination[property] = source[property];
  227. return destination;
  228. }
  229.  
  230. var eventMatchers = {
  231. 'HTMLEvents': /^(?:load|unload|abort|error|select|change|submit|reset|focus|blur|resize|scroll)$/,
  232. 'MouseEvents': /^(?:click|dblclick|mouse(?:down|up|over|move|out))$/
  233. };
  234.  
  235. var defaultOptions = {
  236. pointerX: 0,
  237. pointerY: 0,
  238. button: 0,
  239. ctrlKey: false,
  240. altKey: false,
  241. shiftKey: false,
  242. metaKey: false,
  243. bubbles: true,
  244. cancelable: true
  245. };
  246.  
  247.  
  248. window.addEventListener("load", function(e) {
  249. let interval = setInterval(function(){
  250. getSystemDate();
  251. if(compareTime() && !(document.getElementsByClassName("js-buy")[0])) {
  252. console.log("I'm waiting for drop...");
  253. clearInterval(interval);
  254. location.reload();
  255. } else if ( compareTime() && document.getElementsByClassName("js-buy")[0]) {
  256. console.log("Done. I'm working...");
  257. waitForFirstButton();
  258. let addInterval = setInterval(function() {
  259. if (firstButtonClicked) {
  260. setTimeout(addToCart, 200);
  261. clearInterval(addInterval);
  262. console.log("addInterval stopped...");
  263. let paymentInterval = setInterval(function(){
  264. if(hasBeenAdded && (document.querySelector(".credit-card-iframe") || document.querySelector(".js-creditcard"))) {
  265. setTimeout(payment, 100);
  266. console.log("PaymentInterval stopped...");
  267. let finalButtonInterval = setInterval(function () {
  268. if (document.querySelectorAll(".js-save-button")[3]) {
  269. let finalButton = document.querySelectorAll(".js-save-button")[3];
  270. finalButton.click();
  271. clicked++;
  272. console.log("finalButtonInterval stopped...");
  273. } else if (clicked > 2 && document.querySelectorAll(".js-save-button")[3]){
  274. clearInterval(finalButtonInterval);
  275. } else {
  276. console.log("FinalButton error...");
  277. }
  278. }, 100);
  279. clearInterval(paymentInterval);
  280. }
  281. }, 100);
  282. }
  283. }, 100);
  284. clearInterval(interval);
  285. } else {
  286. console.log("I'm waiting for start time...");
  287. }
  288. }, 5000);
  289. }, false);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement