Greasy Fork

Greasy Fork is available in English.

印迹查看要过期的视觉需求

自動點擊美團 Ingee 頁面元素並統計日期 (使用最快速的北京時間比較和正確的日期提取)

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         印迹查看要过期的视觉需求
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  自動點擊美團 Ingee 頁面元素並統計日期 (使用最快速的北京時間比較和正確的日期提取)
// @author       Gemini
// @match        https://ingee.meituan.com/*
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';

    function clickElement(xpath) {
        try {
            const element = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
            if (element) {
                element.click();
                console.log("成功點擊元素: " + xpath);
                return true;
            } else {
                console.log("未找到元素: " + xpath);
                return false;
            }
        } catch (error) {
            console.error("點擊元素出錯: " + error);
            return false;
        }
    }

    function executeClicksAndAnalyze() {
        const step1Success = clickElement('//*[@id="app"]/main/div/div/div[2]/div[2]/div[2]/div[1]/p[4]');

        if (step1Success) {
            setTimeout(() => {
                const step2Success = clickElement('//*[@id="app"]/main/div/div/div[2]/div[2]/div[2]/div[3]/div/div/div');
                if (step2Success) {
                    setTimeout(() => {
                        clickElement('/html/body/div[5]/ul/div/li[4]');
                        setTimeout(() => { analyzeDates(); }, 1500); // 確保下拉選單內容載入完成
                    }, 500);
                }
            }, 1000);
        }
    }

    function analyzeDates() {
        let todayCount = 0;
        let futureCount = 0;

        const dateElements = document.querySelectorAll('.mtd-ingee-table-body p.cycle');

        const todayString = new Date().toLocaleDateString('zh-CN', { timeZone: 'Asia/Shanghai', year: 'numeric', month: '2-digit', day: '2-digit' }).replace(/\//g, '/');

        dateElements.forEach(element => {
            const dateText = extractEndDate(element.textContent);
            if (dateText) {
                if (dateText === todayString) {
                    todayCount++;
                } else if (dateText < todayString) {
                    futureCount++;
                }
            }
        });

        displayResults(todayCount, futureCount);
    }

    function extractEndDate(text) {
        if (!text) return null;

        const parts = text.split('至');
        if (parts.length === 2) {
            const endDate = parts[1].trim();
            if (endDate.match(/^\d{4}\/\d{2}\/\d{2}$/)) {
                return endDate;
            }
        }
        return null;
    }

    function displayResults(todayCount, futureCount) {
        const oldResultDiv = document.getElementById('ingee-result');
        if (oldResultDiv) {
            oldResultDiv.remove();
        }

        const resultDiv = document.createElement('div');
        resultDiv.id = 'ingee-result';
        resultDiv.style.position = 'fixed';
        resultDiv.style.top = '6px';
        resultDiv.style.right = '0px';
        resultDiv.style.backgroundColor = 'white';
        resultDiv.style.padding = '10px';
        resultDiv.style.border = '0px solid black';
        resultDiv.style.zIndex = 9999;
        resultDiv.innerHTML = `今天到期 <b>${todayCount}</b> 个视觉需求,已过期 <b>${futureCount}</b> 个视觉需求`;
        document.body.appendChild(resultDiv);
    }

    let checkInterval = setInterval(() => {
        if (document.readyState === 'complete') {
            clearInterval(checkInterval);
            executeClicksAndAnalyze();
        }
    }, 500);
})();