CNVD_Modify

CNVD添加复制漏洞列表页面单个或所有漏洞标题、优化用户中心已提交漏洞展示和复制漏洞编号

  1. // ==UserScript==
  2. // @name CNVD_Modify
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @description CNVD添加复制漏洞列表页面单个或所有漏洞标题、优化用户中心已提交漏洞展示和复制漏洞编号
  6. // @author Mrxn
  7. // @homepage https://mrxn.net/
  8. // @supportURL https://github.com/Mr-xn/CNVD_Modify
  9. // @license MIT
  10. // @run-at document-end
  11. // @match https://www.cnvd.org.cn/*
  12. // @icon https://www.google.com/s2/favicons?sz=64&domain=cnvd.org.cn
  13. // @grant none
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. 'use strict';
  18.  
  19. // Your code here...
  20.  
  21. function copy_all_vuln_title(){
  22. // 获取表格元素
  23. const table = document.querySelector('.tlist');
  24.  
  25. // 获取表格中的thead和tbody元素
  26. const thead = table.querySelector('thead');
  27. const tbody = table.querySelector('tbody');
  28.  
  29. // 获取所有的tr元素
  30. const trList = tbody.querySelectorAll('tr');
  31.  
  32. // 获取表格中的第一个th元素
  33. const th = thead.querySelector('th:first-child');
  34.  
  35. // 创建复制按钮
  36. const btn = document.createElement('button');
  37. btn.textContent = '复制所有标题';
  38.  
  39. // 给复制按钮设置样式
  40. btn.style.position = 'relative';
  41. btn.style.top = 0;
  42. btn.style.right = 0;
  43. btn.style.paddingLeft = '10px';
  44.  
  45. // 给复制按钮添加点击事件
  46. btn.addEventListener('click', () => {
  47. // 创建一个数组,用于保存所有的title属性值
  48. const titles = [];
  49. // 遍历所有的tr元素
  50. trList.forEach(tr => {
  51. // 获取当前tr元素下的第一个td元素
  52. const td = tr.querySelector('td:first-child');
  53. // 如果当前td元素下有a标签
  54. const a = td.querySelector('a');
  55. if (a) {
  56. // 将a标签的title属性值添加到数组中
  57. titles.push(a.getAttribute('title') || a.outerText);
  58. }
  59. });
  60. // 将title属性值以换行符为分隔符合并为一个字符串
  61. const text = titles.join('\n');
  62. // 创建一个临时的textarea元素
  63. const textarea = document.createElement('textarea');
  64. // 将合并后的字符串赋值给textarea元素的value属性
  65. textarea.value = text;
  66. // 将textarea元素添加到页面中
  67. document.body.appendChild(textarea);
  68. // 选中textarea元素中的文本
  69. textarea.select();
  70. // 复制选中的文本
  71. document.execCommand('copy');
  72. // 删除临时的textarea元素
  73. document.body.removeChild(textarea);
  74. });
  75.  
  76. // 将复制按钮添加到th元素中
  77. th.appendChild(btn);
  78. }
  79.  
  80. function user_copy(){
  81. // 判断当前页面是否为 https://www.cnvd.org.cn/
  82. if (window.location.href.startsWith('https://www.cnvd.org.cn/')) {
  83. //优化用户中心的已提交漏洞列表展示
  84. var elements = document.querySelectorAll('.tlist th, .tlist td');
  85. for (var i = 0; i < elements.length; i++) {
  86. elements[i].style.padding = '0';
  87. }
  88.  
  89. //优化漏洞列表页面给每条漏洞前面添加复制按钮
  90. // 获取所有的td元素
  91. const tdList = document.querySelectorAll('tbody td');
  92.  
  93. // 遍历所有的td元素
  94. tdList.forEach(td => {
  95. // 获取a标签元素
  96. const a = td.querySelector('a');
  97. if (!a) {
  98. return;
  99. }
  100. // 创建复制按钮
  101. const btn = document.createElement('button');
  102. btn.textContent = '复制';
  103.  
  104. // 给复制按钮设置样式
  105. btn.style.position = 'relative';
  106. btn.style.top = 0;
  107. btn.style.right = 0;
  108.  
  109. // 根据a标签的href属性判断复制的内容
  110. if (a.getAttribute('href').startsWith('/flaw/show/')) {
  111. //复制单独的每一条漏洞标题
  112. // 复制a标签的title属性
  113. btn.addEventListener('click', () => {
  114. // 创建一个临时的textarea元素
  115. const textarea = document.createElement('textarea');
  116. // 将a标签的title属性赋值给textarea元素的value属性
  117. textarea.value = a.getAttribute('title') || a.outerText;
  118. // 将textarea元素添加到页面中
  119. document.body.appendChild(textarea);
  120. // 选中textarea元素中的文本
  121. textarea.select();
  122. // 复制选中的文本
  123. document.execCommand('copy');
  124. // 删除临时的textarea元素
  125. document.body.removeChild(textarea);
  126. });
  127. } else if (a.getAttribute('href').startsWith('/user/myreport/')) {
  128. // 复制a标签的文本内容
  129. btn.addEventListener('click', () => {
  130. // 创建一个临时的textarea元素
  131. const textarea = document.createElement('textarea');
  132. // 将a标签的文本内容赋值给textarea元素的value属性
  133. textarea.value = a.textContent;
  134. // 将textarea元素添加到页面中
  135. document.body.appendChild(textarea);
  136. // 选中textarea元素中的文本
  137. textarea.select();
  138. // 复制选中的文本
  139. document.execCommand('copy');
  140. // 删除临时的textarea元素
  141. document.body.removeChild(textarea);
  142. });
  143. } else {
  144. // 如果a标签的href属性既不以/flaw/show/开头,也不以/user/myreport/开头,则不添加复制按钮
  145. return;
  146. }
  147.  
  148. // 将复制按钮添加到td元素中
  149. td.appendChild(btn);
  150. });
  151. }
  152. }
  153. function run(){
  154. if (window.location.href.startsWith('https://www.cnvd.org.cn/')){
  155. user_copy();
  156. }
  157. if (window.location.href.includes('/flaw/list') || window.location.href.includes('/flaw/flawListByManu')) {
  158. //添加复制所有漏洞标题按钮
  159. copy_all_vuln_title();
  160. }
  161. }
  162. function Surveillance(){
  163. // 监视 table 内容的变化
  164. const observer = new MutationObserver(function(mutationsList, observer) {
  165. // 遍历每一个变化
  166. for (let mutation of mutationsList) {
  167. // 如果变化发生在 table 中,则执行某个函数
  168. if (mutation.target.nodeName === 'TABLE') {
  169. return true;
  170. }
  171. }
  172. });
  173.  
  174. // 配置 MutationObserver 监听 table 内容的变化
  175. const config = { childList: true, subtree: true };
  176. observer.observe(document.body, config);
  177.  
  178. }
  179.  
  180. //开始运行
  181. run();
  182.  
  183. })();