Alpha 数据保存器(微信Civilpy)

自动点击标签,用户确认后复制页面内容,5次后保存为TXT

当前为 2025-10-16 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Alpha 数据保存器(微信Civilpy)
// @namespace    http://tampermonkey.net/ 
// @version      1.0 
// @license MIT
// @description  自动点击标签,用户确认后复制页面内容,5次后保存为TXT
// @match        https://web3.binance.com/zh-CN/markets/alpha?chain=bsc 
// @grant        none
// ==/UserScript==

(function () {
    'use strict'; // 启用严格模式,提高代码安全性和规范性

    // 定义要点击的标签文本数组
    const labels = ["1 分钟", "5 分钟", "1 小时", "4 小时", "24 小时"];
    let result = ""; // 用于保存采集到的文本内容
    let currentIndex = 0; // 当前处理的标签索引

    // 插入主按钮到页面上,用户点击后开始采集流程
    function insertMainButton() {
        const container = document.querySelector(".flex.gap-4.ml-4.mr-6"); // 查找按钮容器
        if (!container || document.getElementById("alpha-capture-btn")) return; // 如果容器不存在或按钮已存在则退出

        const btn = document.createElement("button"); // 创建按钮元素
        btn.id = "alpha-capture-btn"; // 设置按钮 ID
        btn.textContent = "📋 开始标签采集"; // 设置按钮文本
        // 设置按钮样式
        btn.style.padding = "6px 12px";
        btn.style.marginRight = "12px";
        btn.style.backgroundColor = "#f0b90b";
        btn.style.color = "#000";
        btn.style.border = "none";
        btn.style.borderRadius = "4px";
        btn.style.cursor = "pointer";

        // 点击按钮后初始化状态并开始处理标签
        btn.onclick = () => {
            currentIndex = 0;
            result = "";
            processNextLabel();
        };

        container.prepend(btn); // 将按钮插入到容器最前面
    }

    // 处理当前标签:点击按钮并等待用户确认
    function processNextLabel() {
        if (currentIndex >= labels.length) {
            saveToFile(); // 所有标签处理完毕,保存结果为文件
            return;
        }

        const label = labels[currentIndex]; // 获取当前标签文本
        const buttons = Array.from(document.querySelectorAll("button")); // 获取页面所有按钮
        const target = buttons.find(btn => btn.textContent.trim() === label); // 查找匹配标签的按钮
        if (target) {
            target.click(); // 点击该标签按钮
            console.log(`点击标签:${label}`); // 控制台输出日志
            setTimeout(() => {
                showConfirmButton(label); // 等待数据加载后显示确认按钮
            }, 3000); // 延迟 3 秒
        } else {
            // 如果未找到按钮,记录错误信息
            result += `=== ${label} ===\n⚠️ 未找到对应按钮\n\n`;
            currentIndex++; // 继续下一个标签
            processNextLabel();
        }
    }

    // 显示确认按钮,用户点击后复制页面内容
    function showConfirmButton(label) {
        let confirmBtn = document.getElementById("confirm-copy-btn"); // 查找是否已有确认按钮
        if (confirmBtn) confirmBtn.remove(); // 如果存在则移除旧按钮

        confirmBtn = document.createElement("button"); // 创建新确认按钮
        confirmBtn.id = "confirm-copy-btn"; // 设置 ID
        confirmBtn.textContent = `✅ 确认复制 ${label} 数据`; // 设置按钮文本
        // 设置按钮样式(固定在右下角)
        confirmBtn.style.position = "fixed";
        confirmBtn.style.bottom = "20px";
        confirmBtn.style.right = "20px";
        confirmBtn.style.zIndex = "9999";
        confirmBtn.style.padding = "8px 12px";
        confirmBtn.style.backgroundColor = "#00cc66";
        confirmBtn.style.color = "#fff";
        confirmBtn.style.border = "none";
        confirmBtn.style.borderRadius = "4px";
        confirmBtn.style.cursor = "pointer";

        // 点击确认按钮后复制页面内容并继续下一个标签
        confirmBtn.onclick = () => {
            const text = document.body.innerText; // 获取页面所有文本内容
            result += `=== ${label} ===\n${text}\n\n`; // 添加到结果中
            confirmBtn.remove(); // 移除确认按钮
            currentIndex++; // 继续下一个标签
            processNextLabel();
        };

        document.body.appendChild(confirmBtn); // 将确认按钮添加到页面
    }

    // 将采集结果保存为 TXT 文件
    function saveToFile() {
        const blob = new Blob([result], { type: "text/plain" }); // 创建文本文件 Blob 对象
        const link = document.createElement("a"); // 创建下载链接
        link.href = URL.createObjectURL(blob); // 设置链接地址为 Blob 对象 URL
        link.download = "alpha_tags_data.txt"; // 设置下载文件名
        link.click(); // 触发下载
    }

    // 页面加载完成后延迟插入主按钮
    window.addEventListener("load", () => {
        setTimeout(insertMainButton, 3000); // 延迟 3 秒插入按钮
    });
})();