黑糖

q11e 代刷网站的定时提交控制脚本

От 18.03.2025. Виж последната версия.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey, Greasemonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да инсталирате разширение, като например Tampermonkey .

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Userscripts.

За да инсталирате скрипта, трябва да инсталирате разширение като Tampermonkey.

За да инсталирате този скрипт, трябва да имате инсталиран скриптов мениджър.

(Вече имам скриптов мениджър, искам да го инсталирам!)

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

(Вече имам инсталиран мениджър на стиловете, искам да го инсталирам!)

// ==UserScript==
// @name         黑糖
// @namespace    http://sugarblack.top
// @version      0.1.0
// @description  q11e 代刷网站的定时提交控制脚本
// @author       zemelee
// @license MIT
// @match        http://sugarblack.top/*
// ==/UserScript==

async function oneTime(count) {
    let homeBtn = document.querySelector("#home-btn");
    homeBtn.click()
    await new Promise((resolve) => { setTimeout(resolve, 1000); });
    let inputEl = document.querySelector('input[step="5"][max="100"]');
    inputEl.value = count
    const inputEvent = new Event('input', { bubbles: true });
    inputEl.dispatchEvent(inputEvent);
    await new Promise((resolve) => { setTimeout(resolve, 500); });
    let submitBtn = document.querySelector("#submit-btn");
    submitBtn.click()
    await new Promise((resolve) => { setTimeout(resolve, 1000); });
    const buttons = document.querySelectorAll('button');
    const confirmBtn = Array.from(buttons).filter(button => button.innerText.trim() === '确认');
    confirmBtn[0].click()
}

function showMessage(text, delay) {
    messageBox = document.createElement('div');
    messageBox.textContent = text;
    messageBox.style.cssText = `
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translateX(-50%);
        background-color: rgba(0, 0, 0, 0.8);
        color: white;
        padding: 10px 20px;
        border-radius: 5px;
        z-index: 9999;
    `;
    document.body.appendChild(messageBox);
    setTimeout(() => {
        document.body.removeChild(messageBox);
        messageBox = null; // 释放引用,准备下一次使用
    }, delay); // 4 seconds
}
function validate(inputs) {
    let inputNum = inputs[0]
    let inputInterval = inputs[1]
    let inputFor = inputs[2]
    if (!inputNum.value || !inputInterval.value || !inputFor.value) {
        showMessage("份数/间隔/循环次数 需要填写完整", 3500)
        return false
    }
    if (inputNum.value >= 88 || inputNum.value <= 1) {
        showMessage("提交次数区间为[2, 88]!", 3500)
        return false
    }
    if (inputInterval.value > 600 || inputInterval.value < 10) {
        showMessage("间隔时间区间为[10, 600s]!", 3500)
        return false
    }
    if (inputFor > 100 || inputFor < 1) {
        showMessage("循环次数区间为[1, 100]!", 3500)
        return false
    }
    return true
}

async function executeRepeatedly(delay, forTime, singleCnt) {
    let count = 0;
    async function execute() {
        if (count < forTime) {
            showMessage(`当前循环轮次:${count + 1}`, 5000)
            await oneTime(singleCnt); // 等待 oneTime() 完成
            count++;
            setTimeout(execute, delay * 1000);
        }
    }
    await execute();
    window.location.replace("http://sugarblack.top/#/home/params")
}


(async function () {
    'use strict';
    let singleCnt = localStorage.getItem("singleCnt") || null;
    let forTime = localStorage.getItem("forTime") || null;
    let delay = localStorage.getItem("delay") || null;
    await new Promise((resolve) => { setTimeout(resolve, 1000); });
    const btns = document.querySelector(".btns")
    btns.appendChild(document.createElement("br"))
    // 
    const label1 = document.createElement('label');
    const label2 = document.createElement('label');
    const label3 = document.createElement('label');
    label1.textContent = "份数";
    label2.textContent = "间隔";
    label3.textContent = "循环";
    let inputNum = document.createElement("input")
    let inputInterval = document.createElement("input")
    let inputFor = document.createElement("input")
    inputNum.placeholder = "每次提交的份数";
    inputInterval.placeholder = "提交间隔(秒)";
    inputFor.placeholder = "循环次数";
    // inputNum.className = "inputNum";
    // inputInterval.className = "inputInterval";
    // inputFor.className = "inputFor";
    if (singleCnt && forTime && delay) {
        inputNum.value = singleCnt;
        inputInterval.value = delay;
        inputFor.value = forTime;
    }
    let inputs = [inputNum, inputInterval, inputFor]
    let labels = [label1, label2, label3]
    inputs.forEach((item, index) => {
        item.style.marginLeft = "6px";
        item.style.marginRight = "20px";
        item.type = "number";
        item.style.width = "150px";
        btns.appendChild(labels[index]);
        btns.appendChild(item)
    })
    let startBtn = document.createElement("button")
    startBtn.textContent = "开始"
    startBtn.style.marginLeft = "10px";
    startBtn.addEventListener("click", function () {

        if (!validate(inputs)) return
        singleCnt = inputNum.value;
        forTime = inputFor.value;
        delay = inputInterval.value;
        localStorage.setItem("singleCnt", singleCnt)
        localStorage.setItem("forTime", forTime)
        localStorage.setItem("delay", delay)
        executeRepeatedly(delay, forTime, singleCnt)
    })
    btns.appendChild(startBtn)


})();