aliyun_slide

阿里云滑块自动滑动

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         aliyun_slide
// @namespace    https://www.yuban.ltd/
// @version      0.0.1
// @description  阿里云滑块自动滑动
// @author       RenJie
// @include      /[a-zA-z]+://[^\s]*/
// @grant        none
// ==/UserScript==

(function () {
    'use strict';
    /**
     * 休眠
     * @param time    休眠时间,单位秒
     * @param desc
     * @returns {Promise<unknown>}
     */
    function sleep(time, desc = 'sleep') {
        return new Promise(resolve => {
            //sleep
            setTimeout(() => {
                console.log(desc, time, 's')
                resolve(time)
            }, Math.floor(time * 1000))
        })
    }
    /**
     * 监测节点是否存在
     * @param selector    CSS选择器
     * @param desc
     * @returns {Promise<unknown>}
     */
    function obsHas(selector, desc = 'has') {
        return new Promise(resolve => {
            //obs node
            let timer = setInterval(() => {
                let target = document.querySelector(selector)
                if (!!target) {
                    clearInterval(timer)
                    console.log(desc, selector)
                    resolve(selector)
                } else {
                    return
                }
            }, 100)
        })
    }
    function slide(id) {
        var slider = document.getElementById(id),
            container = slider.parentNode;

        var rect = slider.getBoundingClientRect(),
            x0 = rect.x || rect.left,
            y0 = rect.y || rect.top,
            w = container.getBoundingClientRect().width,
            x1 = x0 + w,
            y1 = y0;

        var mousedown = document.createEvent("MouseEvents");
        mousedown.initMouseEvent("mousedown", true, true, window, 0,
            x0, y0, x0, y0, false, false, false, false, 0, null);
        slider.dispatchEvent(mousedown);

        var mousemove = document.createEvent("MouseEvents");
        mousemove.initMouseEvent("mousemove", true, true, window, 0,
            x1, y1, x1, y1, false, false, false, false, 0, null);
        slider.dispatchEvent(mousemove);
    }
    sleep(1)
        .then(() => obsHas('.nc_wrapper'))
        .then(() => slide('nc_1_n1z'))
})();