JSON Viewer

格式化显示JSON使数据看起来更加漂亮,支持折叠/展开格式化后的数据,支持JSON脑图让调用层级看着更清晰,支持复制JSON脑图节点路径

当前为 2024-10-13 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name JSON Viewer
  3. // @namespace http://tampermonkey.net/
  4. // @version v0.6.5
  5. // @author Feny
  6. // @description 格式化显示JSON使数据看起来更加漂亮,支持折叠/展开格式化后的数据,支持JSON脑图让调用层级看着更清晰,支持复制JSON脑图节点路径
  7. // @icon data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAeAB4AAD/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAEAAAAAAAD/2wBDAAIBAQIBAQICAgICAgICAwUDAwMDAwYEBAMFBwYHBwcGBwcICQsJCAgKCAcHCg0KCgsMDAwMBwkODw0MDgsMDAz/2wBDAQICAgMDAwYDAwYMCAcIDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAz/wAARCAAgACADASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD9wvjF8bLX4ZrHZx+XNqlwnmKjH5YUyRvb6kEAd8H058d1b47XV5Ir3eoN++bagaXYrN6KOBn2FfPPx5/aEutX8a+KNWhIubhruZLSNj8u1WMcIOP4QoXOOwNS/wDBM79lDTfjh8YNe+IXj63TxRdeHfKjsE1KMTxtdSbmMmxvlAiVV2IBsUybgAyKR9ZTy6lhsM69Xovm2+iPmKmOqYjEKjT6v5WXU9e8beKrjxZpp/s/xFrfhjWIwWs9X0q42z2kmPlZo2zDcxjqYZ0eNv7obDDf/YL/AG8L745eJNc+G3xCttP0n4qeEWZZ2sVZNP8AENsu0rd2ysS0ZKPG7RMSQsisCcukWd+3x4RtfhpqGk+JNPjS0g1mV7a8iT5UM4XesgHYsofdjglQepJPxwPE1x4V/au8LePtNkeK40ma0lmdDgyorvHMhPo9uxjP+y1bUcHRxmGbS1adn1TXT0/4fcipiqmExCi3pfVdGn19f+GLni/w7ceGf2wPFXga+Vo5rW/vDbI3WWI/v4HA/wBqBg3tk+lfWX7AXia1+F/iDV9B1CRbWHXjFLayyHannpuUxk+rqy4zxlMdWAPQft7fsL33x91nQfiD4DutP0r4oeDXVrT7cWWx1y3UsTZ3LKCyAh5FEigkLLIpHzBk5vwj4JuvE2kLJfeHdY8N6lGAl5pepwBZrOT+JRIuYp0ByBNCzxPg4bIICqYyljMKot62Sa6prr6P/gBDC1MLiHJLS90+jT6ev/Dnmn/BVP8Aaw0nxv4/8P8Aw18KXK69qmk3MlxqEdiRMwuivlpbrtPLopkMnZNy5IIYLyPwa/Z8vvEmv+HtHu4/Ovr+5iS6KDcqAtukwe6om7nuEJxX0XoH7PK/bJG0vRoY5rr/AFslvbLGZf8AfcAf+PGvafgv8CbX4byNqFyI5tWmXYCoytsh6qvqx7t+A4yWiWYUsLhlRpbr72318kVHA1MTiHVqbP7kl0P/2Q==
  8. // @match *://*/*
  9. // @require https://unpkg.com/dom-to-image@2.6.0/dist/dom-to-image.min.js
  10. // @require https://unpkg.com/jquery@3.7.1/dist/jquery.min.js
  11. // @require data:application/javascript,%3Bwindow.jQuery%3DjQuery%3B%3Bwindow.jquery%3DjQuery%3B
  12. // @require https://unpkg.com/jsmind@0.8.5/es6/jsmind.js
  13. // @require data:application/javascript,%3Bwindow.jsMind%3DjsMind%3Bwindow.jsmind%3DjsMind%3B
  14. // @require https://unpkg.com/jsmind@0.8.5/es6/jsmind.screenshot.js
  15. // @require https://unpkg.com/systemjs@6.15.1/dist/system.min.js
  16. // @require https://unpkg.com/systemjs@6.15.1/dist/extras/named-register.min.js
  17. // @require data:application/javascript,%3B(typeof%20System!%3D'undefined')%26%26(System%3Dnew%20System.constructor())%3B
  18. // @resource jsmind https://unpkg.com/jsmind@0.8.5/style/jsmind.css
  19. // @grant GM_addStyle
  20. // @grant GM_getResourceText
  21. // @grant GM_getValue
  22. // @grant GM_setClipboard
  23. // @grant GM_setValue
  24. // @grant unsafeWindow
  25. // @note v0.6.3 修复暗黑主题,tab颜色问题
  26. // @note v0.6.2 脑图增加JSON Crack
  27. // @note v0.6.1 增加多一种浅色主题
  28. // @note v0.6.0 增加简单HTTP 请求功能,可请求GET/POST/PUT/DELETE的API接口,而不单单只能GET请求使用
  29. // @note v0.5.9 jsonp格式小优化
  30. // @note v0.5.8 增加JSON手动输入
  31. // @note v0.5.7 一些小细节优化
  32. // @note v0.5.6 修复BUG
  33. // @note v0.5.5 解决@require jquery-simple-tree-table.min.js依赖加载失败问题
  34. // @note v0.5.4 单击复制修改为CTRL+单击复制JSONPath功能,JSON格式化风格增加table格式
  35. // @note v0.5.3 增加暗黑主题色
  36. // @note v0.5.2 单击JSON格式化的key可复制JSONPath
  37. // @note v0.5.1 修复JSONPath提示有误
  38. // @note v0.5.0 解决chrome 120+以上内核JSON格式化不执行和引入layer报错问题
  39. // @note v0.4.9 布局修改,增加保存JSON/脑图为文件,增加JSON过滤,鼠标移入key提示JSONPath
  40. // @note v0.4.8 代码优化
  41. // @note v0.4.7 增加对JSONP的判断,代码优化
  42. // @note v0.4.6 增加复制按钮,JSON脑图CSS样式细节优化,JSON脑图增加收起/展开子节点按钮
  43. // @note v0.4.5 在json-viewer-updated原基础上进行了一些修改,主要有CSS样式修改,新增折叠/展开全部功能,新增JSON脑图功能,脑图节点点击显示调用路径
  44. // ==/UserScript==
  45.  
  46. (e=>{if(!["application/vnd.api+json","application/javascript","application/json","text/javascript","text/plain","text/json"].includes(document.contentType))return;if(typeof GM_addStyle=="function"){GM_addStyle(e);return}const o=document.createElement("style");o.textContent=e,document.head.append(o)})(' @charset "UTF-8";body,html{margin:0;padding:0;font-size:14px}body td,html td{font-size:14px}body li::marker,html li::marker{content:""}body input:focus,body select:focus,body textarea:focus,html input:focus,html select:focus,html textarea:focus{outline:0}.hidden{display:none!important}.scroll-top{width:48px;height:48px;z-index:999;position:fixed;right:30px;bottom:30px;display:none;background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAAAXNSR0IArs4c6QAAA39JREFUaEPtmV2ITVEUx39rJjT5KPKC5DPKK6UGZZ7Eq0whNUiKFPfcKW9mnmjm7ssLaSLygEx5xItMESnKC4V8FV4IJUkyS+fMHZ07zjl3733PvT6a+3S6Z629/r+99sfa+wgpPw1YDtxLe9/k/1eI4X5STMkSokXWNlloYjgpMZSmIxPgbxBfS8M4QK0eavT78Qw0uodrtd+wDGjAMqBcEVAQw6NaYnzeNwRAi2xBOQlMrYj6jLJTygz6iMzyyR1Ai+xCGUgMqnTmDZErgBYoIJjMXhY2S4mLeWUiNwAt0INwyEqY0iNleq1saxjlAqAB64BrToKEHVLijJNPgnHdALqPaUziOsoKRzGfaKFD+nng6FdlXj+Ay9AZq1Q5L2W2/jEA3c8sWqOSe3aCiK/A3cr/K4G2FKEbxXDZF6KuDKROXKWXFvqlxJdQmBaZzDDdKZP8thhW/RmAgKfA4qrgSq+U6UkSlAostEuJOz4Q3hnQgPXAld+CCh1pB5DogKTcSBAalhpHmw1wGtgxJuhbMczJEqIBbxLmzFUxbGg2gCYE9AVADF6jwctJDzKd73xI7DG/IQQTmCFH+OiaBT+AAyykhWcpBZv7JA4bGmaRHOV5cwBqX7mc5Qe9coyX0TK6n/m0RnVSV4bA1KuTLCi/DBTYhHCpRm+Fe8Bo/b8JmJxp71lqOwNowB7guGuqLe33iuGEpW1k5gTgVDK7qIjbZmyESU1aA1TOuA99dTn5CQulxAsbH3uAeqpOGyXVNrvEcMrGzR4gIGnjsonhYzMkhg4bx3EAm17ysGlIBh4DSzzE+LgMiGG3jaPLEApv2Q7YNFq3jcOmZg9gt/u6aH8PzEx0aGWu9PHapjFrgKimCaIDTHiQqf4pNxHW2AT8ZaMEiZdgSreUKdm25QRQgRi7nIZzI7xZcPmeNkAL5xjmVpVQx1049HUGiCAKFBH6K8GjFUP3MIW2CGJpjd4bFEPnmM54grA761tYWpteAJXgy1A6w6p09Opcu1nED7ZlAcQP/BqwGZjORAblMO9sh03czhsgLZgW6EL4JoYL0b0RTArPBfFnH6G5ZyAVYKTkGBlWQVR2bxDDgvjzvwQQXqGsDQ/sGkTXKdHzOECsB3LtjdjKMjqE/qMMjJwn5olh+98+hM6gvAqXy0aN+4Yuo/HG/weAPmC1GNrzHDbxtn4Coc0pQNdM3UAAAAAASUVORK5CYII=)}.layui-layer-tips{width:auto!important}.flex-container{z-index:10;position:fixed;width:100vw;height:100vh;display:flex;flex-direction:column}.flex-container .tabs,.flex-container .toolbar{display:flex;line-height:28px;background-color:#ececec;border-bottom:1px solid #ccc}.flex-container .toolbar{line-height:23px}.flex-container .toolbar .searchbox{display:flex;flex-grow:1}.flex-container .toolbar .searchbox input{flex-grow:1;border:none;outline:none;font-size:12px;padding-left:23px;background-size:12px;background-repeat:no-repeat;background-position:7px center;background-image:url(data:image/svg+xml;base64,PCEtLSBUaGlzIFNvdXJjZSBDb2RlIEZvcm0gaXMgc3ViamVjdCB0byB0aGUgdGVybXMgb2YgdGhlIE1vemlsbGEgUHVibGljCiAgIC0gTGljZW5zZSwgdi4gMi4wLiBJZiBhIGNvcHkgb2YgdGhlIE1QTCB3YXMgbm90IGRpc3RyaWJ1dGVkIHdpdGggdGhpcwogICAtIGZpbGUsIFlvdSBjYW4gb2J0YWluIG9uZSBhdCBodHRwOi8vbW96aWxsYS5vcmcvTVBMLzIuMC8uIC0tPgo8c3ZnIGZpbGw9InJnYmEoMTM1LCAxMzUsIDEzNywgMC45KSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB2aWV3Qm94PSIwIDAgMTIgMTIiPgogIDxwYXRoIGZpbGw9ImNvbnRleHQtZmlsbCIgb3BhY2l0eT0iLjQiIGQ9Ik01IDkuMmwyIDEuNlY2LjFMOC41NSA0aC01LjFMNSA2LjF2My4xeiIvPgogIDxwYXRoIGZpbGw9ImNvbnRleHQtZmlsbCIgZD0iTTEuMTggMi42QTEgMSAwIDAgMSAyIDFIMTBhMSAxIDAgMCAxIC44IDEuNkw4IDYuNHY0LjgyYzAgLjYzLS43Mi45OC0xLjIyLjZsLTIuNS0xLjk5QS43NS43NSAwIDAgMSA0IDkuMjVWNi40MUwxLjE4IDIuNnpNMiAyTDUgNi4wOXYzLjA0bDIgMS41OVY2LjA5TDEwLjAxIDJIMnoiLz4KPC9zdmc+Cg==)}.flex-container .toolbar .searchbox .clear{flex:0 0 auto;align-self:center;margin:0 4px;padding:0;border:0;width:16px;height:16px;background-color:transparent;background-image:url(data:image/svg+xml;base64,PCEtLSBUaGlzIFNvdXJjZSBDb2RlIEZvcm0gaXMgc3ViamVjdCB0byB0aGUgdGVybXMgb2YgdGhlIE1vemlsbGEgUHVibGljCiAgIC0gTGljZW5zZSwgdi4gMi4wLiBJZiBhIGNvcHkgb2YgdGhlIE1QTCB3YXMgbm90IGRpc3RyaWJ1dGVkIHdpdGggdGhpcwogICAtIGZpbGUsIFlvdSBjYW4gb2J0YWluIG9uZSBhdCBodHRwOi8vbW96aWxsYS5vcmcvTVBMLzIuMC8uIC0tPgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjE2IiBoZWlnaHQ9IjE2IiB2aWV3Qm94PSIwIDAgMTYgMTYiIGZpbGw9ImNvbnRleHQtZmlsbCIgZmlsbC1vcGFjaXR5PSJjb250ZXh0LWZpbGwtb3BhY2l0eSI+CiAgPHBhdGggZD0iTTYuNTg2IDhsLTIuMjkzIDIuMjkzYTEgMSAwIDAgMCAxLjQxNCAxLjQxNEw4IDkuNDE0bDIuMjkzIDIuMjkzYTEgMSAwIDAgMCAxLjQxNC0xLjQxNEw5LjQxNCA4bDIuMjkzLTIuMjkzYTEgMSAwIDEgMC0xLjQxNC0xLjQxNEw4IDYuNTg2IDUuNzA3IDQuMjkzYTEgMSAwIDAgMC0xLjQxNCAxLjQxNEw2LjU4NiA4ek04IDBhOCA4IDAgMSAxIDAgMTZBOCA4IDAgMCAxIDggMHoiLz4KPC9zdmc+Cg==)}.flex-container .tabs-item{border-width:3px;border-top:3px solid #ececec}.flex-container .tabs-item.active{color:#0060df;border-top-color:#0060df;background-color:#e9e9e9}.flex-container .tabs-item:hover{border-top-color:#c3c3c6}.flex-container .tabs-item,.flex-container .toolbar-item{cursor:pointer;padding:0 10px;font-size:12px}.flex-container .tabs-item:hover,.flex-container .toolbar-item:hover{background-color:#d4d4d4}.flex-container .tabs .selectbox{position:absolute;right:200px;display:flex;font-size:13px}.flex-container .inputJson,.flex-container .fetchApi{cursor:pointer;color:#0060df;margin-left:15px}.flex-container .tabs-container{flex-grow:1;overflow:auto;line-height:1.4;font-family:monospace}.flex-container .tabs-container>div{display:none}.flex-container .tabs-container>div.active{display:block}.flex-container .tabs-container #formatContainer{padding:10px}.flex-container .tabs-container #rawTextContainer{padding:0 10px}.flex-container .tabs-container #rawTextContainer pre{display:block!important;overflow-wrap:break-word;white-space:pre-wrap}.flex-container .jsonp{color:#93983a}.flex-container ul.json-object,.flex-container ul.json-array{margin:0 0 0 2px;list-style-type:none;border-left:1px dotted #5d6d7e;padding-left:24px}.flex-container .json-brackets{font-weight:700}.flex-container .json-key{color:#910f93;cursor:pointer}.flex-container .json-string,.flex-container .json-string a{color:#4b8a4c}.flex-container .json-number{color:#1a01cc}.flex-container .json-boolean{color:#905}.flex-container .json-null{color:#0031bc}.flex-container a.json-toggle{position:rElative;color:inherit;opacity:.2;text-decoration:none}.flex-container a.json-toggle:hover{opacity:.35}.flex-container a.json-toggle:active{opacity:.5}.flex-container a.json-toggle:focus{outline:none}.flex-container a.json-toggle:before{top:2.5px;left:-15px;position:absolute;content:"";display:block;width:0;height:0;border-style:solid;border-width:5px 0 5px 8px;border-color:transparent transparent transparent currentColor;transform:rotate(90deg)}.flex-container a.json-toggle.collapsed:before{transform:rotate(0)}.flex-container a.json-placeholder{color:#ccc;font-size:12px;padding:0 1em;text-decoration:none}.flex-container a.json-placeholder:hover{text-decoration:underline}.flex-container .json-curly-brackets{color:#6d9331}.flex-container .json-square-brackets{color:#8e9331}.flex-container #jmContainer{width:100vw;height:calc(100vh - 57px)}.flex-container #jmContainer jmnode{display:flex;align-items:center;padding:0 7px 0 22px;color:#475872!important;box-shadow:none!important;background-color:transparent!important}.flex-container #jmContainer jmnode.root{padding:0;color:transparent!important}.flex-container #jmContainer jmnode:before{top:50%!important;content:"";position:absolute;border-radius:50%;transform:translateY(-50%)}.flex-container #jmContainer jmnode.root:before{left:50%;width:18px;height:18px;transform:translate(-18px,-50%)}.flex-container #jmContainer jmnode:hover{text-shadow:0px 0px 1px currentColor}.flex-container #jmContainer jmnode:not(.root):before{left:0;width:15px;height:15px}.flex-container #jmContainer jmexpander{margin-top:1px;line-height:9px;background-color:#dfdfdf}.flex-container #jmContainer .mind-array{opacity:.6;font-size:12px;padding-left:5px}.flex-container table{width:-webkit-fill-available;margin-left:20px;border-collapse:collapse}.flex-container table tr:hover{background-color:#f0f9fe}.flex-container table tr.selected td,.flex-container table tr.selected td a{color:#fff!important;background-color:#3875d7}.flex-container table tr td:first-child{width:120px}.flex-container table .tree-len{color:#ccc;font-size:13px}.flex-container table .simple-tree-table-icon{color:#000;opacity:.2;width:0!important;margin:0!important;line-height:0!important}.flex-container table .simple-tree-table-icon:before{top:.5px;left:-15px;position:relative;content:"";width:0;height:0;display:none;border-style:solid;border-width:5px 0 5px 8px;border-color:transparent transparent transparent currentColor;transform:rotate(90deg)}.flex-container table .simple-tree-table-icon::hover{opacity:.35}.flex-container table .simple-tree-table-icon:after{content:""!important}.flex-container table .simple-tree-table-icon::active{opacity:.5}.flex-container table .simple-tree-table-opened .simple-tree-table-icon:before{display:block}.flex-container table .simple-tree-table-closed .simple-tree-table-icon:before{display:block;transform:rotate(0)}.httpRequest{padding:20px}.httpRequest input,.httpRequest select{border-radius:0;padding-left:10px;border:1px solid #ccc}.requestbox,.textarea{width:700px;display:flex}.requestbox{height:35px;margin-bottom:15px}.requestbox input{flex-grow:1}.requestbox button{cursor:pointer;padding:0 15px;border:1px solid #ccc}.requestbox button:active{background-color:#cfcfcf}.textarea input{flex-grow:1;height:30px}.light .json-key{color:#0451a5}.light .json-string,.light .json-string a{color:#a31515}.light .json-number{color:#0b7500}.light .json-boolean{color:#00f}.light .json-null{color:#05f}body.dark .tabs-container{background-color:#333}body.dark li,body.dark pre{color:#ccc}body.dark .jsonp{color:#f1d700}body.dark .json-toggle{opacity:.35}body.dark .json-toggle:hover{opacity:.5}body.dark .json-curly-brackets{color:#ce70d6}body.dark .json-square-brackets{color:#f1d700}body.dark .json-key{color:#9cdcfe}body.dark .json-string,body.dark .json-string a{color:#ce9178}body.dark .json-number{color:#b5cea8}body.dark .json-boolean{color:#358cd6}body.dark .json-null{color:#569cd6}body.dark jmnode{color:#7cdcfe!important}body.dark table tr:hover{background-color:#353b48}body.dark .simple-tree-table-icon{color:#fff;opacity:.5} ');
  47.  
  48. System.addImportMap({ imports: {"jquery":"user:jquery","jsmind":"user:jsmind","jsmind/screenshot":"user:jsmind/screenshot"} });
  49. System.set("user:jquery", (()=>{const _=jquery;('default' in _)||(_.default=_);return _})());
  50. System.set("user:jsmind", (()=>{const _=jsmind;('default' in _)||(_.default=_);return _})());
  51. System.set("user:jsmind/screenshot", (()=>{const _=jsmind;('default' in _)||(_.default=_);return _})());
  52.  
  53. System.register("./__entry.js", ['./__monkey.entry-DJjsLgK8.js'], (function (exports, module) {
  54. 'use strict';
  55. return {
  56. setters: [null],
  57. execute: (function () {
  58.  
  59.  
  60.  
  61. })
  62. };
  63. }));
  64.  
  65. System.register("./__monkey.entry-DJjsLgK8.js", ['jquery'], (function (exports, module) {
  66. 'use strict';
  67. var $;
  68. return {
  69. setters: [module => {
  70. $ = module.default;
  71. }],
  72. execute: (function () {
  73.  
  74. const scriptRel = function detectScriptRel() {
  75. const relList = typeof document !== "undefined" && document.createElement("link").relList;
  76. return relList && relList.supports && relList.supports("modulepreload") ? "modulepreload" : "preload";
  77. }();
  78. const assetsURL = function(dep) {
  79. return "/" + dep;
  80. };
  81. const seen = {};
  82. const __vitePreload = function preload(baseModule, deps, importerUrl) {
  83. let promise = Promise.resolve();
  84. if (deps && deps.length > 0) {
  85. document.getElementsByTagName("link");
  86. const cspNonceMeta = document.querySelector(
  87. "meta[property=csp-nonce]"
  88. );
  89. const cspNonce = (cspNonceMeta == null ? void 0 : cspNonceMeta.nonce) || (cspNonceMeta == null ? void 0 : cspNonceMeta.getAttribute("nonce"));
  90. promise = Promise.allSettled(
  91. deps.map((dep) => {
  92. dep = assetsURL(dep);
  93. if (dep in seen) return;
  94. seen[dep] = true;
  95. const isCss = dep.endsWith(".css");
  96. const cssSelector = isCss ? '[rel="stylesheet"]' : "";
  97. if (document.querySelector(`link[href="${dep}"]${cssSelector}`)) {
  98. return;
  99. }
  100. const link = document.createElement("link");
  101. link.rel = isCss ? "stylesheet" : scriptRel;
  102. if (!isCss) {
  103. link.as = "script";
  104. }
  105. link.crossOrigin = "";
  106. link.href = dep;
  107. if (cspNonce) {
  108. link.setAttribute("nonce", cspNonce);
  109. }
  110. document.head.appendChild(link);
  111. if (isCss) {
  112. return new Promise((res, rej) => {
  113. link.addEventListener("load", res);
  114. link.addEventListener(
  115. "error",
  116. () => rej(new Error(`Unable to preload CSS for ${dep}`))
  117. );
  118. });
  119. }
  120. })
  121. );
  122. }
  123. function handlePreloadError(err) {
  124. const e = new Event("vite:preloadError", {
  125. cancelable: true
  126. });
  127. e.payload = err;
  128. window.dispatchEvent(e);
  129. if (!e.defaultPrevented) {
  130. throw err;
  131. }
  132. }
  133. return promise.then((res) => {
  134. for (const item of res || []) {
  135. if (item.status !== "rejected") continue;
  136. handlePreloadError(item.reason);
  137. }
  138. return baseModule().catch(handlePreloadError);
  139. });
  140. };
  141. const Utils = exports("U", {
  142. // 检查字符串是否为URL
  143. isUrl: function(string) {
  144. const regexp = /^(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
  145. return regexp.test(string);
  146. },
  147. // 检查是否是图片链接
  148. isImg: function(pathImg) {
  149. const regexp = /\.(ico|bmp|gif|jpg|jpeg|png|svg|webp|GIF|JPG|PNG|WEBP|SVG)([\w#!:.?+=&%@!\-\/])?/i;
  150. return regexp.test(pathImg);
  151. },
  152. // 检验内容是否是json格式的内容
  153. isJSON: function(str) {
  154. try {
  155. JSON.parse(str);
  156. return true;
  157. } catch (e) {
  158. console.log("is not json", e);
  159. return false;
  160. }
  161. },
  162. // 获取数据类型
  163. getType: function(value) {
  164. return Object.prototype.toString.call(value).match(/\s(.+)]/)[1].toLowerCase();
  165. },
  166. // 获取数组中对象key最多的对象
  167. findMaxKeysObject: function(arr) {
  168. let maxKeysCount = 0, maxKeysObject;
  169. for (const obj of arr) {
  170. const keysCount = Object.keys(obj).length;
  171. if (keysCount > maxKeysCount) {
  172. maxKeysCount = keysCount;
  173. maxKeysObject = obj;
  174. }
  175. }
  176. return maxKeysObject;
  177. },
  178. // 随机rgb颜色
  179. randomColor: (opacity) => {
  180. const red = Math.floor(Math.random() * 256);
  181. const green = Math.floor(Math.random() * 256);
  182. const blue = Math.floor(Math.random() * 256);
  183. return `rgba(${red}, ${green}, ${blue}, ${opacity})`;
  184. },
  185. /**
  186. * 是否满足JSON
  187. * @returns
  188. */
  189. isJSONDocument: function(contentType) {
  190. const docType = [
  191. "application/vnd.api+json",
  192. "application/javascript",
  193. "application/json",
  194. "text/javascript",
  195. "text/plain",
  196. "text/json"
  197. ];
  198. if (!docType.includes(contentType)) {
  199. return false;
  200. }
  201. return true;
  202. }
  203. });
  204. var _GM_addStyle = /* @__PURE__ */ (() => typeof GM_addStyle != "undefined" ? GM_addStyle : void 0)();
  205. var _GM_getValue = exports("c", /* @__PURE__ */ (() => typeof GM_getValue != "undefined" ? GM_getValue : void 0)());
  206. var _GM_setClipboard = exports("_", /* @__PURE__ */ (() => typeof GM_setClipboard != "undefined" ? GM_setClipboard : void 0)());
  207. var _GM_setValue = exports("b", /* @__PURE__ */ (() => typeof GM_setValue != "undefined" ? GM_setValue : void 0)());
  208. var _unsafeWindow = exports("a", /* @__PURE__ */ (() => typeof unsafeWindow != "undefined" ? unsafeWindow : void 0)());
  209. (function() {
  210. if (!Utils.isJSONDocument(document.contentType)) {
  211. return;
  212. }
  213. _unsafeWindow.GLOBAL_SOURCE_ELEMENT = $("pre").first();
  214. if (_unsafeWindow.GLOBAL_SOURCE_ELEMENT.length === 0) {
  215. const text = document.body.innerText;
  216. if (!Utils.isJSON(text)) {
  217. return;
  218. }
  219. const pre = document.createElement("pre");
  220. pre.innerText = text;
  221. document.body.insertAdjacentHTML("afterbegin", pre);
  222. _unsafeWindow.GLOBAL_SOURCE_ELEMENT = $(pre);
  223. }
  224. let rawText = _unsafeWindow.GLOBAL_SOURCE_ELEMENT.text();
  225. if (!rawText) {
  226. return;
  227. }
  228. let tokens = rawText.match(/^([^\s(]*)\s*\(([\s\S]*)\)\s*;?$/);
  229. if (tokens && tokens[1] && tokens[2]) {
  230. _unsafeWindow.GLOBAL_JSONP_FUN = tokens[1];
  231. rawText = tokens[2];
  232. }
  233. if (!Utils.isJSON(rawText)) {
  234. return;
  235. }
  236. _unsafeWindow.GLOBAL_SOURCE_ELEMENT.hide();
  237. try {
  238. _unsafeWindow.GLOBAL_JSON = eval(`(${rawText})`);
  239. } catch (e) {
  240. _unsafeWindow.GLOBAL_JSON = JSON.parse(rawText);
  241. }
  242. const LAYUI_JS = "//unpkg.com/layui@2.7.6/dist/layui.js";
  243. const LAYUI_CSS = "//unpkg.com/layui@2.7.6/dist/css/layui.css";
  244. $("head").append(`<link href="${LAYUI_CSS}" rel="stylesheet">`).append(`<script src="${LAYUI_JS}">`);
  245. _GM_addStyle(`
  246. jmnode.root::before{
  247. background-color: ${Utils.randomColor(0.5)}
  248. }
  249.  
  250. jmnode:not(.root)::before{
  251. background-color: ${Utils.randomColor(0.5)}
  252. }
  253. `);
  254. __vitePreload(() => module.import('./layout-DTea31Wm-BaKXQvNI.js'), void 0 );
  255. __vitePreload(() => module.import('./formatStyle-G8UeWY1h-C6u4ZziO.js'), void 0 ).then((formatStyle) => {
  256. formatStyle.default.init();
  257. });
  258. })();
  259.  
  260. })
  261. };
  262. }));
  263.  
  264. System.register("./layout-DTea31Wm-BaKXQvNI.js", ['jquery'], (function (exports, module) {
  265. 'use strict';
  266. var $;
  267. return {
  268. setters: [module => {
  269. $ = module.default;
  270. }],
  271. execute: (function () {
  272.  
  273. const UI = `
  274. <div class="scroll-top"></div>
  275. <div class="flex-container">
  276. <div class="panel">
  277. <div class="tabs">
  278. <div class="tabs-item btn active" id="format">JSON格式化</div>
  279. <div class="tabs-item btn" id="viewJsonMind">JSON脑图</div>
  280. <div class="tabs-item btn" id="viewRawText">原始数据</div>
  281. <div class="selectbox">
  282. <div class="formatStyle">
  283. <label>风格:</label>
  284. <select>
  285. <option value="default">默认</option>
  286. <option value="treaTable">表格</option>
  287. </select>
  288. </div>
  289. <div class="theme" style="margin: 0 15px">
  290. <label>主题: </label>
  291. <select>
  292. <option value="default">默认</option>
  293. <option value="light">浅色</option>
  294. <option value="dark">暗黑</option>
  295. </select>
  296. </div>
  297. <span class="inputJson">JSON 输入</span>
  298. <span class="fetchApi">HTTP 请求</span>
  299. </div>
  300. </div>
  301. <div class="toolbar">
  302. <div class="toolbar-item btn" id="saveJson">保存</div>
  303. <div class="toolbar-item btn" id="copyJson">复制</div>
  304. <div class="toolbar-item btn" id="collapseAll">全部折叠</div>
  305. <div class="toolbar-item btn" id="expandAll">全部展开</div>
  306. <div class="toolbar-item btn" id="jsoncrack" style="display: none;">JSON Crack</div>
  307. <div class="toolbar-item btn" id="beautify" style="display: none;">美化输出</div>
  308. <div class="searchbox">
  309. <input type="text" placeholder="过滤 JSON "/>
  310. <button class="clear" hidden></button>
  311. </div>
  312. </div>
  313. </div>
  314. <div class="tabs-container">
  315. <div class="active" id="formatContainer"></div>
  316. <div id="jmContainer"></div>
  317. <div id="rawTextContainer"><pre></pre></div>
  318. </div>
  319. </div>`;
  320. $("body").append(UI);
  321.  
  322. })
  323. };
  324. }));
  325.  
  326. System.register("./formatStyle-G8UeWY1h-C6u4ZziO.js", ['jquery', './__monkey.entry-DJjsLgK8.js', 'jsmind', 'jsmind/screenshot'], (function (exports, module) {
  327. 'use strict';
  328. var $, _GM_setClipboard, _unsafeWindow, _GM_setValue, _GM_getValue, Utils, jsMind;
  329. return {
  330. setters: [module => {
  331. $ = module.default;
  332. }, module => {
  333. _GM_setClipboard = module._;
  334. _unsafeWindow = module.a;
  335. _GM_setValue = module.b;
  336. _GM_getValue = module.c;
  337. Utils = module.U;
  338. }, module => {
  339. jsMind = module.default;
  340. }, null],
  341. execute: (function () {
  342.  
  343. (function($2) {
  344. function isCollapsable(arg) {
  345. return arg instanceof Object && Object.keys(arg).length > 0;
  346. }
  347. function json2html(json2, parentPath = "") {
  348. let html = "", type = Utils.getType(json2);
  349. switch (type) {
  350. case "array":
  351. case "object":
  352. let len = json2.length || Object.keys(json2).length;
  353. if (len > 0) {
  354. html += `<span class="json-brackets ${type == "array" ? "json-square-brackets" : "json-curly-brackets"}">`;
  355. html += type === "array" ? '[</span><ol class="json-array">' : '{</span><ul class="json-object">';
  356. for (var key in json2) {
  357. if (json2.hasOwnProperty(key)) {
  358. let comma = --len > 0 ? "," : "", jsonPath = parentPath + "." + key, collapse = isCollapsable(json2[key]) ? '<a href class="json-toggle"></a>' : "", res = json2html(json2[key], jsonPath);
  359. let toHtml = type === "array" ? res : `<span class="json-key">"${key}"</span>: ${res}`;
  360. html += [
  361. `<li json-path="${jsonPath}">`,
  362. collapse,
  363. toHtml,
  364. comma,
  365. "</li>"
  366. ].join("");
  367. }
  368. }
  369. if (type === "array") {
  370. html += `</ol><span class="json-brackets json-square-brackets">]</span>`;
  371. } else {
  372. html += `</ul><span class="json-brackets json-curly-brackets">}</span>`;
  373. }
  374. } else {
  375. html += `<span class="json-brackets ${type == "array" ? "json-square-brackets" : "json-curly-brackets"}">`;
  376. html += type === "array" ? "[]" : "{}";
  377. html += "</span>";
  378. }
  379. break;
  380. default:
  381. json2 = type === "string" ? json2.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;") : json2;
  382. if (Utils.isUrl(json2)) {
  383. html += `<a target="_blank" href="${json2}" class="json-string">"${json2}"</a>`;
  384. } else {
  385. json2 = type === "string" ? `"${json2}"` : json2;
  386. html += `<span class="json-${type}">${json2}</span>`;
  387. }
  388. break;
  389. }
  390. return html;
  391. }
  392. $2.fn.jsonViewer = function(json2, jsonpFn) {
  393. return this.each(function() {
  394. var html = json2html(json2);
  395. if (jsonpFn !== void 0 && jsonpFn !== null) {
  396. html = `<div class="jsonp">${jsonpFn}(</div>${html}<div class="jsonp">)</div>`;
  397. }
  398. $2(this).html(html);
  399. $2(this).off("click");
  400. $2(this).on("click", "a.json-toggle", function() {
  401. var target = $2(this).toggleClass("collapsed").siblings("ul.json-object, ol.json-array");
  402. target.toggle();
  403. if (target.is(":visible")) {
  404. target.siblings(".json-placeholder").remove();
  405. } else {
  406. var count = target.children('li:not([class*="hidden"])').length;
  407. var placeholder = count + (count > 1 ? " items" : " item");
  408. target.after(
  409. '<a href class="json-placeholder">' + placeholder + "</a>"
  410. );
  411. }
  412. return false;
  413. });
  414. $2(this).on("click", "a.json-placeholder", function() {
  415. $2(this).siblings("a.json-toggle").click();
  416. $2(this).siblings("a.json-placeholder").remove();
  417. return false;
  418. });
  419. });
  420. };
  421. })($);
  422. const theme = {
  423. // 切换主题
  424. changeTheme: function() {
  425. const that2 = this;
  426. $(".theme select").change(function(e) {
  427. const val = $(e.target).val();
  428. _GM_setValue("theme", val);
  429. that2.setTheme();
  430. });
  431. return this;
  432. },
  433. // 设置主题
  434. setTheme: function() {
  435. const theme2 = _GM_getValue("theme") || "default";
  436. $("body").removeClass().addClass(theme2);
  437. $(".theme select").val(theme2);
  438. return this;
  439. },
  440. init: function() {
  441. this.setTheme().changeTheme();
  442. }
  443. };
  444. const cssLoader = (e) => {
  445. const t = GM_getResourceText(e);
  446. return GM_addStyle(t), t;
  447. };
  448. cssLoader("jsmind");
  449. const jsonMind = {
  450. isFirst: true,
  451. // JSON数据转换为jsMind所需要的数据结构
  452. convert: function(json2) {
  453. const children = [];
  454. if (typeof json2 === "object") {
  455. for (const key in json2) {
  456. let val = json2[key], isArray = Array.isArray(val);
  457. if (isArray && val.length > 0) {
  458. val = Utils.findMaxKeysObject(val);
  459. }
  460. const type = Object.prototype.toString.call(val).match(/\s(.+)]/)[1];
  461. children.push({
  462. isArray,
  463. chain: key,
  464. id: key + "_" + Math.random(),
  465. topic: `${key}<span class="mind-array">${type}</span>`,
  466. children: this.convert(val)
  467. });
  468. }
  469. }
  470. return children;
  471. },
  472. // 脑图节点调用链
  473. mindChain: function(node) {
  474. let chain = node.data.chain;
  475. if (!node.parent) {
  476. return chain;
  477. }
  478. const parent = node.parent, parentChain = this.mindChain(parent);
  479. chain = parent.data.isArray ? `${parentChain}[0].${chain}` : `${parentChain}.${chain}`;
  480. return chain;
  481. },
  482. // 显示脑图
  483. show: function(json2) {
  484. let isArr = Array.isArray(json2);
  485. if (isArr) {
  486. if (typeof json2[0] !== "object") {
  487. layer.msg("数据结构无法生成脑图", { time: 1e3 });
  488. return this;
  489. }
  490. json2 = Utils.findMaxKeysObject(json2);
  491. }
  492. if (!this.isFirst) {
  493. return this;
  494. }
  495. jm.show({
  496. meta: {
  497. name: "JSON脑图",
  498. author: "1220301855@qq.com",
  499. version: "1.0"
  500. },
  501. format: "node_tree",
  502. /* 数据内容 */
  503. data: {
  504. id: "root",
  505. topic: "Response",
  506. direction: "left",
  507. children: this.convert(json2),
  508. chain: isArr ? "Response[0]" : "Response"
  509. }
  510. });
  511. this.isFirst = false;
  512. return this;
  513. },
  514. // 脑图节点事件
  515. event: function() {
  516. $("jmnode").on("dblclick mouseover mouseout", function(event) {
  517. const that2 = $(this), node = jm.get_node(that2.attr("nodeid"));
  518. if (!node.parent) {
  519. return;
  520. }
  521. switch (event.type) {
  522. case "dblclick":
  523. _GM_setClipboard(jsonMind.mindChain(node));
  524. layer.msg("节点路径复制成功", { time: 1500 });
  525. break;
  526. case "mouseover":
  527. const s = `<b>节点路径(双击复制)</b><br/>${jsonMind.mindChain(node)}`;
  528. layer.tips(s, that2, {
  529. time: 0,
  530. tips: [2, "#2e59a7"]
  531. });
  532. break;
  533. default:
  534. layer.closeAll();
  535. break;
  536. }
  537. });
  538. return this;
  539. },
  540. init: function(json2) {
  541. if (!window.jm) {
  542. window.jm = new jsMind({
  543. mode: "side",
  544. editable: false,
  545. container: "jmContainer",
  546. view: {
  547. hmargin: 50,
  548. // 思维导图距容器外框的最小水平距离
  549. vmargin: 50,
  550. // 思维导图距容器外框的最小垂直距离
  551. engine: "svg",
  552. // 思维导图各节点之间线条的绘制引擎
  553. draggable: true,
  554. // 当容器不能完全容纳思维导图时,是否允许拖动画布代替鼠标滚动
  555. support_html: false,
  556. line_color: "#C4C9D0"
  557. },
  558. zoom: {
  559. // 配置缩放
  560. min: 0.1,
  561. // 最小的缩放比例
  562. max: 2.1,
  563. // 最大的缩放比例
  564. step: 0.1
  565. // 缩放比例间隔
  566. },
  567. layout: {
  568. vspace: 7,
  569. // 节点之间的垂直间距
  570. hspace: 150
  571. // 节点之间的水平空间
  572. }
  573. });
  574. }
  575. this.show(json2).event();
  576. }
  577. };
  578. const btnEvent = {
  579. firstFormat: true,
  580. isBeautify: false,
  581. $rawText: $("#rawTextContainer"),
  582. /**
  583. * 保存为文件
  584. */
  585. download: {
  586. download: function(content, filename) {
  587. const link = document.createElement("a");
  588. link.href = content;
  589. link.download = filename;
  590. link.click();
  591. },
  592. saveJSON: function(text2) {
  593. const blob = new Blob([text2], { type: "text/plain;charset=utf-8" });
  594. const url = URL.createObjectURL(blob);
  595. const filename = (/* @__PURE__ */ new Date()).getTime() + ".json";
  596. this.download(url, filename);
  597. URL.revokeObjectURL(url);
  598. },
  599. savePNG: () => jm.shoot()
  600. },
  601. saveJson: function() {
  602. if ($("#jmContainer").is(":visible")) {
  603. this.download.savePNG();
  604. } else {
  605. this.download.saveJSON(this.$rawText.text());
  606. }
  607. },
  608. // 复制JSON文本内容
  609. copyJson: function() {
  610. _GM_setClipboard(this.$rawText.text());
  611. layer.msg("复制成功", { time: 1500 });
  612. },
  613. // 全部折叠
  614. collapseAll: function() {
  615. if ($("#formatContainer").is(":visible")) {
  616. try {
  617. $("a.json-toggle").not(".collapsed").click();
  618. } catch (e) {
  619. }
  620. } else {
  621. jm.collapse_all();
  622. }
  623. },
  624. // 全部展开
  625. expandAll: function() {
  626. if ($("#formatContainer").is(":visible")) {
  627. try {
  628. $("a.json-placeholder").click().remove();
  629. } catch (e) {
  630. }
  631. } else {
  632. jm.expand_all();
  633. jm.scroll_node_to_center(jm.get_root());
  634. }
  635. },
  636. format: function() {
  637. },
  638. // 显示JSON脑图
  639. viewJsonMind: function() {
  640. jsonMind.init(_unsafeWindow.GLOBAL_JSON);
  641. jm.scroll_node_to_center(jm.get_root());
  642. },
  643. // 查看原始JSON内容
  644. viewRawText: function() {
  645. if (this.firstFormat) {
  646. this.$rawText.html(_unsafeWindow.GLOBAL_SOURCE_ELEMENT.clone());
  647. this.firstFormat = false;
  648. }
  649. },
  650. // 美化
  651. beautify: function() {
  652. this.isBeautify = !this.isBeautify;
  653. if (this.isBeautify) {
  654. let str = JSON.stringify(_unsafeWindow.GLOBAL_JSON, null, 2);
  655. if (_unsafeWindow.GLOBAL_JSONP_FUN !== void 0 && _unsafeWindow.GLOBAL_JSONP_FUN !== null) {
  656. str = `${_unsafeWindow.GLOBAL_JSONP_FUN}(${str})`;
  657. }
  658. this.$rawText.find("pre").text(str);
  659. } else {
  660. this.$rawText.html(_unsafeWindow.GLOBAL_SOURCE_ELEMENT.clone());
  661. }
  662. },
  663. jsoncrack: function() {
  664. layer.closeAll();
  665. const index = layer.open({
  666. type: 1,
  667. title: false,
  668. maxmin: true,
  669. shadeClose: true,
  670. area: ["900px", "600px"],
  671. content: '<iframe style="width: 100%;height: 100%;border: 0;" id="jsoncrackEmbed" src="https://jsoncrack.feny.ink/widget"></iframe>',
  672. success: function(layero) {
  673. const jsonCrackEmbed = layero.find("#jsoncrackEmbed")[0];
  674. window == null ? void 0 : window.addEventListener("message", () => {
  675. jsonCrackEmbed.contentWindow.postMessage(
  676. {
  677. json: JSON.stringify(_unsafeWindow.GLOBAL_JSON)
  678. },
  679. "*"
  680. );
  681. });
  682. }
  683. });
  684. layer.full(index);
  685. },
  686. init: function() {
  687. this.viewRawText();
  688. $(".btn").on("click", (e) => {
  689. const target = e.target, id = target.id;
  690. if (target.classList.contains("tabs-item")) {
  691. const index = $(target).index();
  692. $(target).addClass("active").siblings().removeClass("active");
  693. $(".tabs-container > div").removeClass("active").eq(index).addClass("active");
  694. const beautifyEl = $("#beautify"), searchEl = $(".searchbox"), copyJsonEl = $("#copyJson"), jsoncrackEl = $("#jsoncrack"), aEl = $("#collapseAll, #expandAll");
  695. id === "format" ? searchEl.show() : searchEl.hide();
  696. id === "viewJsonMind" ? copyJsonEl.hide() && jsoncrackEl.show() : copyJsonEl.show() && jsoncrackEl.hide();
  697. id === "viewRawText" ? beautifyEl.show() && aEl.hide() : beautifyEl.hide() && aEl.show();
  698. }
  699. this[id](target);
  700. });
  701. return this;
  702. }
  703. };
  704. const otherEvent = {
  705. // 过滤 JSON
  706. filterJSON: function(filter) {
  707. const style = _GM_getValue("formatStyle") || "default";
  708. if (!filter) {
  709. style == "default" ? $("#formatContainer li").removeClass("hidden") : $(".json-key").parent().removeClass("hidden");
  710. return;
  711. }
  712. const chainSet = /* @__PURE__ */ new Set();
  713. document.querySelectorAll("#formatContainer *[json-path]").forEach((el) => {
  714. let chain = $(el).attr("json-path");
  715. if (!chain) {
  716. return;
  717. }
  718. const newChain = chain.substr(chain.lastIndexOf("."));
  719. if (!newChain.toLowerCase().includes(filter.toLowerCase())) {
  720. return;
  721. }
  722. chainSet.add(chain);
  723. while (chain = chain.substr(0, chain.lastIndexOf("."))) {
  724. chainSet.add(chain);
  725. }
  726. });
  727. document.querySelectorAll(
  728. "#formatContainer *[class*='json-']:not([class*='json-key']):not([class*='json-brackets'])"
  729. ).forEach((el) => {
  730. const target = $(el);
  731. let chain = style == "default" ? target.parent().attr("json-path") : target.siblings(".json-key").attr("json-path");
  732. if (!chain) {
  733. return;
  734. }
  735. const text2 = target.text();
  736. if (!text2.toLowerCase().includes(filter.toLowerCase())) {
  737. return;
  738. }
  739. chainSet.add(chain);
  740. while (chain = chain.substring(0, chain.lastIndexOf("."))) {
  741. chainSet.add(chain);
  742. }
  743. });
  744. style == "default" ? $("#formatContainer li").addClass("hidden") : $(".json-key").parent().addClass("hidden");
  745. chainSet.forEach((chain) => {
  746. style == "default" ? $(`#formatContainer *[json-path="${chain}"]`).removeClass("hidden") : $(`#formatContainer *[json-path="${chain}"]`).parent().removeClass("hidden");
  747. });
  748. },
  749. // JSON 过滤
  750. input: function() {
  751. const that2 = this;
  752. $("input").on("input", function() {
  753. const val = $(this).val();
  754. val === "" ? $(".clear").attr("hidden", true) : $(".clear").attr("hidden", false);
  755. that2.filterJSON(val);
  756. });
  757. return that2;
  758. },
  759. // 清空输入框内容
  760. clear: function() {
  761. const that2 = this;
  762. $(".clear").click(function() {
  763. that2.filterJSON();
  764. $("input").val("");
  765. $(this).attr("hidden", true);
  766. });
  767. return this;
  768. },
  769. // 返回顶部
  770. scrollTop: function() {
  771. $(".scroll-top").click(function() {
  772. $(".tabs-container").animate(
  773. {
  774. scrollTop: "0"
  775. },
  776. 1e3
  777. );
  778. });
  779. $(".tabs-container").scroll(function(e) {
  780. const scrollTop = $(this).scrollTop();
  781. scrollTop > 500 ? $(".scroll-top").fadeIn() : $(".scroll-top").fadeOut();
  782. });
  783. return this;
  784. },
  785. // 所有a标签,看是否是图片,是图片生成预览图
  786. urlHover: function() {
  787. $("#formatContainer").on(
  788. {
  789. mouseenter: function() {
  790. var that2 = $(this), href = that2.attr("href");
  791. if (Utils.isImg(href)) {
  792. layer.tips(`<img src="${href}" />`, that2, {
  793. time: 0,
  794. anim: 5,
  795. maxWidth: 500,
  796. tips: [3, "#d9d9d9"]
  797. });
  798. }
  799. },
  800. mouseleave: () => layer.closeAll()
  801. },
  802. "a[href]"
  803. );
  804. return this;
  805. },
  806. // 提示key的JSONPath
  807. tipsJsonPath: function() {
  808. var that2 = this;
  809. $("#formatContainer").on(
  810. {
  811. mouseenter: function() {
  812. const jsonPath = that2.getJsonPath(this);
  813. const tips = `<b>ctrl + 点击复制</b><br/>${jsonPath}`;
  814. layer.tips(tips, this, {
  815. time: 0,
  816. anim: 5,
  817. maxWidth: 500,
  818. tips: [1, "#2e59a7"]
  819. });
  820. },
  821. mouseleave: () => layer.closeAll()
  822. },
  823. ".json-key"
  824. );
  825. return this;
  826. },
  827. // 单击key复制JSONPath
  828. copyJsonPath: function() {
  829. var that2 = this;
  830. $("#formatContainer").on("click", ".json-key", function(event) {
  831. if (event.ctrlKey) {
  832. const jsonPath = that2.getJsonPath(this);
  833. _GM_setClipboard(jsonPath);
  834. layer.msg("复制成功", { time: 1500 });
  835. }
  836. });
  837. return this;
  838. },
  839. getJsonPath: function(element) {
  840. const style = _GM_getValue("formatStyle") || "default";
  841. const jsonPath = style == "default" ? $(element).parent().attr("json-path") : $(element).attr("json-path");
  842. return jsonPath.split(".").reduce(
  843. (prev, next) => /^\d+$/.test(next) ? prev + `[${next}]` : prev + "." + next
  844. );
  845. },
  846. inputJson: function() {
  847. const that = this;
  848. $(".inputJson").off("click").click(function() {
  849. layer.prompt(
  850. {
  851. title: "JSON 输入",
  852. formType: 2,
  853. shadeClose: true,
  854. maxlength: 1e6
  855. },
  856. function(text) {
  857. if (!text) {
  858. layer.msg("内容不能为空", { time: 1500 });
  859. return;
  860. }
  861. const rawText = text, oldJSONPFun = _unsafeWindow.GLOBAL_JSONP_FUN;
  862. const match = text.match(/^([^\s(]*)\s*\(([\s\S]*)\)\s*;?$/);
  863. if (match && match[1] && match[2]) {
  864. _unsafeWindow.GLOBAL_JSONP_FUN = match[1];
  865. text = match[2];
  866. }
  867. try {
  868. const json = JSON.parse(JSON.stringify(eval(`(${text})`)));
  869. that.reload(json, rawText);
  870. } catch (e) {
  871. console.log(e);
  872. _unsafeWindow.GLOBAL_JSONP_FUN = oldJSONPFun;
  873. layer.msg("JSON不合法", { time: 1500 });
  874. }
  875. }
  876. );
  877. });
  878. return this;
  879. },
  880. fetchApi: function() {
  881. const that2 = this;
  882. $(".fetchApi").off("click").on("click", function() {
  883. layer.open({
  884. type: 1,
  885. closeBtn: 0,
  886. //不显示关闭按钮
  887. shadeClose: true,
  888. //开启遮罩关闭
  889. title: "HTTP 请求",
  890. content: `<form class="httpRequest">
  891. <div class="requestbox">
  892. <select name="method">
  893. <option value="POST">POST</option>
  894. <option value="GET">GET</option>
  895. <option value="PUT">PUT</option>
  896. <option value="DELETE">DELETE</option>
  897. </select>
  898. <input name="url" placeholder="请求地址" />
  899. <select name="contentType">
  900. <option value="application/x-www-form-urlencoded;charset=UTF-8">urlencoded</option>
  901. <option value="application/json;charset=UTF-8">application/json</option>
  902. </select>
  903. <button type="submit">发送</button>
  904. </div>
  905. <div class="textarea">
  906. <input name="headers" placeholder='请求头 {"token": "test"}' />
  907. <input name="params" placeholder='请求参数 {"id": "test", ""name": "test"}' />
  908. </div>
  909. </form>`
  910. });
  911. $("form").submit(function(event) {
  912. event.preventDefault();
  913. const serialize = $(this).serializeArray();
  914. const form = {};
  915. for (const key in serialize) {
  916. const it = serialize[key];
  917. form[it.name] = it.value;
  918. }
  919. if (form.url === "") {
  920. layer.msg("请求URL不能为空");
  921. return;
  922. }
  923. let headers = form.headers;
  924. let params = form.params;
  925. try {
  926. if (headers) {
  927. headers = JSON.parse(headers);
  928. }
  929. } catch (e) {
  930. layer.msg("请求头格式不合法");
  931. return;
  932. }
  933. try {
  934. if (params) {
  935. params = JSON.parse(params);
  936. }
  937. } catch (e) {
  938. layer.msg("请求参数格式不合法");
  939. return;
  940. }
  941. layer.load(0, { shade: false });
  942. $.ajax({
  943. url: "https://fetch-api.feny.ink/httpRequest",
  944. type: "POST",
  945. data: JSON.stringify(form),
  946. contentType: "application/json"
  947. }).then(
  948. (response) => {
  949. _unsafeWindow.GLOBAL_JSONP_FUN = null;
  950. that2.reload(response, JSON.stringify(response));
  951. },
  952. (error) => {
  953. layer.closeAll();
  954. console.log(error);
  955. }
  956. );
  957. });
  958. });
  959. return this;
  960. },
  961. reload: function(json2, rawText2) {
  962. _unsafeWindow.GLOBAL_JSON = json2;
  963. _unsafeWindow.GLOBAL_SOURCE_ELEMENT.text(rawText2);
  964. btnEvent.isBeautify = false;
  965. btnEvent.$rawText.html(_unsafeWindow.GLOBAL_SOURCE_ELEMENT.clone());
  966. formatStyle.setStyle();
  967. jsonMind.isFirst = true;
  968. jsonMind.init(_unsafeWindow.GLOBAL_JSON);
  969. layer.closeAll();
  970. },
  971. init: function() {
  972. this.input().clear().scrollTop().urlHover().tipsJsonPath().copyJsonPath().inputJson().fetchApi();
  973. }
  974. };
  975. function treeTableHtml(json2, level = 0, pId = "", pChain = "") {
  976. let tr = "";
  977. for (const key in json2) {
  978. let val = json2[key], type = Utils.getType(val), tId = key + "_" + Math.random(), chain = pChain + "." + key;
  979. if (["array", "object"].includes(type)) {
  980. let brackets = "", len = Object.keys(val).length, res = treeTableHtml(val, level + 1, tId, chain);
  981. if (!res) {
  982. if (type === "array") {
  983. brackets = `<span class="json-brackets json-square-brackets">[]</span>`;
  984. } else {
  985. brackets = `<span class="json-brackets json-curly-brackets">{}</span>`;
  986. }
  987. }
  988. tr += `
  989. <tr data-node-id="${tId}" data-node-pid="${pId}" type="${type}">
  990. <td class="json-key" json-path="${chain}" style="padding-left: ${level * 19}px">${key}:
  991. <span class="tree-len">${len > 0 ? type === "array" ? "[" + len + "]" : "{" + len + "}" : ""}</span>
  992. </td>
  993. <td>${brackets}</td>
  994. </tr>`;
  995. tr += res;
  996. } else {
  997. val = type === "string" ? val.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;") : val;
  998. tr += `<tr data-node-id="${tId}" data-node-pid="${pId}" type="${type}">
  999. <td class="json-key" json-path="${chain}" style="padding-left: ${level * 19}px">${key}:</td>`;
  1000. if (Utils.isUrl(val)) {
  1001. tr += `<td class="json-${type}"><a target="_blank" href="${val}">"${val}"</a></td>`;
  1002. } else {
  1003. val = type === "string" ? `"${val}"` : val;
  1004. tr += `<td class="json-${type}">${val}</td>`;
  1005. }
  1006. tr += "</tr>";
  1007. }
  1008. }
  1009. return tr;
  1010. }
  1011. !function(e) {
  1012. var t = {};
  1013. function n(o) {
  1014. if (t[o]) return t[o].exports;
  1015. var i = t[o] = { i: o, l: false, exports: {} };
  1016. return e[o].call(i.exports, i, i.exports, n), i.l = true, i.exports;
  1017. }
  1018. n.m = e, n.c = t, n.d = function(e2, t2, o) {
  1019. n.o(e2, t2) || Object.defineProperty(e2, t2, { enumerable: true, get: o });
  1020. }, n.r = function(e2) {
  1021. "undefined" != typeof Symbol && Symbol.toStringTag && Object.defineProperty(e2, Symbol.toStringTag, { value: "Module" }), Object.defineProperty(e2, "__esModule", { value: true });
  1022. }, n.t = function(e2, t2) {
  1023. if (1 & t2 && (e2 = n(e2)), 8 & t2) return e2;
  1024. if (4 & t2 && "object" == typeof e2 && e2 && e2.__esModule) return e2;
  1025. var o = /* @__PURE__ */ Object.create(null);
  1026. if (n.r(o), Object.defineProperty(o, "default", { enumerable: true, value: e2 }), 2 & t2 && "string" != typeof e2) for (var i in e2) n.d(o, i, (function(t3) {
  1027. return e2[t3];
  1028. }).bind(null, i));
  1029. return o;
  1030. }, n.n = function(e2) {
  1031. var t2 = e2 && e2.__esModule ? function() {
  1032. return e2.default;
  1033. } : function() {
  1034. return e2;
  1035. };
  1036. return n.d(t2, "a", t2), t2;
  1037. }, n.o = function(e2, t2) {
  1038. return Object.prototype.hasOwnProperty.call(e2, t2);
  1039. }, n.p = "/dist", n(n.s = 5);
  1040. }([function(e, t) {
  1041. e.exports = $;
  1042. }, function(e, t, n) {
  1043. var o = n(2), i = n(3);
  1044. "string" == typeof (i = i.__esModule ? i.default : i) && (i = [[e.i, i, ""]]);
  1045. var a = { insert: "head", singleton: false };
  1046. o(i, a);
  1047. e.exports = i.locals || {};
  1048. }, function(e, t, n) {
  1049. var o, i = function() {
  1050. return void 0 === o && (o = Boolean(window && document && document.all && !window.atob)), o;
  1051. }, a = /* @__PURE__ */ function() {
  1052. var e2 = {};
  1053. return function(t2) {
  1054. if (void 0 === e2[t2]) {
  1055. var n2 = document.querySelector(t2);
  1056. if (window.HTMLIFrameElement && n2 instanceof window.HTMLIFrameElement) try {
  1057. n2 = n2.contentDocument.head;
  1058. } catch (e3) {
  1059. n2 = null;
  1060. }
  1061. e2[t2] = n2;
  1062. }
  1063. return e2[t2];
  1064. };
  1065. }(), r = [];
  1066. function s(e2) {
  1067. for (var t2 = -1, n2 = 0; n2 < r.length; n2++) if (r[n2].identifier === e2) {
  1068. t2 = n2;
  1069. break;
  1070. }
  1071. return t2;
  1072. }
  1073. function c(e2, t2) {
  1074. for (var n2 = {}, o2 = [], i2 = 0; i2 < e2.length; i2++) {
  1075. var a2 = e2[i2], c2 = t2.base ? a2[0] + t2.base : a2[0], l2 = n2[c2] || 0, u2 = "".concat(c2, " ").concat(l2);
  1076. n2[c2] = l2 + 1;
  1077. var d2 = s(u2), f2 = { css: a2[1], media: a2[2], sourceMap: a2[3] };
  1078. -1 !== d2 ? (r[d2].references++, r[d2].updater(f2)) : r.push({ identifier: u2, updater: y(f2, t2), references: 1 }), o2.push(u2);
  1079. }
  1080. return o2;
  1081. }
  1082. function l(e2) {
  1083. var t2 = document.createElement("style"), o2 = e2.attributes || {};
  1084. if (void 0 === o2.nonce) {
  1085. var i2 = n.nc;
  1086. i2 && (o2.nonce = i2);
  1087. }
  1088. if (Object.keys(o2).forEach(function(e3) {
  1089. t2.setAttribute(e3, o2[e3]);
  1090. }), "function" == typeof e2.insert) e2.insert(t2);
  1091. else {
  1092. var r2 = a(e2.insert || "head");
  1093. if (!r2) throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");
  1094. r2.appendChild(t2);
  1095. }
  1096. return t2;
  1097. }
  1098. var u, d = (u = [], function(e2, t2) {
  1099. return u[e2] = t2, u.filter(Boolean).join("\n");
  1100. });
  1101. function f(e2, t2, n2, o2) {
  1102. var i2 = n2 ? "" : o2.media ? "@media ".concat(o2.media, " {").concat(o2.css, "}") : o2.css;
  1103. if (e2.styleSheet) e2.styleSheet.cssText = d(t2, i2);
  1104. else {
  1105. var a2 = document.createTextNode(i2), r2 = e2.childNodes;
  1106. r2[t2] && e2.removeChild(r2[t2]), r2.length ? e2.insertBefore(a2, r2[t2]) : e2.appendChild(a2);
  1107. }
  1108. }
  1109. function h(e2, t2, n2) {
  1110. var o2 = n2.css, i2 = n2.media, a2 = n2.sourceMap;
  1111. if (i2 ? e2.setAttribute("media", i2) : e2.removeAttribute("media"), a2 && btoa && (o2 += "\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(a2)))), " */")), e2.styleSheet) e2.styleSheet.cssText = o2;
  1112. else {
  1113. for (; e2.firstChild; ) e2.removeChild(e2.firstChild);
  1114. e2.appendChild(document.createTextNode(o2));
  1115. }
  1116. }
  1117. var p = null, v = 0;
  1118. function y(e2, t2) {
  1119. var n2, o2, i2;
  1120. if (t2.singleton) {
  1121. var a2 = v++;
  1122. n2 = p || (p = l(t2)), o2 = f.bind(null, n2, a2, false), i2 = f.bind(null, n2, a2, true);
  1123. } else n2 = l(t2), o2 = h.bind(null, n2, t2), i2 = function() {
  1124. !function(e3) {
  1125. if (null === e3.parentNode) return false;
  1126. e3.parentNode.removeChild(e3);
  1127. }(n2);
  1128. };
  1129. return o2(e2), function(t3) {
  1130. if (t3) {
  1131. if (t3.css === e2.css && t3.media === e2.media && t3.sourceMap === e2.sourceMap) return;
  1132. o2(e2 = t3);
  1133. } else i2();
  1134. };
  1135. }
  1136. e.exports = function(e2, t2) {
  1137. (t2 = t2 || {}).singleton || "boolean" == typeof t2.singleton || (t2.singleton = i());
  1138. var n2 = c(e2 = e2 || [], t2);
  1139. return function(e3) {
  1140. if (e3 = e3 || [], "[object Array]" === Object.prototype.toString.call(e3)) {
  1141. for (var o2 = 0; o2 < n2.length; o2++) {
  1142. var i2 = s(n2[o2]);
  1143. r[i2].references--;
  1144. }
  1145. for (var a2 = c(e3, t2), l2 = 0; l2 < n2.length; l2++) {
  1146. var u2 = s(n2[l2]);
  1147. 0 === r[u2].references && (r[u2].updater(), r.splice(u2, 1));
  1148. }
  1149. n2 = a2;
  1150. }
  1151. };
  1152. };
  1153. }, function(e, t, n) {
  1154. (t = n(4)(false)).push([e.i, ".simple-tree-table-icon{display:inline-block;width:1.5em;line-height:1.5em;margin:0.1em;background-color:#eee;text-align:center;cursor:pointer}.simple-tree-table-opened .simple-tree-table-icon:after{content:'-'}.simple-tree-table-closed .simple-tree-table-icon:after{content:'+'}\n", ""]), e.exports = t;
  1155. }, function(e, t, n) {
  1156. e.exports = function(e2) {
  1157. var t2 = [];
  1158. return t2.toString = function() {
  1159. return this.map(function(t3) {
  1160. var n2 = function(e3, t4) {
  1161. var n3 = e3[1] || "", o = e3[3];
  1162. if (!o) return n3;
  1163. if (t4 && "function" == typeof btoa) {
  1164. var i = (r = o, s = btoa(unescape(encodeURIComponent(JSON.stringify(r)))), c = "sourceMappingURL=data:application/json;charset=utf-8;base64,".concat(s), "/*# ".concat(c, " */")), a = o.sources.map(function(e4) {
  1165. return "/*# sourceURL=".concat(o.sourceRoot || "").concat(e4, " */");
  1166. });
  1167. return [n3].concat(a).concat([i]).join("\n");
  1168. }
  1169. var r, s, c;
  1170. return [n3].join("\n");
  1171. }(t3, e2);
  1172. return t3[2] ? "@media ".concat(t3[2], " {").concat(n2, "}") : n2;
  1173. }).join("");
  1174. }, t2.i = function(e3, n2, o) {
  1175. "string" == typeof e3 && (e3 = [[null, e3, ""]]);
  1176. var i = {};
  1177. if (o) for (var a = 0; a < this.length; a++) {
  1178. var r = this[a][0];
  1179. null != r && (i[r] = true);
  1180. }
  1181. for (var s = 0; s < e3.length; s++) {
  1182. var c = [].concat(e3[s]);
  1183. o && i[c[0]] || (n2 && (c[2] ? c[2] = "".concat(n2, " and ").concat(c[2]) : c[2] = n2), t2.push(c));
  1184. }
  1185. }, t2;
  1186. };
  1187. }, function(e, t, n) {
  1188. n.r(t);
  1189. var o = n(0), i = n.n(o);
  1190. function a(e2, t2) {
  1191. if (!(e2 instanceof t2)) throw new TypeError("Cannot call a class as a function");
  1192. }
  1193. function r(e2, t2) {
  1194. for (var n2 = 0; n2 < t2.length; n2++) {
  1195. var o2 = t2[n2];
  1196. o2.enumerable = o2.enumerable || false, o2.configurable = true, "value" in o2 && (o2.writable = true), Object.defineProperty(e2, o2.key, o2);
  1197. }
  1198. }
  1199. function s(e2, t2, n2) {
  1200. return t2 && r(e2.prototype, t2), e2;
  1201. }
  1202. var c = function() {
  1203. function e2() {
  1204. var t2 = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
  1205. a(this, e2), this.opts = { type: t2.type || "session", key: t2.key }, this.inst = new l(this.opts);
  1206. }
  1207. return s(e2, [{ key: "get", value: function() {
  1208. var e3 = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : null;
  1209. return this.inst.get(this.opts.key) || e3;
  1210. } }, { key: "set", value: function(e3) {
  1211. this.inst.set(this.opts.key, e3);
  1212. } }, { key: "remove", value: function() {
  1213. this.inst.remove(this.opts.key);
  1214. } }]), e2;
  1215. }(), l = function() {
  1216. function e2() {
  1217. var t2 = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
  1218. a(this, e2), this.storage = { local: window.localStorage, session: window.sessionStorage }[t2.type];
  1219. }
  1220. return s(e2, [{ key: "get", value: function(e3) {
  1221. try {
  1222. var t2 = this.storage.getItem(e3);
  1223. return t2 ? JSON.parse(t2) : null;
  1224. } catch (e4) {
  1225. return console.log(e4), null;
  1226. }
  1227. } }, { key: "set", value: function(e3, t2) {
  1228. try {
  1229. this.storage.setItem(e3, JSON.stringify(t2));
  1230. } catch (e4) {
  1231. console.log(e4);
  1232. }
  1233. } }, { key: "remove", value: function(e3) {
  1234. this.storage.removeItem(e3);
  1235. } }]), e2;
  1236. }(), u = (n(1), "simple-tree-table");
  1237. function d(e2, t2) {
  1238. if (!(e2 instanceof t2)) throw new TypeError("Cannot call a class as a function");
  1239. }
  1240. function f(e2, t2) {
  1241. for (var n2 = 0; n2 < t2.length; n2++) {
  1242. var o2 = t2[n2];
  1243. o2.enumerable = o2.enumerable || false, o2.configurable = true, "value" in o2 && (o2.writable = true), Object.defineProperty(e2, o2.key, o2);
  1244. }
  1245. }
  1246. var h = { expander: null, collapser: null, opened: "all", margin: 20, iconPosition: "> :first-child", iconTemplate: "<span />", store: null, storeKey: null }, p = function() {
  1247. function e2(t3) {
  1248. var n3 = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {};
  1249. d(this, e2), this.options = i.a.extend({}, h, n3), this.$table = i()(t3), this.$expander = i()(this.options.expander), this.$collapser = i()(this.options.collapser), this.options.store && this.options.storeKey && (this.store = new c({ type: this.options.store, key: this.options.storeKey })), this.init(), this.load();
  1250. }
  1251. var t2, n2, o2;
  1252. return t2 = e2, o2 = [{ key: "getDefaults", value: function() {
  1253. return h;
  1254. } }, { key: "setDefaults", value: function(e3) {
  1255. return i.a.extend(h, e3);
  1256. } }], (n2 = [{ key: "init", value: function() {
  1257. this.$table.addClass(u), this.build(), this.unbind(), this.bind();
  1258. } }, { key: "destroy", value: function() {
  1259. var e3 = function(e4, t3) {
  1260. var n3 = new RegExp("".concat(u, "(-\\S+)?"), "g");
  1261. return (t3.match(n3) || []).join(" ");
  1262. };
  1263. this.$table.removeClass(e3), this.nodes().removeClass(e3), this.$table.find(".".concat(u, "-icon")).remove(), this.unbind();
  1264. } }, { key: "build", value: function() {
  1265. var e3 = this;
  1266. this.nodes().not("[data-node-depth]").each(function(t3, n3) {
  1267. var o3 = i()(n3), a2 = e3.depth(o3);
  1268. o3.data("node-depth", a2), 1 == a2 && o3.addClass("".concat(u, "-root"));
  1269. }), this.nodes().filter(function(t3, n3) {
  1270. return 0 == i()(n3).find(e3.options.iconPosition).find(".".concat(u, "-handler")).length;
  1271. }).each(function(t3, n3) {
  1272. var o3 = i()(n3), a2 = e3.depth(o3), r2 = e3.options.margin * (a2 - 1), s2 = i()(e3.options.iconTemplate).addClass("".concat(u, "-handler ").concat(u, "-icon")).css("margin-left", "".concat(r2, "px"));
  1273. o3.find(e3.options.iconPosition).prepend(s2);
  1274. }), this.nodes().not(".".concat(u, "-empty, .").concat(u, "-opened, .").concat(u, "-closed")).each(function(t3, n3) {
  1275. var o3 = i()(n3);
  1276. e3.hasChildren(o3) ? e3.opensDefault(o3) ? o3.addClass("".concat(u, "-opened")) : o3.addClass("".concat(u, "-closed")) : o3.addClass("".concat(u, "-empty"));
  1277. }), this.nodes().filter(".".concat(u, "-opened")).each(function(t3, n3) {
  1278. e3.show(i()(n3));
  1279. }), this.nodes().filter(".".concat(u, "-closed")).each(function(t3, n3) {
  1280. e3.hide(i()(n3));
  1281. });
  1282. } }, { key: "opensDefault", value: function(e3) {
  1283. var t3 = this.options.opened;
  1284. return t3 && ("all" == t3 || -1 != t3.indexOf(e3.data("node-id")));
  1285. } }, { key: "bind", value: function() {
  1286. var e3 = this;
  1287. this.$expander.on("click.".concat(u), function(t3) {
  1288. e3.expand();
  1289. }), this.$collapser.on("click.".concat(u), function(t3) {
  1290. e3.collapse();
  1291. }), this.$table.on("click.".concat(u), "tr .".concat(u, "-handler"), function(t3) {
  1292. var n3 = i()(t3.currentTarget).closest("tr");
  1293. n3.hasClass("".concat(u, "-opened")) ? e3.close(n3) : e3.open(n3);
  1294. });
  1295. } }, { key: "unbind", value: function() {
  1296. this.$expander.off(".".concat(u)), this.$collapser.off(".".concat(u)), this.$table.off(".".concat(u, " node:open node:close"));
  1297. } }, { key: "expand", value: function() {
  1298. var e3 = this;
  1299. this.nodes().each(function(t3, n3) {
  1300. e3.show(i()(n3));
  1301. }), this.save();
  1302. } }, { key: "collapse", value: function() {
  1303. var e3 = this;
  1304. this.nodes().each(function(t3, n3) {
  1305. e3.hide(i()(n3));
  1306. }), this.save();
  1307. } }, { key: "nodes", value: function() {
  1308. return this.$table.find("tr[data-node-id]");
  1309. } }, { key: "depth", value: function(e3) {
  1310. var t3 = e3.data("node-depth");
  1311. if (t3) return t3;
  1312. var n3 = this.findByID(e3.data("node-pid"));
  1313. return 0 != n3.length ? this.depth(n3) + 1 : 1;
  1314. } }, { key: "open", value: function(e3) {
  1315. this.show(e3), this.save(), e3.trigger("node:open", [e3]);
  1316. } }, { key: "show", value: function(e3) {
  1317. e3.hasClass("".concat(u, "-empty")) || (e3.removeClass("".concat(u, "-closed")).addClass("".concat(u, "-opened")), this.showDescs(e3));
  1318. } }, { key: "showDescs", value: function(e3) {
  1319. var t3 = this;
  1320. this.findChildren(e3).each(function(e4, n3) {
  1321. var o3 = i()(n3);
  1322. o3.show(), o3.hasClass("".concat(u, "-opened")) && t3.showDescs(o3);
  1323. });
  1324. } }, { key: "close", value: function(e3) {
  1325. this.hide(e3), this.save(), e3.trigger("node:close", [e3]);
  1326. } }, { key: "hide", value: function(e3) {
  1327. e3.hasClass("".concat(u, "-empty")) || (e3.removeClass("".concat(u, "-opened")).addClass("".concat(u, "-closed")), this.hideDescs(e3));
  1328. } }, { key: "hideDescs", value: function(e3) {
  1329. var t3 = this;
  1330. this.findChildren(e3).each(function(e4, n3) {
  1331. var o3 = i()(n3);
  1332. o3.hide(), t3.hideDescs(o3);
  1333. });
  1334. } }, { key: "hasChildren", value: function(e3) {
  1335. return 0 != this.findChildren(e3).length;
  1336. } }, { key: "findChildren", value: function(e3) {
  1337. var t3 = e3.data("node-id");
  1338. return this.$table.find('tr[data-node-pid="'.concat(t3, '"]'));
  1339. } }, { key: "findDescendants", value: function(e3) {
  1340. var t3 = this, n3 = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : [], o3 = this.findChildren(e3);
  1341. return n3.push(o3), o3.each(function(e4, o4) {
  1342. t3.findDescendants(i()(o4), n3);
  1343. }), n3;
  1344. } }, { key: "findByID", value: function(e3) {
  1345. return this.$table.find('tr[data-node-id="'.concat(e3, '"]'));
  1346. } }, { key: "openByID", value: function(e3) {
  1347. this.open(this.findByID(e3));
  1348. } }, { key: "closeByID", value: function(e3) {
  1349. this.close(this.findByID(e3));
  1350. } }, { key: "load", value: function() {
  1351. var e3 = this;
  1352. if (this.store) {
  1353. var t3 = this.store.get();
  1354. t3 && (this.nodes().each(function(t4, n3) {
  1355. e3.show(i()(n3));
  1356. }), this.nodes().filter(function(e4, n3) {
  1357. return -1 != t3.indexOf(i()(n3).data("node-id"));
  1358. }).each(function(t4, n3) {
  1359. e3.hide(i()(n3));
  1360. }));
  1361. }
  1362. } }, { key: "save", value: function() {
  1363. if (this.store) {
  1364. var e3 = this.nodes().filter(".".concat(u, "-closed")).map(function(e4, t3) {
  1365. return i()(t3).data("node-id");
  1366. }).get();
  1367. this.store.set(e3);
  1368. }
  1369. } }]) && f(t2.prototype, n2), o2 && f(t2, o2), e2;
  1370. }();
  1371. i.a.fn.simpleTreeTable = function(e2) {
  1372. return this.each(function(t2, n2) {
  1373. var o2 = i()(n2);
  1374. o2.data(u) && o2.data(u).destroy(), o2.data(u, new p(o2, e2));
  1375. });
  1376. }, i.a.SimpleTreeTable = p;
  1377. }]);
  1378. const formatStyle = exports("default", {
  1379. // 切换风格
  1380. changeStyle: function() {
  1381. const that2 = this;
  1382. $(".formatStyle select").change(function(e) {
  1383. const val = $(e.target).val();
  1384. _GM_setValue("formatStyle", val);
  1385. that2.setStyle();
  1386. });
  1387. return this;
  1388. },
  1389. // 设置风格
  1390. setStyle: function() {
  1391. const style = _GM_getValue("formatStyle") || "default";
  1392. $(".formatStyle select").val(style);
  1393. $("input").val("");
  1394. $("#formatContainer").html("");
  1395. if (style === "default") {
  1396. $("#formatContainer").jsonViewer(
  1397. _unsafeWindow.GLOBAL_JSON,
  1398. _unsafeWindow.GLOBAL_JSONP_FUN
  1399. );
  1400. } else {
  1401. let appendHtml = `<table id="treeTable">${treeTableHtml(
  1402. _unsafeWindow.GLOBAL_JSON
  1403. )}</table>`;
  1404. if (_unsafeWindow.GLOBAL_JSONP_FUN !== void 0 && _unsafeWindow.GLOBAL_JSONP_FUN !== null) {
  1405. appendHtml = `<div class="jsonp">${_unsafeWindow.GLOBAL_JSONP_FUN}(</div>${appendHtml}<div class="jsonp">)</div>`;
  1406. }
  1407. $("#formatContainer").append(appendHtml);
  1408. $("#treeTable").simpleTreeTable({
  1409. expander: "#expandAll",
  1410. collapser: "#collapseAll"
  1411. });
  1412. $("#treeTable").on("mousedown", "tr", function() {
  1413. $(".selected").not(this).removeClass("selected");
  1414. $(this).toggleClass("selected");
  1415. });
  1416. }
  1417. return this;
  1418. },
  1419. init: function() {
  1420. this.setStyle().changeStyle();
  1421. theme.init();
  1422. btnEvent.init();
  1423. setTimeout(() => otherEvent.init(), 1e3);
  1424. }
  1425. });
  1426.  
  1427. })
  1428. };
  1429. }));
  1430.  
  1431. System.import("./__entry.js", "./");