企管帮日报提交

修改设计列表保存接口的状态参数

// ==UserScript==
// @name         企管帮日报提交
// @name:zh-CN   企管帮日报提交
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  修改设计列表保存接口的状态参数
// @description:zh-CN  修改设计列表保存接口的状态参数
// @author       焦灼
// @license      MIT
// @match        *://qiguanbang.com/*
// @match        *://*.qiguanbang.com/*
// @grant        GM_addStyle
// @grant        GM_notification
// @run-at       document-start
// @grant        unsafeWindow
// ==/UserScript==

(function() {
    'use strict';

    // 添加 unsafeWindow 引用
    const w = typeof unsafeWindow != 'undefined' ? unsafeWindow : window;
    
    function init() {
        // 添加样式
        GM_addStyle(`
            .custom-modal-overlay {
                position: fixed;
                top: 0;
                left: 0;
                right: 0;
                bottom: 0;
                background: rgba(0, 0, 0, 0.5);
                z-index: 999998;
            }
            .custom-modal {
                position: fixed;
                top: 50%;
                left: 50%;
                transform: translate(-50%, -50%);
                background: white;
                padding: 20px;
                border-radius: 8px;
                box-shadow: 0 2px 10px rgba(0,0,0,0.1);
                z-index: 999999;
                width: 300px;
            }
            .modal-title {
                font-size: 16px;
                font-weight: bold;
                margin-bottom: 15px;
                text-align: center;
            }
            .modal-buttons {
                display: flex;
                justify-content: space-around;
                margin-top: 20px;
            }
            .modal-button {
                padding: 8px 20px;
                border: none;
                border-radius: 4px;
                cursor: pointer;
                font-size: 14px;
            }
            .original-button {
                background: #f5f5f5;
                color: #666;
            }
            .modified-button {
                background: #7087ff;
                color: white;
            }
            .float-button {
                position: fixed;
                left: 20px;
                bottom: 50%;
                width: 50px;
                height: 50px;
                background: #7087ff;
                color: white;
                border-radius: 50%;
                display: flex;
                align-items: center;
                justify-content: center;
                cursor: pointer;
                box-shadow: 0 2px 10px rgba(0,0,0,0.2);
                z-index: 999997;
                font-size: 24px;
                border: none;
                transition: transform 0.2s;
            }
            .float-button:hover {
                transform: scale(1.1);
            }
        `);

        // 创建悬浮按钮
        const floatButton = document.createElement('button');
        floatButton.className = 'float-button';
        floatButton.innerHTML = '📝';
        floatButton.title = '跳转到日报';
        
        // 添加拖拽功能
        let isDragging = false;
        let currentX;
        let currentY;
        let initialX;
        let initialY;
        let xOffset = 0;
        let yOffset = 0;

        floatButton.addEventListener('mousedown', dragStart);
        document.addEventListener('mousemove', drag);
        document.addEventListener('mouseup', dragEnd);

        // 添加一个标记来追踪拖动状态
        let dragStartTime = 0;

        function dragStart(e) {
            initialX = e.clientX - xOffset;
            initialY = e.clientY - yOffset;
            dragStartTime = Date.now();
            
            if (e.target === floatButton) {
                isDragging = true;
            }
        }

        // 添加缺失的 drag 函数
        function drag(e) {
            if (isDragging) {
                e.preventDefault();
                currentX = e.clientX - initialX;
                currentY = e.clientY - initialY;
                xOffset = currentX;
                yOffset = currentY;

                floatButton.style.transform = `translate(${currentX}px, ${currentY}px)`;
            }
        }

        function dragEnd() {
            initialX = currentX;
            initialY = currentY;
            isDragging = false;
        }

        // 修改点击事件
        floatButton.addEventListener('click', async (e) => {
            if (Date.now() - dragStartTime > 200) {
                return;
            }

            try {
                // 从 cookie 获取 token
                const token = document.cookie.split(';')
                    .find(row => row.trim().startsWith('token='))
                    ?.split('=')[1];

                if (!token) {
                    showToast('未找到登录(不可用)信息,请先登录(不可用)');
                    return;
                }

                // 请求认证接口
                await fetch('https://gateway.jingyingbang.com/authentication/sv1/cut/202004302544834', {
                    method: 'GET',
                    credentials: 'include',
                    headers: {
                        'Authorization': `Bearer ${token}`
                    }
                });
                
                window.location.href = 'https://qiguanbang.com/designListPage/658ea19ed3bb4b18a67dfc6c?title=%E6%AF%8F%E6%97%A5%E5%B7%A5%E4%BD%9C%E6%B1%87%E6%8A%A5';
            } catch (error) {
                console.error('认证请求失败:', error);
                showToast('认证失败,请重试');
            }
        });

        document.body.appendChild(floatButton);

        // 创建弹窗
        function createModal() {
            return new Promise((resolve) => {
                const overlay = document.createElement('div');
                overlay.className = 'custom-modal-overlay';

                const modal = document.createElement('div');
                modal.className = 'custom-modal';
                modal.innerHTML = `
                    <div class="modal-title">请选择参数处理方式</div>
                    <div class="modal-buttons">
                        <button class="modal-button original-button">草稿</button>
                        <button class="modal-button modified-button">提交</button>
                    </div>
                `;

                overlay.appendChild(modal);
                document.body.appendChild(overlay);

                const buttons = modal.querySelectorAll('button');
                buttons[0].onclick = () => {
                    document.body.removeChild(overlay);
                    resolve(false);
                };
                buttons[1].onclick = () => {
                    document.body.removeChild(overlay);
                    resolve(true);
                };
            });
        }

        // 修改拦截器代码
        const originalXHR = w.XMLHttpRequest;
        w.XMLHttpRequest = function() {
            const xhr = new originalXHR();
            const originalOpen = xhr.open;
            const originalSend = xhr.send;

            xhr.open = function() {
                this._url = arguments[1];
                return originalOpen.apply(this, arguments);
            };

            xhr.send = async function(data) {
                if (this._url && this._url.includes('gateway.jingyingbang.com/lowcode/v2/table/data/save')) {
                    try {
                        const shouldModify = await createModal();
                        if (shouldModify) {
                            let modifiedData = JSON.parse(data);
                            modifiedData.state = 1;
                            console.log('已修改状态参数:', modifiedData);
                            data = JSON.stringify(modifiedData);
                            GM_notification({
                                text: '已将状态参数修改为1',
                                title: '参数修改成功',
                                timeout: 2000
                            });
                        }
                    } catch (e) {
                        console.error('数据处理失败:', e);
                    }
                }
                return originalSend.call(this, data);
            };

            return xhr;
        };

        // 修改 Fetch 拦截器
        const originalFetch = w.fetch;
        w.fetch = async function(url, options = {}) {
            if (typeof url === 'string' && url.includes('gateway.jingyingbang.com/lowcode/v2/table/data/save')) {
                try {
                    const shouldModify = await createModal();
                    if (shouldModify) {
                        const modifiedOptions = {...options};
                        if (modifiedOptions.body) {
                            let data = JSON.parse(modifiedOptions.body);
                            data.state = 1;
                            console.log('已修改状态参数:', data);
                            modifiedOptions.body = JSON.stringify(data);
                            GM_notification({
                                text: '已将状态参数修改为1',
                                title: '参数修改成功',
                                timeout: 2000
                            });
                            return originalFetch(url, modifiedOptions);
                        }
                    }
                } catch (e) {
                    console.error('数据处理失败:', e);
                }
            }
            return originalFetch.apply(w, arguments);
        };

        // 创建并显示 toast 提示
        function showToast(message) {
            GM_addStyle(`
                .custom-toast {
                    position: fixed;
                    bottom: 50%;
                    left: 50%;
                    transform: translateX(-50%);
                    background: rgba(0, 0, 0, 0.8);
                    color: white;
                    padding: 10px 20px;
                    border-radius: 4px;
                    z-index: 999999;
                }
            `);

            const toast = document.createElement('div');
            toast.className = 'custom-toast';
            toast.textContent = message;
            document.body.appendChild(toast);

            setTimeout(() => {
                document.body.removeChild(toast);
            }, 3000);
        }

        // 将控制台日志改为 toast 提示
        showToast('企管帮日报提交脚本已启动');
        console.log('企管帮日报提交脚本已启动');

        // 添加自动处理按钮的函数
        function handleButtons() {
            const footerContainer = document.querySelector('.footer-container');
            if (footerContainer) {
                // 注释掉主要按钮
                const primaryBtn = footerContainer.querySelector('.el-button--primary');
                if (primaryBtn) {
                    primaryBtn.style.display = 'none';
                }
                
                // 修改默认按钮宽度
                const defaultBtn = footerContainer.querySelector('.el-button--default');
                if (defaultBtn) {
                    defaultBtn.style.width = '100px';
                    defaultBtn.textContent = '自动处理';
                }
            }
        }

        // 使用 MutationObserver 监听 DOM 变化
        const observer = new MutationObserver((mutations) => {
            handleButtons();
        });

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

        // 初始执行一次
        handleButtons();
    }

    // 使用 setTimeout 确保在页面加载完成后执行
    setTimeout(init, 2000);
})();

QingJ © 2025

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