【油猴脚本】集团OA显示主要领导后续处理环节

油猴脚本,处理集团OA文件,获取主要领导文件下一步分发动作,防止重复提交。

隐藏部分关键信息

// ==UserScript==
// @name         集团OA显示徐XX后续处理环节
// @namespace    http://tampermonkey.net/
// @version      2.5
// @description  后台获取处理人"徐XX"的"后续处理环节"内容并在页面右上角显示(完全无感模式,无闪烁)
// @author       You
// @match        http://XXXXXX/std-official-document-view/g4/process-form*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    let isProcessing = false;
    let observer = null;
    let dataCheckInterval = null;
    let dialogHideInterval = null;

    // 创建页面右上角显示区域
    function createPageDisplayArea(content) {
        let displayDiv = document.getElementById('xuXX-display');
        if (!displayDiv) {
            displayDiv = document.createElement('div');
            displayDiv.id = 'xuXX-display';
            displayDiv.style.cssText = `
                position: fixed;
                top: 10px;
                right: 10px;
                background-color: #e6f7ff;
                border: 1px solid #1890ff;
                padding: 8px 12px;
                z-index: 9999;
                font-size: 12px;
                border-radius: 4px;
                box-shadow: 0 2px 8px rgba(0,0,0,0.15);
                max-width: 280px;
                max-height: 80px;
                overflow: hidden;
            `;

            const title = document.createElement('div');
            title.style.cssText = `
                font-weight: bold;
                color: #1890ff;
                margin-bottom: 3px;
                font-size: 12px;
            `;
            title.textContent = '徐XX后续处理:';
            displayDiv.appendChild(title);

            const contentDiv = document.createElement('div');
            contentDiv.id = 'xuXX-content';
            contentDiv.style.cssText = `
                color: #333;
                word-break: break-all;
                line-height: 1.3;
                font-size: 11px;
            `;
            contentDiv.textContent = content || '获取中...';
            displayDiv.appendChild(contentDiv);

            document.body.appendChild(displayDiv);
        } else {
            document.getElementById('xuXX-content').textContent = content || '未找到相关信息';
            displayDiv.style.display = 'block';
        }

        return displayDiv;
    }

    // 完全无感隐藏对话框
    function hideDialogCompletely() {
        try {
            // 停止之前的隐藏监控
            if (dialogHideInterval) {
                clearInterval(dialogHideInterval);
            }

            // 动态注入样式,强制隐藏所有可能的对话框
            const style = document.createElement('style');
            style.id = 'xuXX-hide-dialog';
            style.textContent = `
                .el-dialog[aria-label="流程跟踪"],
                .el-dialog:has(.el-dialog__title:not(:empty):contains("流程跟踪")) {
                    display: none !important;
                    visibility: hidden !important;
                    opacity: 0 !important;
                    position: absolute !important;
                    left: -9999px !important;
                    top: -9999px !important;
                    width: 0 !important;
                    height: 0 !important;
                    pointer-events: none !important;
                }
                .el-dialog__wrapper:has(.el-dialog[aria-label="流程跟踪"]),
                .el-dialog__wrapper:has(.el-dialog .el-dialog__title:not(:empty):contains("流程跟踪")) {
                    display: none !important;
                    visibility: hidden !important;
                }
            `;
            document.head.appendChild(style);

            // 持续监控并隐藏对话框(以防动态加载绕过样式)
            dialogHideInterval = setInterval(() => {
                const dialogs = document.querySelectorAll('.el-dialog');
                dialogs.forEach(dialog => {
                    const title = dialog.querySelector('.el-dialog__title');
                    if (title && title.textContent.trim() === '流程跟踪') {
                        dialog.style.cssText = `
                            display: none !important;
                            visibility: hidden !important;
                            opacity: 0 !important;
                            position: absolute !important;
                            left: -9999px !important;
                            top: -9999px !important;
                            width: 0 !important;
                            height: 0 !important;
                        `;
                        // 隐藏父级 wrapper
                        const wrapper = dialog.closest('.el-dialog__wrapper');
                        if (wrapper) {
                            wrapper.style.display = 'none !important';
                        }
                    }
                });
            }, 20); // 提高检查频率到20ms,确保无闪烁

            // 3秒后停止隐藏检查(减少资源占用)
            setTimeout(() => {
                if (dialogHideInterval) {
                    clearInterval(dialogHideInterval);
                    dialogHideInterval = null;
                }
                // 移除动态样式
                const styleElement = document.getElementById('xuXX-hide-dialog');
                if (styleElement) {
                    styleElement.remove();
                }
            }, 3000);

        } catch (e) {
            console.error('[徐XX脚本] 隐藏对话框异常:', e);
        }
    }

    // 彻底关闭流程跟踪对话框
    function closeProcessTraceDialog() {
        try {
            if (dialogHideInterval) {
                clearInterval(dialogHideInterval);
                dialogHideInterval = null;
            }

            const dialogs = document.querySelectorAll('.el-dialog');
            for (let dialog of dialogs) {
                const title = dialog.querySelector('.el-dialog__title');
                if (title && title.textContent.trim() === '流程跟踪') {
                    const closeBtn = dialog.querySelector('.el-dialog__headerbtn');
                    if (closeBtn) {
                        closeBtn.click();
                        const event = new MouseEvent('click', {
                            view: window,
                            bubbles: true,
                            cancelable: true
                        });
                        closeBtn.dispatchEvent(event);
                    }
                    setTimeout(() => {
                        if (dialog.parentNode) {
                            dialog.parentNode.removeChild(dialog);
                        }
                    }, 50);
                    return true;
                }
            }
            return false;
        } catch (e) {
            console.error('[徐XX脚本] 关闭对话框异常:', e);
            return false;
        }
    }

    // 清理所有定时器和观察器
    function cleanup() {
        if (dataCheckInterval) {
            clearInterval(dataCheckInterval);
            dataCheckInterval = null;
        }

        if (dialogHideInterval) {
            clearInterval(dialogHideInterval);
            dialogHideInterval = null;
        }

        if (observer) {
            observer.disconnect();
            observer = null;
        }

        isProcessing = false;
    }

    // 提取徐XX信息
    function extractXuXXInfo(processFlow) {
        let foundContent = '未找到相关信息';

        if (dataCheckInterval) {
            clearInterval(dataCheckInterval);
        }

        const checkDataLoaded = () => {
            try {
                const rows = processFlow.querySelectorAll('.el-table__body tbody tr');
                if (rows.length > 0) {
                    clearInterval(dataCheckInterval);
                    dataCheckInterval = null;

                    for (let i = 0; i < rows.length; i++) {
                        const row = rows[i];
                        const processorCell = row.querySelector('.el-table_1_column_2 .cell');
                        if (processorCell && processorCell.textContent.trim() === '徐XX') {
                            const nextStepCell = row.querySelector('.el-table_1_column_6 .cell');
                            if (nextStepCell) {
                                foundContent = nextStepCell.textContent.trim() || '无后续处理';
                                break;
                            }
                        }
                    }

                    setTimeout(() => {
                        closeProcessTraceDialog();
                        createPageDisplayArea(foundContent);
                        cleanup();
                    }, 50);

                    return true;
                }
                return false;
            } catch (e) {
                console.error('[徐XX脚本] 检查数据加载错误:', e);
                return false;
            }
        };

        if (checkDataLoaded()) {
            return;
        }

        dataCheckInterval = setInterval(() => {
            if (checkDataLoaded()) {
                // 数据加载完成
            }
        }, 100); // 降低检查频率到100ms,减少性能开销

        setTimeout(() => {
            if (dataCheckInterval) {
                clearInterval(dataCheckInterval);
                dataCheckInterval = null;
                closeProcessTraceDialog();
                createPageDisplayArea('数据加载超时');
                cleanup();
            }
        }, 6000); // 缩短超时时间到6秒
    }

    // 完全无感获取徐XX信息
    function getXuXXInfoInvisible() {
        if (isProcessing) return;

        isProcessing = true;
        createPageDisplayArea('正在获取信息...');

        try {
            const traceButton = document.querySelector('button[label="流程跟踪"][event="trace"]');
            if (!traceButton) {
                createPageDisplayArea('未找到流程跟踪按钮');
                cleanup();
                return;
            }

            // 提前注入隐藏逻辑
            hideDialogCompletely();

            observer = new MutationObserver((mutations, obs) => {
                for (const mutation of mutations) {
                    if (mutation.type === 'childList') {
                        for (const node of mutation.addedNodes) {
                            if (node.nodeType === 1) {
                                let processFlow = null;
                                if (node.classList?.contains('jdf-process-flow')) {
                                    processFlow = node;
                                } else if (node.querySelector) {
                                    processFlow = node.querySelector('.jdf-process-flow');
                                }

                                if (processFlow) {
                                    console.log('[徐XX脚本] 检测到流程跟踪对话框');
                                    extractXuXXInfo(processFlow);
                                    return; // 立即处理,减少不必要循环
                                }
                            }
                        }
                    }
                }
            });

            observer.observe(document.body, {
                childList: true,
                subtree: true
            });

            // 延迟点击,确保隐藏逻辑生效
            setTimeout(() => {
                console.log('[徐XX脚本] 点击流程跟踪按钮');
                traceButton.click();
            }, 100);

            setTimeout(() => {
                if (isProcessing) {
                    console.log('[徐XX脚本] 整体超时');
                    closeProcessTraceDialog();
                    createPageDisplayArea('操作超时');
                    cleanup();
                }
            }, 10000); // 缩短整体超时到10秒

        } catch (error) {
            console.error('[徐XX脚本] 错误:', error);
            closeProcessTraceDialog();
            createPageDisplayArea('获取失败');
            cleanup();
        }
    }

    // 初始化
    function init() {
        console.log('[徐XX脚本] 完全无感模式启动');
        setTimeout(() => {
            getXuXXInfoInvisible();
        }, 2000); // 缩短初始化延迟到2秒
    }

    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', () => {
            setTimeout(init, 1500);
        });
    } else {
        setTimeout(init, 2000);
    }
})();