// ==UserScript==
// @name AliExpress Captcha Solver
// @description Решает капчу
// @author longnull
// @namespace longnull
// @version 1.0
// @updateURL https://gist.github.com/longnull/827b6f4829355fdbe7f0e573bf75f850/raw/AliExpressCaptchaSolver.user.js
// @downloadURL https://gist.github.com/longnull/827b6f4829355fdbe7f0e573bf75f850/raw/AliExpressCaptchaSolver.user.js
// @match https://*.aliexpress.com/*/_____tmd_____/punish*
// @match https://*.aliexpress.ru/*/_____tmd_____/punish*
// @grant none
// ==/UserScript==
(async () => {
'use strict';
const waitForElement = (selectors, waitForExistence = true, visible = false, parent = document, interval = 250, seconds = 0) => {
const isVisible = (e) => {
return !!(e.offsetWidth || e.offsetHeight || e.getClientRects().length);
};
return new Promise((resolve) => {
if (!Array.isArray(selectors)) {
selectors = [selectors];
}
seconds = seconds * 1000;
const startTime = Date.now();
const check = () => {
let found = true;
let el;
for (const s of selectors) {
el = parent.querySelector(s);
if ((waitForExistence && (!el || (visible && !isVisible(el)))) || (!waitForExistence && el)) {
found = false;
break;
}
}
if (found) {
return resolve(el);
}
if (seconds > 0 && Date.now() - startTime > seconds) {
return resolve(false);
}
setTimeout(check, interval);
};
check();
});
};
const sleep = async (ms) => {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
};
const randomRange = (min, max) => {
return Math.floor(Math.random() * (max + 1 - min)) + min;
};
const sendMouseEvent = (x, y, element, eventType) => {
const event = document.createEvent('MouseEvents');
event.initMouseEvent(eventType, true, true, window, 1, x, y, x, y, false, false, false, false, 0, null);
element.dispatchEvent(event);
}
const slider = await waitForElement('#nc_1_n1z');
const sliderRect = slider.getBoundingClientRect();
const sliderWrapperRect = document.querySelector('#nc_1_wrapper').getBoundingClientRect();
const startX = sliderRect.x + sliderRect.width / 2;
const endX = startX + sliderWrapperRect.width - sliderRect.width;
const posY = sliderRect.y + sliderRect.width / 2;
let posX = startX;
sendMouseEvent(startX, posY, slider, 'mousedown');
while (posX < endX) {
await sleep(randomRange(2, 10));
const move = randomRange(4, 10);
sendMouseEvent(posX + move, posY, slider, 'mousemove');
posX += move;
}
sendMouseEvent(sliderRect.x + sliderRect.width + sliderWrapperRect.width, sliderRect.y + sliderRect.height / 2, slider, 'mouseup');
})();