这是一个浏览器js插件,可以实现打开工单监控界面无需设置自动语音播报,关闭页面自动停播。
播报内容包含工单总量,待领取,待回复,挂起四项。代码19行是播报时间间隔。
步骤:
1.用Edge浏览器,打开篡改猴插件安装
2.安装篡改猴插件后浏览器打开:
“extension://fcmfnpggmnlmfebfghbfnillijihnkoh/options.html#nav=new-user-script+editor”
新建用户脚本并保存
3.将以下代码第21行的星号,改成网点ID,加入脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
// ==UserScript== // @name 工单多指标监控 // @namespace https://snote.cn/ // @version 1.8 // @description 监控发起总量、待领取、待回复、挂起数量 // @author ZhangZsky // @match *://r.woms.jd.com/* // @grant GM_xmlhttpRequest // @grant GM_getValue // ==/UserScript== // 使用立即执行函数表达式(IIFE)来创建一个独立的作用域,避免全局变量污染 (function() { // 开启严格模式,有助于编写更规范、更安全的代码 'use strict'; // 定义API的URL,用于请求工单数据 const API_URL = "http://xg.jd.com/dataApi/api/realtime/v1/department"; // 定义数据刷新的时间间隔,单位为毫秒,这里设置为10分钟 const REFRESH_INTERVAL = 10 * 60 * 1000; // 定义目标部门的ID,需要与API返回的processDeptId一致 const DEPARTMENT_ID = ****; // 定义每页请求的数据数量 const PAGE_SIZE = 100; // 获取动态时间范围(昨天0点至明天24点) function getDynamicTimeRange() { // 获取当前时间 const now = new Date(); // 创建一个昨天的日期对象 const yesterday = new Date(now); // 将日期设置为昨天 yesterday.setDate(yesterday.getDate() - 1); // 格式化昨天的日期为"YYYY-MM-DD 00:00:00"的格式 const startTime = `${yesterday.toISOString().split('T')[0]} 00:00:00`; // 创建一个明天的日期对象 const tomorrow = new Date(now); // 将日期设置为明天 tomorrow.setDate(tomorrow.getDate() + 1); // 格式化明天的日期为"YYYY-MM-DD 23:59:59"的格式 const endTime = `${tomorrow.toISOString().split('T')[0]} 23:59:59`; // 返回包含开始时间和结束时间的对象 return { startTime, endTime }; } // 获取当前页面Cookie function getCurrentCookies() { // 将document.cookie字符串按"; "分割成数组,然后使用reduce方法将其转换为对象 return document.cookie.split('; ').reduce((acc, cookie) => { // 将每个cookie字符串按"="分割成键值对 const [k, v] = cookie.split('='); // 将键值对添加到累加器对象中 acc[k] = v; // 返回累加器对象 return acc; }, {}); } // 语音提醒函数 function speakMessage(initiate, pending, reply, suspend) { // 打印函数调用的时间日志 console.log(`[${new Date().toLocaleString()}] speakMessage 函数被调用`); // 定义一个空数组,用于存储要播报的消息片段 const parts = []; // 发起总量(totalCount) parts.push(`发起总量:${initiate}`); // 待领取总量(pendingFetchCount) parts.push(`待领取:${pending}`); // 待回复总量(pendingReplyCount) parts.push(`待回复:${reply}`); // 挂起数量(suspendCount) parts.push(`客服挂起:${suspend}`); // 获取当前时间,格式为"HH:MM" const time = new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); // 拼接完整的消息 const message = `[${time}] ${parts.join(',')}`; // 打印要播报的消息 console.log(message); // 获取浏览器的语音合成对象 const synth = window.speechSynthesis; // 创建一个语音合成的话语对象 const utterance = new SpeechSynthesisUtterance(message); // 设置话语的语言为中文 utterance.lang = 'zh-CN'; // 开始语音播报 synth.speak(utterance); } // 核心数据获取函数 function fetchWorkorderData() { // 打印函数调用的时间日志 console.log(`[${new Date().toLocaleString()}] fetchWorkorderData 函数被调用`); // 获取动态时间范围 const { startTime, endTime } = getDynamicTimeRange(); // 获取当前页面的Cookie const cookies = getCurrentCookies(); // 定义请求的数据对象 const requestData = { startTime, endTime, processDeptIds: [DEPARTMENT_ID], // 关键:指定监控的部门ID sortInd: "totalCount", sort: "desc", processDeptLevel: 4, pageNum: 1, pageSize: PAGE_SIZE, showAssignedBroOnly: false }; // 使用GM_xmlhttpRequest发送POST请求 GM_xmlhttpRequest({ method: "POST", url: API_URL, headers: { // 设置请求头的Content-Type为application/json "Content-Type": "application/json", // 将Cookie对象转换为字符串添加到请求头中 "Cookie": Object.entries(cookies).map(([k, v]) => `${k}=${v}`).join("; "), // 设置请求的来源页面 "Referer": "http://r.woms.jd.com/workorder/list" }, // 将请求数据对象转换为JSON字符串 data: JSON.stringify(requestData), // 请求成功的回调函数 onload: (response) => { // 打印请求成功回调函数调用的时间日志 console.log(`[${new Date().toLocaleString()}] 请求成功回调函数被调用`); try { // 将响应的文本数据解析为JSON对象 const result = JSON.parse(response.responseText); // 获取响应数据中的data字段,若不存在则为空对象 const data = result.data || {}; // 提取汇总数据 const summaryData = data.summary; // 若未找到汇总数据,打印警告信息并返回 if (!summaryData) { console.warn("未找到汇总数据"); return; } // 提取指标(根据API响应结构调整) const initiateCount = summaryData.totalCount || 0; // 发起总量 const pendingFetchCount = summaryData.pendingFetchCount || 0; // 待领取总量 const pendingReplyCount = summaryData.pendingReplyCount || 0; // 待回复总量 const suspendCount = summaryData.suspendCount || 0; // 挂起数量 // 调用语音提醒函数进行播报 speakMessage(initiateCount, pendingFetchCount, pendingReplyCount, suspendCount); // 将最后一次获取的工单数据保存到本地 GM_setValue("lastWorkorderData", summaryData); } catch (error) { // 若数据解析失败,打印错误信息和响应文本 console.error("数据解析失败:", error, response.responseText); } }, // 请求失败的回调函数 onerror: (error) => { // 打印请求失败的错误信息 console.error("请求失败:", error); } }); } // 第一次获取数据并播报 fetchWorkorderData(); // 按照REFRESH_INTERVAL设定的频率定时获取数据并播报 setInterval(fetchWorkorderData, REFRESH_INTERVAL); })(); |
4.再打开”extension://fcmfnpggmnlmfebfghbfnillijihnkoh/options.html#nav=dashboard”已安装脚本中确认脚本已经启用
5.打开工单监控网址http://r.woms.jd.com/#即可,无需设置自动播报。
鄙人水平不行,有问题别问更别请教,我不配!
发表回复