旺旺UpUp

牛刀小试

当前为 2024-11-02 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.gf.qytechs.cn/scripts/515340/1476099/%E6%97%BA%E6%97%BAUpUp.js

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

(function() {
    'use strict';

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


    // 监测DOM
    const observer = new MutationObserver(() => {
        const targetElement = document.querySelector(targetSelector);
            if (targetElement) {
            // 找到目标元素,执行函数
            console.log("已出现");
        
            // 停止观察
            observer.disconnect();
const targetElement = document.querySelector('.biz-right-bar');
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();
                }
            }, 10000);
        });

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

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

             }
    });

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

QingJ © 2025

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