// ==UserScript== // @name 美的 CSS 系统 鉴定单打印 // @namespace http://tampermonkey.net/ // @version 3.0 // @description 跳过 “退换机处理状态为‘鉴定审核通过’和之后的非驳回状态或者服务单状态为‘网点封单’和‘已结单’才能打印” 的提示 // @author 雪 // @match https://cs.midea.com/v3/portal/jsp/wom/identify/* // @grant none // ==/UserScript== (function() { 'use strict'; // 核心替换逻辑 function replacePrintButton() { // 按钮的 id 包含特殊字符,用 getElementById 精准抓取 var printBtn = document.getElementById("btnidentify_archives_view.print()"); if (printBtn && !printBtn.dataset.hooked) { console.log("[油猴脚本] 找到打印按钮,正在替换为新窗口打开模式..."); // 1. 移除原本的 onclick 属性,掐断原有的状态检查 printBtn.removeAttribute("onclick"); // 2. 绑定极简版的新窗口打开逻辑 printBtn.onclick = function(e) { e.preventDefault(); // 阻止 a 标签的默认点击行为 try { // 确保全局所需的 vModel 数据已经存在 if (!window.vModel || !window.vModel.returnObject || !window.vModel.returnObject.identifyVO) { alert("页面数据尚未加载完全,获取打印链接失败!"); return; } // 组装打印请求路径 var identifyId = window.vModel.returnObject.identifyVO.identifyId; var currentCtx = typeof window.ctx !== 'undefined' ? window.ctx : ''; // 最终拼接出来的相对路径或绝对路径 var src = currentCtx + "/wom/identify/identifyPrint/" + identifyId; console.log("[油猴脚本] 成功获取路径,正在新窗口打开:", src); // 核心动作:直接在新标签页/新窗口打开该路径 window.open(src, '_blank'); } catch (err) { console.error("[油猴脚本] 拼接路径过程中发生错误:", err); alert("获取打印链接出错,请按 F12 查看控制台日志。"); } }; // 标记为已替换,防止定时器重复绑定 printBtn.dataset.hooked = "true"; return true; } return false; } // 页面加载时按钮大概率是动态渲染出来的,使用轮询等待机制 let timer = setInterval(() => { if (replacePrintButton()) { clearInterval(timer); // 替换成功后清除定时器 console.log("[油猴脚本] 打印按钮替换完成!点击将在新标签页直接打开打印页面。"); } }, 500); // 设置 30 秒超时,防止无限轮询消耗性能 setTimeout(() => { clearInterval(timer); }, 30000); })();