SmartPP Helper

增强分发系统功能,检验分发系统异常值

目前为 2020-11-04 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name SmartPP Helper
  3. // @namespace http://minhill.com
  4. // @version 0.2
  5. // @description 增强分发系统功能,检验分发系统异常值
  6. // @author Minhill
  7. // @include http://10.148.16.64:8080/*
  8. // @include http://10.148.16.63:8080/*
  9. // @include http://10.148.16.40:8080/*
  10. // @grant GM_addStyle
  11. // @supportURL https://gf.qytechs.cn/scripts/415457
  12. // @homepage https://gf.qytechs.cn/zh-CN/scripts/415457
  13. // ==/UserScript==
  14.  
  15. (function () {
  16. 'use strict';
  17. let config = {
  18. keyword: {
  19. CN: {
  20. tMax: '最高温度',
  21. tMin: '最低温度',
  22. fcTime: '预报时效',
  23. timeSplit: '至',
  24. hour08: '08时',
  25. hourReg: /(\d{2})时/,
  26. },
  27. EN: {
  28. tMax: 'Maximum Temperature',
  29. tMin: 'Minimum Temperature',
  30. fcTime: 'Forecast Period',
  31. timeSplit: ' - ',
  32. hour08: '08:00',
  33. hourReg: /(\d{2}):00/,
  34. }
  35. }
  36. }
  37. /**
  38. *
  39. * @param {Object} table 表 Html DOM
  40. */
  41. function validateTemp(table) {
  42.  
  43. let IntlWords;
  44. if (table.textContent.includes('预报时效')) {
  45. // 中文
  46. IntlWords = config.keyword.CN;
  47. }
  48. else if (table.textContent.includes('Forecast')) {// 英文
  49. IntlWords = config.keyword.EN;
  50. } else {
  51. console.log('未识别语言');
  52. return;
  53. }
  54.  
  55. var tBody = table.children[0];
  56. let TimeRow, TmaxRow, TminRow;
  57. for (let tr of tBody.children) {// 获取高低温行元素
  58. if (tr.textContent.includes(IntlWords.fcTime)) TimeRow = tr;// Forecast Period
  59. if (tr.textContent.includes(IntlWords.tMax)) TmaxRow = tr;// Maximum Temperature
  60. if (tr.textContent.includes(IntlWords.tMin)) TminRow = tr;// Minimum Temperature
  61. }
  62. if (!TmaxRow) return;// 没有最高最低温直接返回
  63. let [tMaxList, tMinList, timeList] = [ [], [], [] ];
  64. for (let index = 1; index < TmaxRow.children.length; index++) {// 导入高低温数据
  65. tMinList.push(Number(TminRow.children[index].textContent));
  66. tMaxList.push(Number(TmaxRow.children[index].textContent));
  67. timeList.push(TimeRow.children[index].textContent);
  68. }
  69.  
  70. let initHour = NaN,endHour = NaN;
  71. var timePeroidList = timeList[0].split(IntlWords.timeSplit);
  72. if (timePeroidList.length === 1) throw new Error('未识别的日期分隔符');
  73. let initHourMatched = timePeroidList[0].match(IntlWords.hourReg);
  74. if (initHourMatched) {
  75. initHour = Number(initHourMatched[1]);
  76. } else {
  77. throw new Error('未识别的日期格式' + timePeroidList[0]);
  78. }
  79. let endHourMatched = timePeroidList[1].match(IntlWords.hourReg);
  80. if (endHourMatched) {
  81. endHour = Number(endHourMatched[1]);
  82. } else {
  83. throw new Error('未识别的日期格式' + timePeroidList[1]);
  84. }
  85.  
  86. let validTmaxList,validTminList;
  87. if ((initHour === 8 && endHour === 20) || (initHour === 20 && endHour === 8)) {
  88. validTmaxList = new Array(tMaxList.length / 2);
  89. validTminList = new Array(tMaxList.length / 2);
  90. } else {
  91. console.log(`非正点时次${initHour}, ${endHour}`);
  92. return;
  93. }
  94. for (let i = 0; i < validTmaxList.length; i++) {// 判断每一对温度
  95. if (initHour === 8 && endHour === 20) {
  96. validTmaxList[i] = tMaxList[i * 2] > tMaxList[i * 2 + 1];
  97. validTminList[i] = tMinList[i * 2] > tMinList[i * 2 + 1];
  98. } else if (initHour === 20 && endHour === 8) {
  99. validTmaxList[i] = tMaxList[i * 2] < tMaxList[i * 2 + 1];
  100. validTminList[i] = tMinList[i * 2] < tMinList[i * 2 + 1];
  101. } else {
  102. console.log(`非正点时次${initHour}, ${endHour}`);
  103. return;
  104. }
  105. }
  106. changeValidStatus(validTmaxList, TmaxRow);
  107. changeValidStatus(validTminList, TminRow);
  108. }
  109.  
  110. /**
  111. *
  112. * @param {Array} validList 判断列表
  113. * @param {Object} tempRow 温度行元素
  114. */
  115. function changeValidStatus(validList, tempRow) {
  116. validList.forEach((iValid, index) => {
  117. if (iValid) {
  118. tempRow.children[1 + index * 2].classList.add("valid-success");
  119. tempRow.children[1 + index * 2 + 1].classList.add("valid-success");
  120. tempRow.children[1 + index * 2].classList.remove("valid-error");
  121. tempRow.children[1 + index * 2 + 1].classList.remove("valid-error");
  122. } else {
  123. tempRow.children[1 + index * 2].classList.add("valid-error");
  124. tempRow.children[1 + index * 2 + 1].classList.add("valid-error");
  125. tempRow.children[1 + index * 2].classList.remove("valid-success");
  126. tempRow.children[1 + index * 2 + 1].classList.remove("valid-success");
  127. }
  128. });
  129. }
  130.  
  131. /**
  132. * 获取表格
  133. */
  134. function tableSelector() {
  135. var tableList = document.querySelectorAll('table.text_table2');
  136. for (let iTable of tableList) {
  137. validateTemp(iTable);
  138. }
  139. }
  140.  
  141. /**
  142. * 模板部分监听器
  143. */
  144. function templateObserver() {
  145. const targetNode = document.getElementById('templatePreContent');// 选择需要观察变动的节点
  146. const config = { childList: true, subtree: false };// 观察器的配置(需要观察什么变动)
  147. const callback = function (mutationsList, observer) {// 当观察到变动时执行的回调函数
  148. tableSelector();
  149. };
  150. const observer = new MutationObserver(callback);// 创建一个观察器实例并传入回调函数
  151. observer.observe(targetNode, config);// 以上述配置开始观察目标节点
  152. }
  153.  
  154. /**
  155. * 主入口函数
  156. */
  157. function main() {
  158. var style = '<style>.valid-success{background-color:green;}.valid-error{background-color:orange;}</style>';
  159. var ele = document.createElement('div');
  160. ele.innerHTML = style;
  161. document.getElementsByTagName('head')[0].appendChild(ele.firstElementChild);
  162. lookUpTarget();
  163. }
  164.  
  165. /**
  166. * 处理注入问题
  167. */
  168. function lookUpTarget() {
  169. const targetNode = document.getElementById('templatePreContent');
  170. if(targetNode){
  171. return templateObserver()
  172. }else{
  173. console.log('未找到目标元素,等待5秒重新查找');
  174. return setTimeout(lookUpTarget, 5000);
  175. }
  176. }
  177.  
  178. main();
  179.  
  180. })();

QingJ © 2025

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