Greasy Fork is available in English.

cc_log_tool

曹操出行日志格式转换工具

  1. // ==UserScript==
  2. // @name cc_log_tool
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1.1
  5. // @description 曹操出行日志格式转换工具
  6. // @author GengFei
  7. // @match https://nelk.caocaokeji.cn/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=caocaokeji.cn
  9. // @require https://cdn.jsdelivr.net/npm/@textea/json-viewer@3
  10. // @grant none
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (function () {
  15. 'use strict';
  16.  
  17. let list = [];
  18.  
  19. setInterval(() => {
  20. const list_new = document.querySelectorAll('.kbnDocViewer__value');
  21.  
  22. if (list.length !== list_new.length) {
  23. list = list_new;
  24. const r = [];
  25. list.forEach((item, i) => {
  26. if (
  27. document.querySelectorAll('.kbnDocViewer__field .euiToolTipAnchor')[i]
  28. .innerText === 'message'
  29. ) {
  30. r.push(item);
  31. }
  32. });
  33.  
  34. r.forEach((item) => {
  35. const all = item.innerText;
  36.  
  37. if (
  38. all.indexOf('req: ') > -1 &&
  39. item.getAttribute('cc-log-json-result') !== '1'
  40. ) {
  41. item.setAttribute('cc-log-json-result', '1');
  42.  
  43. const [baseInfo, p1] = all
  44. .replace(/(\r\n|\n|\r)/gm, '')
  45. .split(', req: ');
  46. const [req, p2] = p1.split(', res: ');
  47. const [res, cost] = p2.split(', cost ');
  48.  
  49. const id = 'json_' + Date.now();
  50.  
  51. item.innerHTML =
  52. '<div style="display: flex;">' +
  53. '<div style="flex: 2; flex-shrink: 0; padding-right: 12px">' +
  54. all +
  55. '</div>' +
  56. '<div style="flex: 3; flex-shrink: 0;" id=' +
  57. id +
  58. '>' +
  59. '</div>';
  60. +'</div>';
  61.  
  62. try {
  63. // JsonViewer 配置文档,有需要的可以自行修改,https://viewer.textea.io/apis
  64. new JsonViewer({
  65. value: {
  66. baseInfo,
  67. cost,
  68. req: JSON.parse(req),
  69. res: JSON.parse(res),
  70. },
  71. displayDataTypes: false,
  72. enableClipboard: true,
  73. objectSortKeys: true,
  74. maxDisplayLength: 300,
  75. collapseStringsAfterLength: 500,
  76. }).render('#' + id);
  77. } catch (error) {}
  78. }
  79. });
  80. }
  81. }, 100);
  82. })();