checkReven

捕获并过滤域名数据,计算总反款金额。

目前為 2025-03-03 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         checkReven
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  捕获并过滤域名数据,计算总反款金额。
// @author       你的名字
// @match        https://www.ads.com/cn/account/reports/parking/domains
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // 创建日志窗口
    const logContainer = document.createElement('div');
    logContainer.style.position = 'fixed';
    logContainer.style.left = '10px';
    logContainer.style.bottom = '10px';
    logContainer.style.width = '500px';
    logContainer.style.maxHeight = '400px';
    logContainer.style.overflowY = 'auto';
    logContainer.style.background = 'rgba(0, 0, 0, 0.8)';
    logContainer.style.color = 'white';
    logContainer.style.padding = '10px';
    logContainer.style.borderRadius = '8px';
    logContainer.style.fontSize = '14px';
    logContainer.style.zIndex = '9999';
    logContainer.style.display = 'flex';
    logContainer.style.flexDirection = 'column';
    document.body.appendChild(logContainer);

    // 创建输入框
    const inputField = document.createElement('input');
    inputField.type = 'text';
    inputField.placeholder = '输入 domain_name (用逗号分隔)';
    inputField.style.width = '500px';
    inputField.style.padding = '5px';
    inputField.style.marginBottom = '5px';
    inputField.style.border = '1px solid #ccc';
    inputField.style.borderRadius = '4px';
     inputField.style.color = 'white';
    // 创建过滤按钮
    const filterButton = document.createElement('button');
    filterButton.innerText = '过滤';
    filterButton.style.marginLeft = '5px';
    filterButton.style.padding = '5px 10px';
    filterButton.style.background = '#007bff';
    filterButton.style.color = 'white';
    filterButton.style.border = 'none';
    filterButton.style.borderRadius = '4px';
    filterButton.style.cursor = 'pointer';

    // 创建清空按钮
    const clearButton = document.createElement('button');
    clearButton.innerText = '清空';
    clearButton.style.marginLeft = '5px';
    clearButton.style.padding = '5px 10px';
    clearButton.style.background = '#dc3545';
    clearButton.style.color = 'white';
    clearButton.style.border = 'none';
    clearButton.style.borderRadius = '4px';
    clearButton.style.cursor = 'pointer';

    // 将输入框和按钮添加到日志窗口
    logContainer.appendChild(inputField);
    logContainer.appendChild(filterButton);
    logContainer.appendChild(clearButton);

    let filterDomains = [];
    let capturedData = []; // 用于存储捕获的请求数据

    // 过滤按钮点击事件
    filterButton.addEventListener('click', () => {
        const inputText = inputField.value.trim();
        if (inputText) {
            filterDomains = inputText.split(',').map(domain => domain.trim());
            logMessage(`<b>✅ 过滤列表更新:</b> ${JSON.stringify(filterDomains)}`);
        }

        // 过滤并展示数据
        applyFilter();
    });

    // 清空按钮点击事件
    clearButton.addEventListener('click', () => {
        // 清空日志窗口内容
        logContainer.innerHTML = '';
        // 重新添加输入框和按钮
        logContainer.appendChild(inputField);
        logContainer.appendChild(filterButton);
        logContainer.appendChild(clearButton);
        logMessage(`<b>🧹 日志已清空</b>`);
    });

    function logMessage(message) {
        const logItem = document.createElement('div');
        logItem.innerHTML = message;
        logContainer.appendChild(logItem);
        logContainer.scrollTop = logContainer.scrollHeight;
    }

    // 监听 XMLHttpRequest 请求
    const originalXhrOpen = XMLHttpRequest.prototype.open;
    XMLHttpRequest.prototype.open = function (method, url, ...args) {
        this._requestUrl = url;
        return originalXhrOpen.apply(this, [method, url, ...args]);
    };

    const originalXhrSend = XMLHttpRequest.prototype.send;
    XMLHttpRequest.prototype.send = function (body) {
        this.addEventListener("load", function () {
            try {
                const responseData = JSON.parse(this.responseText);

                if (responseData.data && Array.isArray(responseData.data)) {
                    // 存储捕获的数据
                    capturedData = responseData.data.map(({ domain_name, estimated_revenue }) => ({
                        domain_name,
                        estimated_revenue: parseFloat(estimated_revenue) // 将 estimated_revenue 转换为数字
                    }));

                    logMessage(`<b>📥 数据已捕获,等待过滤...</b>`);
                } else {
                    logMessage(`<b>⚠️ 服务器返回的数据格式不匹配,未找到 'data' 数组。</b>`);
                }
            } catch (error) {
                logMessage(`<b>❌ JSON 解析失败:</b> ${error.message}`);
            }
        });
        return originalXhrSend.apply(this, arguments);
    };

    // 应用过滤并展示数据
    function applyFilter() {
        if (capturedData.length === 0) {
            logMessage(`<b>⚠️ 没有捕获到数据,请先发起请求。</b>`);
            return;
        }

        let filteredData = capturedData;

        // 如果有过滤条件,就筛选数据
        if (filterDomains.length > 0) {
            filteredData = capturedData.filter(item => filterDomains.includes(item.domain_name));
        }

        // 计算总的反款金额
        const totalRevenue = filteredData.reduce((sum, item) => sum + item.estimated_revenue, 0);

        // 展示总的反款金额
        logMessage(`<b>📥 总反款:</b> ${totalRevenue.toFixed(2)}`);
    }
})();