Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Nike Bot v.1.0.1
- // @namespace http://tampermonkey.net/
- // @version 1.0.1
- // @description try to take over the world!
- // @author You
- // @match https://www.nike.com/pl/launch/t/air-max-97-plus-black-white
- // @grant none
- // ==/UserScript==
- // @description: Use developer mode of Chrome.
- // array of sizes you need to buy
- let iWant = [44.5, 46, 47, 40];
- // your card informations for payment
- let cardInfo = {
- cardNumber: "xxxx xxxx xxxx xxxx",
- expirationDate: "xx/xx",
- cvvNumber: "xxx"
- };
- let dropDate = {
- hour: 8, minutes: 59
- };
- //flags
- let firstButtonClicked = false;
- let hasBeenAdded = false;
- let sendOrder = false;
- let clicked = 0;
- // end flags
- //time
- var getSystemDate = function () {
- var date = new Date();
- this.hour = date.getHours();
- this.minutes = date.getMinutes();
- };
- function compareTime() {
- var systemDate = new getSystemDate();
- if((systemDate.hour >= dropDate.hour) || (systemDate.hour === dropDate.hour && systemDate.minutes === dropDate.minutes)) {
- return 1;
- } else {
- console.log(systemDate);
- return 0;
- }
- }
- //waiting for first button
- function waitForFirstButton () {
- let firstButtonLoaded = setInterval(function() {
- if(document.querySelectorAll(".js-size-btn")[0]) {
- let firstButton = document.querySelectorAll(".js-size-btn")[0];
- firstButton.click();
- clearInterval(firstButtonLoaded);
- console.log("firstButton has been detected...");
- firstButtonClicked = true;
- } else {
- console.log("firstButton is not detected...");
- }
- }, 100);
- }
- function getSize (sizeEU) {
- let size = parseFloat(sizeEU.replace("EU ", ""));
- return size;
- }
- function outOfStock () {
- let outOfStockSizing = [];
- let list = document.querySelectorAll(".disabled");
- for (let i = 0; i < list.length; i++) {
- let sizeEU = list[i].innerText;
- let size = getSize(sizeEU);
- outOfStockSizing[i] = size;
- }
- return outOfStockSizing;
- }
- // checking sizes in stock, compare with outOfStock
- function inStock() {
- let inStockSizing = [];
- let list = document.querySelectorAll(".size");
- for (let i = 0; i < list.length; i++) {
- let sizeEU = list[i].innerText;
- let size = getSize(sizeEU);
- if (outOfStock().indexOf(size) < 0) {
- inStockSizing.push(size);
- }
- }
- return inStockSizing;
- }
- // look for my sizing in stock
- function checkInStock (size) {
- for (let i = 0; i < inStock().length; i++) {
- if (size === inStock()[i]) {
- return true;
- }
- } return false;
- }
- // add to cart module
- function addToCart() {
- let list = document.querySelectorAll(".size");
- let addToCartButton = document.querySelector(".js-buy");
- if(iWant.length) {
- for (let i = 0; i < iWant.length; i++) {
- for (let j = 0; j < list.length; j++) {
- let sizeEU = list[j].innerText;
- let size = getSize(sizeEU);
- //console.log(size);
- if (iWant[i] === size && checkInStock(size) === true && hasBeenAdded === false) {
- console.log("I'm adding: " + size + " to cart...");
- list[j].click();
- addToCartButton.click();
- hasBeenAdded = true;
- } else if (hasBeenAdded){
- console.log("I have added to cart...");
- break;
- } else {
- //console.log("Nie udało się zakupić..." + size);
- }
- }
- }
- if(hasBeenAdded === false) {
- console.log("Size out of stock...");
- location.reload();
- }
- } else {
- console.log("You haven't set sizes...");
- }
- }
- function payment() {
- if(document.querySelector(".credit-card-iframe")) {
- let forceInterval = setInterval(function() {
- let continueButton = document.querySelectorAll(".js-save-button")[2];
- if( continueButton.classList[15] === "disabled") {
- let iFrameBox = document.querySelector(".credit-card-iframe").contentDocument;
- let cvNumber = iFrameBox.querySelector("#cvNumber");
- simulate(cvNumber, "focus");
- cvNumber.value = cardInfo.cvvNumber;
- simulate(cvNumber, "blur");
- console.log("I'm setting cvv...");
- } else {
- console.log("continueButton is active...");
- continueButton.click();
- clearInterval(forceInterval);
- }
- }, 250);
- } else {
- if (document.querySelector(".js-creditcard")) {
- document.querySelector(".js-creditcard").click();
- let forceInterval = setInterval(function() {
- let continueButton = document.querySelectorAll(".js-save-button")[2];
- if( continueButton.classList[15] === "disabled") {
- if(document.querySelector(".credit-card-iframe")) {
- let iFrameBox = document.querySelector(".credit-card-iframe").contentDocument;
- let cardNumber = iFrameBox.querySelector("#creditCardNumber");
- let expirationDate = iFrameBox.querySelector("#expirationDate");
- let cvNumber = iFrameBox.querySelector("#cvNumber");
- simulate(cardNumber, "focus");
- cardNumber.value = cardInfo.cardNumber;
- simulate(cardNumber, "blur");
- simulate(expirationDate, "focus");
- expirationDate.value = cardInfo.expirationDate;
- simulate(expirationDate, "blur");
- simulate(cvNumber, "focus");
- cvNumber.value = cardInfo.cvvNumber;
- simulate(cvNumber, "blur");
- console.log("Payment informations has been filled...");
- continueButton.click();
- } else {
- console.log("No payment IFRAME");
- }
- } else {
- console.log("continueButton is active...");
- continueButton.click();
- clearInterval(forceInterval);
- }
- }, 250);
- } else {
- console.log("Button has been clicked before...");
- }
- }
- }
- function simulate(element, eventName) {
- var options = extend(defaultOptions, arguments[2] || {});
- var oEvent, eventType = null;
- for (var name in eventMatchers) {
- if (eventMatchers[name].test(eventName)) { eventType = name; break; }
- }
- if (!eventType)
- throw new SyntaxError('Only HTMLEvents and MouseEvents interfaces are supported');
- if (document.createEvent) {
- oEvent = document.createEvent(eventType);
- if (eventType == 'HTMLEvents') {
- oEvent.initEvent(eventName, options.bubbles, options.cancelable);
- } else {
- oEvent.initMouseEvent(eventName, options.bubbles, options.cancelable, document.defaultView,
- options.button, options.pointerX, options.pointerY, options.pointerX, options.pointerY,
- options.ctrlKey, options.altKey, options.shiftKey, options.metaKey, options.button, element);
- }
- element.dispatchEvent(oEvent);
- } else {
- options.clientX = options.pointerX;
- options.clientY = options.pointerY;
- var evt = document.createEventObject();
- oEvent = extend(evt, options);
- element.fireEvent('on' + eventName, oEvent);
- }
- return element;
- }
- function extend(destination, source) {
- for (var property in source)
- destination[property] = source[property];
- return destination;
- }
- var eventMatchers = {
- 'HTMLEvents': /^(?:load|unload|abort|error|select|change|submit|reset|focus|blur|resize|scroll)$/,
- 'MouseEvents': /^(?:click|dblclick|mouse(?:down|up|over|move|out))$/
- };
- var defaultOptions = {
- pointerX: 0,
- pointerY: 0,
- button: 0,
- ctrlKey: false,
- altKey: false,
- shiftKey: false,
- metaKey: false,
- bubbles: true,
- cancelable: true
- };
- window.addEventListener("load", function(e) {
- let interval = setInterval(function(){
- getSystemDate();
- if(compareTime() && !(document.getElementsByClassName("js-buy")[0])) {
- console.log("I'm waiting for drop...");
- clearInterval(interval);
- location.reload();
- } else if ( compareTime() && document.getElementsByClassName("js-buy")[0]) {
- console.log("Done. I'm working...");
- waitForFirstButton();
- let addInterval = setInterval(function() {
- if (firstButtonClicked) {
- setTimeout(addToCart, 200);
- clearInterval(addInterval);
- console.log("addInterval stopped...");
- let paymentInterval = setInterval(function(){
- if(hasBeenAdded && (document.querySelector(".credit-card-iframe") || document.querySelector(".js-creditcard"))) {
- setTimeout(payment, 100);
- console.log("PaymentInterval stopped...");
- let finalButtonInterval = setInterval(function () {
- if (document.querySelectorAll(".js-save-button")[3]) {
- let finalButton = document.querySelectorAll(".js-save-button")[3];
- finalButton.click();
- clicked++;
- console.log("finalButtonInterval stopped...");
- } else if (clicked > 2 && document.querySelectorAll(".js-save-button")[3]){
- clearInterval(finalButtonInterval);
- } else {
- console.log("FinalButton error...");
- }
- }, 100);
- clearInterval(paymentInterval);
- }
- }, 100);
- }
- }, 100);
- clearInterval(interval);
- } else {
- console.log("I'm waiting for start time...");
- }
- }, 5000);
- }, false);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement