OneTwitt

Скрипт автоматической оплаты из списка заказов до вебманей

May 13th, 2020
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.22 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Aliexpress automatic payment
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description try to take over the world!
  6. // @author Andronio
  7. // @match https://trade.aliexpress.ru/orderList.htm*
  8. // @match https://trade.aliexpress.com/orderList.htm*
  9. // @match https://trade.aliexpress.ru/order_list.htm*
  10. // @match https://trade.aliexpress.com/order_list.htm*
  11. // @match https://shoppingcart.aliexpress.ru/order/secondPayment.htm*
  12. // @match https://shoppingcart.aliexpress.com/order/secondPayment.htm*
  13. // @grant none
  14. // ==/UserScript==
  15.  
  16. let mymoney = 'WebMoney';
  17. //let mymoney = 'Яндекс.Деньги';
  18.  
  19. (async function() {
  20. 'use strict';
  21. let href = location.href;
  22. if (href.search("trade.aliexpress.ru/orderList.htm") >= 0 ||
  23. href.search("trade.aliexpress.ru/order_list.htm") >= 0) {
  24. let buttonPay = document.querySelectorAll(".button-pay");
  25. if (buttonPay.length > 0) {
  26. location.href = "https://trade.aliexpress.com/orderList.htm";
  27. return;
  28. }
  29. }
  30. if (href.search("shoppingcart.aliexpress.ru/order/secondPayment.htm") >= 0 ||
  31. href.search("shoppingcart.aliexpress.com/order/secondPayment.htm") >= 0)
  32. wmPaySelect();
  33. if (href.search("trade.aliexpress.com/orderList.htm") >= 0 ||
  34. href.search("trade.aliexpress.com/order_list.htm") >= 0) {
  35. // currentMode - хранит текущий шаг последовательности оплаты
  36. let currentMode = sessionStorage.getItem('currentMode');
  37. if (!currentMode) {
  38.  
  39. // Первый проход
  40. let buttonPay = document.querySelectorAll(".button-pay");
  41. if (buttonPay.length > 0) {
  42. let combinPay = document.getElementById("TP_CombinPay");
  43. if (!combinPay) {
  44. // Кнопка оплатить все
  45. let button = document.createElement("button");
  46. button.id = "allPay";
  47. button.className = "ui-button ui-button-primary combine-pay-button";
  48. button.innerText = "Оплатить все";
  49. document.getElementById("simple-pager").before(button);
  50. button.addEventListener("click", function(){
  51. sessionStorage.setItem('currentMode', 'payAll_step1');
  52. document.getElementById("remiandTips_waitBuyerPayment").click();
  53. });
  54. }
  55. }
  56. } else {
  57. document.getElementById("cb").click(); // Выбрать все заказы
  58. await sleep(100);
  59. document.getElementById("TP_CombinPay").click(); // Нажать кнопку оплатить
  60. sessionStorage.removeItem('currentMode');
  61. }
  62. }
  63.  
  64. })();
  65.  
  66.  
  67. async function wmPaySelect() {
  68. // Ждем выбор эл. денег
  69. try {
  70. await waitForDisableElement("#init-loading", 150);
  71. await waitForElement(".title-to-detail", 150);
  72. } catch {
  73. return alert("Не найден элемент 1");
  74. }
  75. await sleep(500);
  76. document.querySelector(".title-to-detail").click();
  77. // Ждем появления вебманей
  78. try {
  79. await waitForElement(".payment-opt", 150);
  80. } catch {
  81. return alert("Не найден элемент 2");
  82. }
  83. // Выбираем вебмани
  84. let money = document.querySelectorAll(".opt-title");
  85. let found = false;
  86. for (let el of money) {
  87. if (el.innerText == mymoney) {
  88. money = el;
  89. found = true;
  90. break;
  91. }
  92. }
  93. await sleep(800);
  94. if (found) {
  95. try {
  96. await waitForDisableElement(".spinner-container", 150);
  97. } catch {
  98. return alert("Не найден элемент 2.5");
  99. }
  100. await sleep(800);
  101. money.click();
  102. } else return alert("Не нашел " + mymoney + " 3");
  103. // Только для ЯД нажать кошелек
  104. if (mymoney == 'Яндекс.Деньги') {
  105. await sleep(800);
  106. try {
  107. await waitForDisableElement(".spinner-container", 150);
  108. await waitForElement(".sub-payment-opt-item", 150);
  109. } catch {
  110. return alert("Не найден элемент 4");
  111. }
  112. await sleep(500);
  113. let wallet = document.querySelectorAll(".sub-payment-opt-item");
  114. if (wallet) wallet[0].click();
  115. else return alert("Не нашел " + mymoney + " 5");
  116. }
  117. await sleep(800);
  118. let countdown = 15;
  119. do {
  120. try {
  121. await waitForDisableElement(".spinner-container", 150);
  122. } catch {
  123. return alert("Не прошел ожидание 7");
  124. }
  125. await sleep(1000);
  126. } while(document.querySelector(".spinner-container") && --countdown);
  127. if (!countdown) return alert("Не прошел ожидание 8");
  128. await sleep(500);
  129. document.querySelector(".next-btn-primary").click();
  130. }
  131.  
  132. function sleep(ms) {
  133. return new Promise(resolve => setTimeout(resolve, ms));
  134. }
  135.  
  136. // Функция ждет элемент elem, таймаут timeout
  137. async function waitForElement(elem, timeout) {
  138. while(!document.querySelector(elem) && --timeout > 0) {
  139. await sleep(100);
  140. }
  141. let el = document.querySelector(elem);
  142. if (el) return Promise.resolve(el);
  143. else return Promise.reject();
  144. }
  145.  
  146. async function waitInnerText(elem, text, timeout)
  147. {
  148. let el;
  149. do {
  150. el = document.querySelector(elem);
  151. if (el.innerText == text) break;
  152. } while(--timeout > 0);
  153. if (el.innerText == text) Promise.resolve(el);
  154. else return Promise.reject();
  155. }
  156.  
  157. // Функция для фрейма ждет элемент elem, таймаут timeout
  158. async function waitForDisableElement(elem, timeout) {
  159. let el;
  160. while((el = document.querySelector(elem)) && --timeout > 0) {
  161. if (el.style.display == "none") break;
  162. await sleep(100);
  163. }
  164. if (!el || el.style.display == "none") return Promise.resolve(true);
  165. else return Promise.reject();
  166. }
Add Comment
Please, Sign In to add comment