9blok0 / Amazon

// ==UserScript==
// @name         Amazon
// @version      0.1
// @author       9blok0
// @licence      MIT
// @match        https://www.amazon.com/gp/prime/pipeline/membersignup*
// @match        https://www.amazon.com/ap/register*
// @require      http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    var Email = new EmailGen();
    $("#ap_customer_name").val(Email);
    $("#ap_email").val(Email);
    $("#ap_password").val(Email);
    $("#ap_password_check").val(Email);
    $("#continue").trigger('click');
     //card
    var completed = false;
    $('input[name="ppw-accountHolderName"]').attr('value', nameGen());
    while (completed === false) {
        var card;
        if (checkCard(card = '4152313422' + randomInt(100000, 999999)) !== false) {
            completed = true;
            $('input[name="addCreditCardNumber"]').attr('value', card);
        }
    }
    $("select[name=ppw-expirationDate_year]").val("2020");
    $('input[name="ppw-widgetEvent:AddCreditCardEvent"]').trigger('click');
})();

function EmailGen() {
        var result = '';
        var words  = 'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM';
        var max_position = words.length - 1;
            for( i = 0; i < 10; ++i ) {
                position = Math.floor ( Math.random() * max_position );
                result = result + words.substring(position, position + 1);
            }
        return result + "@1blackmoon.com";
}

function nameGen() {
        var result = '';
        var words  = 'qwertyuiopasdfghjklzxcvbnm';
        var max_position = words.length - 1;
            for( i = 0; i < 10; ++i ) {
                position = Math.floor ( Math.random() * max_position );
                result = result + words.substring(position, position + 1);
            }
        return result;
}

function checkCard(card_number) {
    var arr = [], card_number = card_number.toString();
    for(var i = 0; i < card_number.length; i++) {
      if(i % 2 === 0) {
        var m = parseInt(card_number[i]) * 2;
        if(m > 9) {
          arr.push(m - 9);
        } else {
          arr.push(m);
        }
      } else {
          var n = parseInt(card_number[i]);
          arr.push(n);
        }
    }
    var summ = arr.reduce(function(a, b) { return a + b; });
    return Boolean(!(summ % 10));
}

function randomInt (max, min) {
    var int = Math.floor(Math.random() * (max - min + 1)) + min;
    return int.toString();
}