// ==UserScript==
// @name Aliexpress CARD filler
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Заполнение данных платежной карты
// @author Andronio
// @match https://shoppingcart.aliexpress.ru/orders.htm?aeOrderFrom=main_shopcart*
// @grant none
// @noframes
// ==/UserScript==
let timeout = 50;
(function() {
'use strict';
var div = document.createElement('div');
div.className = 'myBox';
div.innerHTML += `
<input type="text" id="carddata"></br>
<input type="button" id="cardfill" class="mybutton" value="Карта">
`;
// Стили
var styles = `
.myBox {
position: fixed;
top: 0;
right: 0;
background: white;
box-shadow: 1px -1px 4px 1px;
max-width: 40%;
max-height: 400px;
padding: 10px 20px;
overflow-y: auto;
overflow-x: hidden;
z-index:9999;
}
.mybutton {
display: inline;
padding: 5px 10px;
margin-right:auto;
cursor:pointer;
}`
var styleSheet = document.createElement("style")
styleSheet.type = "text/css"
styleSheet.innerText = styles
document.head.append(styleSheet)
document.body.append(div);
let mybutton1 = document.getElementById("cardfill");
mybutton1.addEventListener('click', cardFunc);
let mytext = document.getElementById("carddata");
mytext.addEventListener('keydown', event => {
if (event.keyCode == "13") {
document.getElementById('cardfill').click();
}
});
mytext.focus();
})();
function cardFunc() {
let cardNumber = document.getElementById('cardNo');
let cardHold = document.getElementById('cardHolder');
let dateExpire = document.getElementById('expire');
let codeCVC = document.getElementById('cvc');
let mytext = document.getElementById("carddata");
let mass;
if (mytext.value == "") return null;
if (/\d{4}\s\d{4}\s\d{4}\s\d{4},\s\d{4}\/\d\d,\s\d{3},\s[\w\s]+,\s/.test(mytext.value)) {
mass = mytext.value.split(', ');
} else {
return alert("Нет данных карты");
}
let nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value').set;
nativeInputValueSetter.call(cardNumber, mass[0]);
cardNumber.dispatchEvent(new Event('change', {bubbles: true}));
cardNumber.dispatchEvent(new Event('blur', {bubbles: true}));
nativeInputValueSetter.call(cardHold, mass[3]);
cardHold.dispatchEvent(new Event('change', {bubbles: true}));
let date = mass[1].slice(5,7) + '/' + mass[1].slice(2,4);
nativeInputValueSetter.call(dateExpire, date);
dateExpire.dispatchEvent(new Event('change', {bubbles: true}));
nativeInputValueSetter.call(codeCVC, mass[2]);
codeCVC.dispatchEvent(new Event('change', {bubbles: true}));
document.querySelector('[ae_button_type="confirm"]').click();
document.querySelector(".myBox").style.display = "none";
}