NovelAI 自定义连点器

自定义点击间隔以及插入随机值,请勿滥用, 粗制滥造还望海涵。少代码部分参考:LigHT。

当前为 2023-12-29 提交的版本,查看 最新版本

// ==UserScript==
// @name         NovelAI 自定义连点器
// @namespace    https://novelai.net
// @match        https://novelai.net/image
// @icon         https://novelai.net/_next/static/media/goose_blue.1580a990.svg
// @license      MIT
// @version      1.3
// @author       Takoro
// @description  自定义点击间隔以及插入随机值,请勿滥用, 粗制滥造还望海涵。少代码部分参考:LigHT。
// ==/UserScript==

console.log("NovelAI 自定义连点器 ver1.3");

var div_class;
var loopTime = 15000;
var randomTime = 5000;
var tmpTime;
var interval;
var initX, initY, containerX, containerY;

var intervalId = setInterval(function() {

    // var xpathExpression = '/html/body/div[1]/div[2]/div[4]/div[1]/div[5]/button/div/div[2]';
    var xpathExpression = '/html/body/div[1]/div[2]/div[4]/div[1]/div[5]/button';
    var result = document.evaluate(xpathExpression, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
    var targetElement = result.singleNodeValue;

    if (targetElement) {
        clearInterval(intervalId);
        div_class = targetElement.getAttribute('class');
        console.log('获取到的随机 class 名为:' + div_class);
        createComponent();
    } else {
        console.log('未找到符合条件的元素');
    }
}, 5000);

function createComponent() {
    var container = document.createElement("div");
    container.style.height = "34px";
    container.style.position = "fixed";
    container.style.display = "flex";
    container.style.justifyContent = "center";
    container.style.alignItems = "center";
    container.style.bottom = "90px";
    container.style.left = "50%";
    container.style.transform = "translateX(-50%)";
    container.style.userSelect = "none";
    container.style.zIndex = "999";
    document.body.appendChild(container);

    var button = document.createElement("button");
    button.innerHTML = "Start";
    button.style.backgroundColor = 'rgb(34, 37, 63)';
    button.style.color = 'rgb(245 243 194)';
    button.style.border = '0.1px solid rgb(245 243 194)';
    button.style.height = '34px';
    button.style.paddingLeft = '10px';
    button.style.paddingRight= '10px';
    button.style.borderRadius = '3px';
    button.style.fontFamily = 'Source Sans Pro';
    button.style.fontSize = '15px';
    button.style.userSelect = "none";
    button.style.cursor = "pointer";
    container.appendChild(button);

    var input = document.createElement("input");
    input.type = "number";
    input.placeholder = "间隔:" + parseInt(loopTime/1000) + "秒";
    input.style.width = "90px";
    input.style.height = "34px";
    input.style.padding = "6px 6px 5px 6px";
    input.style.backgroundColor = 'rgb(34, 37, 63)';
    input.style.userSelect = "none";
    container.appendChild(input);


    var random = document.createElement("input");
    random.type = "number";
    random.placeholder = "± " + parseInt(randomTime/1000) + "秒";
    random.style.width = "50px";
    random.style.height = "34px";
    random.style.padding = "6px 6px 5px 6px";
    random.style.backgroundColor = 'rgb(34, 37, 63)';
    random.style.userSelect = "none";
    container.appendChild(random);

    var mover = document.createElement("button");
    mover.innerHTML = "↔";
    mover.style.display = "flex";
    mover.style.alignItems = "center";
    mover.style.backgroundColor = 'rgb(34, 37, 63)';
    mover.style.color = 'rgb(245 243 194)';
    mover.style.border = '0.1px solid rgb(245 243 194)';
    mover.style.height = '34px';
    mover.style.paddingLeft = '10px';
    mover.style.paddingRight= '10px';
    mover.style.borderRadius = '3px';
    mover.style.fontFamily = 'Source Sans Pro';
    mover.style.fontSize = '20px';
    mover.style.userSelect = "none";
    mover.style.cursor = "pointer";
    container.appendChild(mover);

    mover.addEventListener('mousedown', function(e) {
        initX = e.pageX;
        initY = e.pageY;
        containerX = container.offsetLeft;
        containerY = container.offsetTop;
        document.addEventListener('mousemove', mouseMoveHandler);
    });

    function mouseMoveHandler(e) {
        var moveX = e.pageX - initX;
        var moveY = (e.pageY - initY);
        container.style.left = containerX + moveX + 'px';
        container.style.top = containerY + moveY + 'px';
    }

    document.addEventListener('mouseup', function() {
        document.removeEventListener('mousemove', mouseMoveHandler);
    });

    function clickElement() {
        if((getRandomInt(0, 9)%2) == 0){
            tmpTime = loopTime + getRandomInt(0, randomTime)
        }else{
            tmpTime = loopTime - getRandomInt(0, randomTime)
        }
        console.log("下一次点击间隔为:" + tmpTime/1000);
        var target = document.getElementsByClassName(div_class)[0];
        var event = new MouseEvent("click", {
            bubbles: true,
            cancelable: true,
        });
        target.dispatchEvent(event);

        clearInterval(interval);
        interval = null;
        interval = setInterval(clickElement, tmpTime);
        console.log("计时器:" + interval);
    }

    button.onclick = function() {
        if (interval) {
            clearInterval(interval);
            interval = null;
            console.log("计时器销毁:" + interval);
            button.innerHTML = "Start";
        } else {
            clickElement();
            console.log("启动计时器:" + tmpTime);
            button.innerHTML = "Pause";
        }
    };

    input.onchange = function() {
        loopTime = parseInt(input.value) * 1000;
        console.log("设置间隔:" + loopTime);
        input.value = "";
        input.placeholder = "间隔:" + parseInt(loopTime/1000) + "秒";
    };

    random.onchange = function() {
        randomTime = parseInt(random.value) * 1000;
        console.log("随机间隔:" + randomTime);
        random.value = "";
        random.placeholder = "± " + parseInt(randomTime/1000) + "秒";
    };

    function getRandomInt(min, max) {
        min = Math.ceil(min);
        max = Math.floor(max);
        return Math.floor(Math.random() * (max - min + 1)) + min;
    }

}

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址