MCPcopy Create free account
hub / github.com/Xu22Web/tech-study-js / handleSlideVerify

Function handleSlideVerify

tech-study.js:2763–2902  ·  view source on GitHub ↗

* @description 处理滑动验证

()

Source from the content-addressed store, hash-verified

2761 * @description 处理滑动验证
2762 */
2763function handleSlideVerify() {
2764 return new Promise(async (resolve) => {
2765 // 滑动验证
2766 const mask = $$('#nc_mask')[0];
2767 if (mask && getComputedStyle(mask).display !== 'none') {
2768 // 创建提示
2769 createTip('等待滑动验证');
2770 // 提高层级
2771 mask.style.zIndex = '999';
2772 // 轨道
2773 const track = (await $_('.nc_scale', undefined, 3000))[0];
2774 // 滑块
2775 const slide = (await $_('.btn_slide', undefined, 3000))[0];
2776 // 延时
2777 await sleep(2000);
2778 // 矩形范围
2779 const rectTrack = track.getBoundingClientRect();
2780 // 矩形范围
2781 const rectSlide = slide.getBoundingClientRect();
2782 // 窗口
2783 const window = unsafeWindow;
2784 // 范围内随机起点
2785 const start = createRandomPoint(rectSlide);
2786 // 终点
2787 const end = {
2788 x: rectTrack.x + rectTrack.width,
2789 y: rectTrack.y + rectTrack.height / 2,
2790 };
2791 // 路径
2792 const path = createRandomPath(start, end, 10);
2793 // 移动端
2794 const mobile = hasMobile();
2795 if (mobile) {
2796 slide.style.touchAction = 'none';
2797 const touchstartTouch = new Touch({
2798 identifier: 0,
2799 target: slide,
2800 clientX: path[0].x,
2801 clientY: path[0].y,
2802 });
2803 const touchstartList = [touchstartTouch];
2804 // 开始触摸
2805 const touchstart = new TouchEvent('touchstart', {
2806 targetTouches: touchstartList,
2807 touches: touchstartList,
2808 changedTouches: touchstartList,
2809 view: window,
2810 bubbles: true,
2811 });
2812 slide.dispatchEvent(touchstart);
2813 // 触摸滑动
2814 for (const i in path) {
2815 const touchmoveTouch = new Touch({
2816 identifier: 0,
2817 target: slide,
2818 clientX: path[i].x,
2819 clientY: path[i].y,
2820 });

Callers 1

doingExamFunction · 0.70

Calls 8

$$Function · 0.70
createTipFunction · 0.70
$_Function · 0.70
sleepFunction · 0.70
createRandomPointFunction · 0.70
createRandomPathFunction · 0.70
hasMobileFunction · 0.70
logFunction · 0.70

Tested by

no test coverage detected