Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Aliexpress automatic payment
- // @namespace http://tampermonkey.net/
- // @version 0.2
- // @description try to take over the world!
- // @author Andronio
- // @match https://trade.aliexpress.ru/orderList.htm*
- // @match https://trade.aliexpress.com/orderList.htm*
- // @match https://trade.aliexpress.ru/order_list.htm*
- // @match https://trade.aliexpress.com/order_list.htm*
- // @match https://shoppingcart.aliexpress.ru/order/secondPayment.htm*
- // @match https://shoppingcart.aliexpress.com/order/secondPayment.htm*
- // @grant none
- // ==/UserScript==
- let mymoney = 'WebMoney';
- //let mymoney = 'Яндекс.Деньги';
- (async function() {
- 'use strict';
- let href = location.href;
- if (href.search("trade.aliexpress.ru/orderList.htm") >= 0 ||
- href.search("trade.aliexpress.ru/order_list.htm") >= 0) {
- let buttonPay = document.querySelectorAll(".button-pay");
- if (buttonPay.length > 0) {
- location.href = "https://trade.aliexpress.com/orderList.htm";
- return;
- }
- }
- if (href.search("shoppingcart.aliexpress.ru/order/secondPayment.htm") >= 0 ||
- href.search("shoppingcart.aliexpress.com/order/secondPayment.htm") >= 0)
- wmPaySelect();
- if (href.search("trade.aliexpress.com/orderList.htm") >= 0 ||
- href.search("trade.aliexpress.com/order_list.htm") >= 0) {
- // currentMode - хранит текущий шаг последовательности оплаты
- let currentMode = sessionStorage.getItem('currentMode');
- if (!currentMode) {
- // Первый проход
- let buttonPay = document.querySelectorAll(".button-pay");
- if (buttonPay.length > 0) {
- let combinPay = document.getElementById("TP_CombinPay");
- if (!combinPay) {
- // Кнопка оплатить все
- let button = document.createElement("button");
- button.id = "allPay";
- button.className = "ui-button ui-button-primary combine-pay-button";
- button.innerText = "Оплатить все";
- document.getElementById("simple-pager").before(button);
- button.addEventListener("click", function(){
- sessionStorage.setItem('currentMode', 'payAll_step1');
- document.getElementById("remiandTips_waitBuyerPayment").click();
- });
- }
- }
- } else {
- document.getElementById("cb").click(); // Выбрать все заказы
- await sleep(100);
- document.getElementById("TP_CombinPay").click(); // Нажать кнопку оплатить
- sessionStorage.removeItem('currentMode');
- }
- }
- })();
- async function wmPaySelect() {
- // Ждем выбор эл. денег
- try {
- await waitForDisableElement("#init-loading", 150);
- await waitForElement(".title-to-detail", 150);
- } catch {
- return alert("Не найден элемент 1");
- }
- await sleep(500);
- document.querySelector(".title-to-detail").click();
- // Ждем появления вебманей
- try {
- await waitForElement(".payment-opt", 150);
- } catch {
- return alert("Не найден элемент 2");
- }
- // Выбираем вебмани
- let money = document.querySelectorAll(".opt-title");
- let found = false;
- for (let el of money) {
- if (el.innerText == mymoney) {
- money = el;
- found = true;
- break;
- }
- }
- await sleep(800);
- if (found) {
- try {
- await waitForDisableElement(".spinner-container", 150);
- } catch {
- return alert("Не найден элемент 2.5");
- }
- await sleep(800);
- money.click();
- } else return alert("Не нашел " + mymoney + " 3");
- // Только для ЯД нажать кошелек
- if (mymoney == 'Яндекс.Деньги') {
- await sleep(800);
- try {
- await waitForDisableElement(".spinner-container", 150);
- await waitForElement(".sub-payment-opt-item", 150);
- } catch {
- return alert("Не найден элемент 4");
- }
- await sleep(500);
- let wallet = document.querySelectorAll(".sub-payment-opt-item");
- if (wallet) wallet[0].click();
- else return alert("Не нашел " + mymoney + " 5");
- }
- await sleep(800);
- let countdown = 15;
- do {
- try {
- await waitForDisableElement(".spinner-container", 150);
- } catch {
- return alert("Не прошел ожидание 7");
- }
- await sleep(1000);
- } while(document.querySelector(".spinner-container") && --countdown);
- if (!countdown) return alert("Не прошел ожидание 8");
- await sleep(500);
- document.querySelector(".next-btn-primary").click();
- }
- function sleep(ms) {
- return new Promise(resolve => setTimeout(resolve, ms));
- }
- // Функция ждет элемент elem, таймаут timeout
- async function waitForElement(elem, timeout) {
- while(!document.querySelector(elem) && --timeout > 0) {
- await sleep(100);
- }
- let el = document.querySelector(elem);
- if (el) return Promise.resolve(el);
- else return Promise.reject();
- }
- async function waitInnerText(elem, text, timeout)
- {
- let el;
- do {
- el = document.querySelector(elem);
- if (el.innerText == text) break;
- } while(--timeout > 0);
- if (el.innerText == text) Promise.resolve(el);
- else return Promise.reject();
- }
- // Функция для фрейма ждет элемент elem, таймаут timeout
- async function waitForDisableElement(elem, timeout) {
- let el;
- while((el = document.querySelector(elem)) && --timeout > 0) {
- if (el.style.display == "none") break;
- await sleep(100);
- }
- if (!el || el.style.display == "none") return Promise.resolve(true);
- else return Promise.reject();
- }
Add Comment
Please, Sign In to add comment