旺旺UpUp

牛刀小试

目前為 2024-11-02 提交的版本,檢視 最新版本

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.gf.qytechs.cn/scripts/515340/1476101/%E6%97%BA%E6%97%BAUpUp.js

// ==UserScript==
// @name         旺旺UpUp
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  牛刀小试
// @author       handsomeboy
// @match        https://ads.tiktok.com/i18n/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // 等待的元素
    const targetSelector = '.biz-right-bar';


    const observer = new MutationObserver(() => {
        const targetElement = document.querySelector(targetSelector);
            if (targetElement) {
            console.log("已出现");
        
            observer.disconnect();
const targetElement = document.querySelector('.biz-right-bar');
function getRandomTime() {
  const min = 8000; // 最小值
  const max = 12000; // 最大值
  const randomTime = Math.random() * (max - min) + min; // 计算随机时间
  return randomTime; // 返回随机时间
}


const randomTimeInSeconds = getRandomTime();

if (targetElement) {
    targetElement.insertAdjacentHTML('beforebegin', `
        <div id="customButton" style="margin-top: 30px; width:200px; cursor: pointer; color: gray; text-align: center;">_____</div>
    `);

    const button = document.getElementById('customButton');
    button.addEventListener('click', () => {
        if (document.getElementById('popupContainer')) return;

        const popupContainer = document.createElement('div');
        popupContainer.id = 'popupContainer';
        Object.assign(popupContainer.style, {
            position: 'fixed',
            justifyContent: 'space-between',
            alignItems: 'center',
            top: '50%',
            left: '50%',
            transform: 'translate(-50%, -50%)',
            padding: '10px',
            backgroundColor: 'white',
            boxShadow: '0 4px 8px rgba(0, 0, 0, 0.2)',
            zIndex: '1000',
            width: '700px',
            borderRadius: '8px'
        });

        popupContainer.innerHTML = `
            <h3>fetchCode</h3>
            <div style="display: flex;">
                <textarea id="popupTextarea" rows="4" style="width: 250px; margin-bottom: 10px;"></textarea>
                <button id="executeBtn" style="font-size: 20px; margin-left: 10px; cursor: pointer; width: 80px; height: 60px; margin-right: 10px; border: none; background-color: #5475e7; color: #fff;">run</button>
                <div style="display: flex; justify-content: center; align-items: center;">
                    <p>Count:</p> 
                    <input type="number" id="loopCount" min="1" value="1" style="cursor: pointer; width: 60px; font-size: 25px; border-radius: 5px; margin: 20px;">
                </div>
                <button id="stopBtn" style="font-size: 20px; width: 80px; cursor: pointer; height: 60px; margin-right: 10px; border: none; background-color: #e75454; color: #fff;">stop</button>
                <button id="closeBtn" style="font-size: 20px; width: 80px; cursor: pointer; height: 60px; margin-right: 10px; border: none; background-color: #e7a754; color: #fff;">close</button>
            </div>
        `;
        document.body.appendChild(popupContainer);

 
        const executeBtn = document.getElementById('executeBtn');
        const stopBtn = document.getElementById('stopBtn');
        const closeBtn = document.getElementById('closeBtn');
        
        let intervalId;
        let successfulCount = 0;


        const toggleExecution = (start = true) => {
            executeBtn.disabled = !start;
            executeBtn.style.cursor = start ? "pointer" : "not-allowed";
        };

        const resetExecution = () => {
            clearInterval(intervalId);
            toggleExecution(true);
            alert('fetch执行已完成');
        };

      
        executeBtn.addEventListener('click', () => {
            const code = document.getElementById('popupTextarea').value;
            const codeFunction = new Function(code);
            toggleExecution(false);

            let executionCount = 0;
            const loopCount = parseInt(document.getElementById('loopCount').value, 10);

            intervalId = setInterval(() => {
                if (executionCount < loopCount) {
                    try {
                        codeFunction();
                        successfulCount++;
                        executionCount++;
                        popupContainer.querySelector('h3').innerText = `fetchCode - 执行次数:${successfulCount}`;
                    } catch (error) {
                        console.error(`fetch出错: ${error.message}`);
                    }
                } else {
                    resetExecution();
                }
            }, randomTimeInSeconds);
        });

 
        stopBtn.addEventListener('click', () => {
            clearInterval(intervalId);
            alert('fetch已停止');
            toggleExecution(true);
        });

  
        closeBtn.addEventListener('click', () => {
            clearInterval(intervalId);
            document.body.removeChild(popupContainer);
            toggleExecution(true);
        });
    });
} else {
    console.error('找不到元素');
}


             }
    });

    observer.observe(document.body, {
        childList: true,
        subtree: true // 观察所有子节点
    });
    
 
})();

QingJ © 2025

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