Greasy Fork is available in English.

YapiCopy

Yapi接口数据一键复制

اعتبارا من 22-08-2024. شاهد أحدث إصدار.

  1. // ==UserScript==
  2. // @name YapiCopy
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.4.21
  5. // @description Yapi接口数据一键复制
  6. // @author Enjoy
  7. // @icon https://foruda.gitee.com/avatar/1698283059572409586/4867929_enjoy_li_1698283059.png!avatar200
  8. // @match *://yapi.*.com/project/*/interface/api/*
  9. // @exclude *localhost*
  10. // @grant GM_addElement
  11. // @grant GM_addStyle
  12. // @grant GM_setClipboard
  13. // @license GPL License
  14. // @ES6+ =>ES5 https://babel.docschina.org/repl/
  15. // ==/UserScript==
  16.  
  17. /******/ (() => { // webpackBootstrap
  18. /******/ var __webpack_modules__ = ({
  19.  
  20. /***/ 712:
  21. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  22.  
  23. var _typeof = (__webpack_require__(215)["default"]);
  24. function _regeneratorRuntime() {
  25. "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
  26. module.exports = _regeneratorRuntime = function _regeneratorRuntime() {
  27. return e;
  28. }, module.exports.__esModule = true, module.exports["default"] = module.exports;
  29. var t,
  30. e = {},
  31. r = Object.prototype,
  32. n = r.hasOwnProperty,
  33. o = Object.defineProperty || function (t, e, r) {
  34. t[e] = r.value;
  35. },
  36. i = "function" == typeof Symbol ? Symbol : {},
  37. a = i.iterator || "@@iterator",
  38. c = i.asyncIterator || "@@asyncIterator",
  39. u = i.toStringTag || "@@toStringTag";
  40. function define(t, e, r) {
  41. return Object.defineProperty(t, e, {
  42. value: r,
  43. enumerable: !0,
  44. configurable: !0,
  45. writable: !0
  46. }), t[e];
  47. }
  48. try {
  49. define({}, "");
  50. } catch (t) {
  51. define = function define(t, e, r) {
  52. return t[e] = r;
  53. };
  54. }
  55. function wrap(t, e, r, n) {
  56. var i = e && e.prototype instanceof Generator ? e : Generator,
  57. a = Object.create(i.prototype),
  58. c = new Context(n || []);
  59. return o(a, "_invoke", {
  60. value: makeInvokeMethod(t, r, c)
  61. }), a;
  62. }
  63. function tryCatch(t, e, r) {
  64. try {
  65. return {
  66. type: "normal",
  67. arg: t.call(e, r)
  68. };
  69. } catch (t) {
  70. return {
  71. type: "throw",
  72. arg: t
  73. };
  74. }
  75. }
  76. e.wrap = wrap;
  77. var h = "suspendedStart",
  78. l = "suspendedYield",
  79. f = "executing",
  80. s = "completed",
  81. y = {};
  82. function Generator() {}
  83. function GeneratorFunction() {}
  84. function GeneratorFunctionPrototype() {}
  85. var p = {};
  86. define(p, a, function () {
  87. return this;
  88. });
  89. var d = Object.getPrototypeOf,
  90. v = d && d(d(values([])));
  91. v && v !== r && n.call(v, a) && (p = v);
  92. var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
  93. function defineIteratorMethods(t) {
  94. ["next", "throw", "return"].forEach(function (e) {
  95. define(t, e, function (t) {
  96. return this._invoke(e, t);
  97. });
  98. });
  99. }
  100. function AsyncIterator(t, e) {
  101. function invoke(r, o, i, a) {
  102. var c = tryCatch(t[r], t, o);
  103. if ("throw" !== c.type) {
  104. var u = c.arg,
  105. h = u.value;
  106. return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
  107. invoke("next", t, i, a);
  108. }, function (t) {
  109. invoke("throw", t, i, a);
  110. }) : e.resolve(h).then(function (t) {
  111. u.value = t, i(u);
  112. }, function (t) {
  113. return invoke("throw", t, i, a);
  114. });
  115. }
  116. a(c.arg);
  117. }
  118. var r;
  119. o(this, "_invoke", {
  120. value: function value(t, n) {
  121. function callInvokeWithMethodAndArg() {
  122. return new e(function (e, r) {
  123. invoke(t, n, e, r);
  124. });
  125. }
  126. return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
  127. }
  128. });
  129. }
  130. function makeInvokeMethod(e, r, n) {
  131. var o = h;
  132. return function (i, a) {
  133. if (o === f) throw new Error("Generator is already running");
  134. if (o === s) {
  135. if ("throw" === i) throw a;
  136. return {
  137. value: t,
  138. done: !0
  139. };
  140. }
  141. for (n.method = i, n.arg = a;;) {
  142. var c = n.delegate;
  143. if (c) {
  144. var u = maybeInvokeDelegate(c, n);
  145. if (u) {
  146. if (u === y) continue;
  147. return u;
  148. }
  149. }
  150. if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
  151. if (o === h) throw o = s, n.arg;
  152. n.dispatchException(n.arg);
  153. } else "return" === n.method && n.abrupt("return", n.arg);
  154. o = f;
  155. var p = tryCatch(e, r, n);
  156. if ("normal" === p.type) {
  157. if (o = n.done ? s : l, p.arg === y) continue;
  158. return {
  159. value: p.arg,
  160. done: n.done
  161. };
  162. }
  163. "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
  164. }
  165. };
  166. }
  167. function maybeInvokeDelegate(e, r) {
  168. var n = r.method,
  169. o = e.iterator[n];
  170. if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
  171. var i = tryCatch(o, e.iterator, r.arg);
  172. if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
  173. var a = i.arg;
  174. return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
  175. }
  176. function pushTryEntry(t) {
  177. var e = {
  178. tryLoc: t[0]
  179. };
  180. 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
  181. }
  182. function resetTryEntry(t) {
  183. var e = t.completion || {};
  184. e.type = "normal", delete e.arg, t.completion = e;
  185. }
  186. function Context(t) {
  187. this.tryEntries = [{
  188. tryLoc: "root"
  189. }], t.forEach(pushTryEntry, this), this.reset(!0);
  190. }
  191. function values(e) {
  192. if (e || "" === e) {
  193. var r = e[a];
  194. if (r) return r.call(e);
  195. if ("function" == typeof e.next) return e;
  196. if (!isNaN(e.length)) {
  197. var o = -1,
  198. i = function next() {
  199. for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
  200. return next.value = t, next.done = !0, next;
  201. };
  202. return i.next = i;
  203. }
  204. }
  205. throw new TypeError(_typeof(e) + " is not iterable");
  206. }
  207. return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
  208. value: GeneratorFunctionPrototype,
  209. configurable: !0
  210. }), o(GeneratorFunctionPrototype, "constructor", {
  211. value: GeneratorFunction,
  212. configurable: !0
  213. }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
  214. var e = "function" == typeof t && t.constructor;
  215. return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
  216. }, e.mark = function (t) {
  217. return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
  218. }, e.awrap = function (t) {
  219. return {
  220. __await: t
  221. };
  222. }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
  223. return this;
  224. }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
  225. void 0 === i && (i = Promise);
  226. var a = new AsyncIterator(wrap(t, r, n, o), i);
  227. return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
  228. return t.done ? t.value : a.next();
  229. });
  230. }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
  231. return this;
  232. }), define(g, "toString", function () {
  233. return "[object Generator]";
  234. }), e.keys = function (t) {
  235. var e = Object(t),
  236. r = [];
  237. for (var n in e) r.push(n);
  238. return r.reverse(), function next() {
  239. for (; r.length;) {
  240. var t = r.pop();
  241. if (t in e) return next.value = t, next.done = !1, next;
  242. }
  243. return next.done = !0, next;
  244. };
  245. }, e.values = values, Context.prototype = {
  246. constructor: Context,
  247. reset: function reset(e) {
  248. if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
  249. },
  250. stop: function stop() {
  251. this.done = !0;
  252. var t = this.tryEntries[0].completion;
  253. if ("throw" === t.type) throw t.arg;
  254. return this.rval;
  255. },
  256. dispatchException: function dispatchException(e) {
  257. if (this.done) throw e;
  258. var r = this;
  259. function handle(n, o) {
  260. return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
  261. }
  262. for (var o = this.tryEntries.length - 1; o >= 0; --o) {
  263. var i = this.tryEntries[o],
  264. a = i.completion;
  265. if ("root" === i.tryLoc) return handle("end");
  266. if (i.tryLoc <= this.prev) {
  267. var c = n.call(i, "catchLoc"),
  268. u = n.call(i, "finallyLoc");
  269. if (c && u) {
  270. if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
  271. if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
  272. } else if (c) {
  273. if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
  274. } else {
  275. if (!u) throw new Error("try statement without catch or finally");
  276. if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
  277. }
  278. }
  279. }
  280. },
  281. abrupt: function abrupt(t, e) {
  282. for (var r = this.tryEntries.length - 1; r >= 0; --r) {
  283. var o = this.tryEntries[r];
  284. if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
  285. var i = o;
  286. break;
  287. }
  288. }
  289. i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
  290. var a = i ? i.completion : {};
  291. return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
  292. },
  293. complete: function complete(t, e) {
  294. if ("throw" === t.type) throw t.arg;
  295. return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
  296. },
  297. finish: function finish(t) {
  298. for (var e = this.tryEntries.length - 1; e >= 0; --e) {
  299. var r = this.tryEntries[e];
  300. if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
  301. }
  302. },
  303. "catch": function _catch(t) {
  304. for (var e = this.tryEntries.length - 1; e >= 0; --e) {
  305. var r = this.tryEntries[e];
  306. if (r.tryLoc === t) {
  307. var n = r.completion;
  308. if ("throw" === n.type) {
  309. var o = n.arg;
  310. resetTryEntry(r);
  311. }
  312. return o;
  313. }
  314. }
  315. throw new Error("illegal catch attempt");
  316. },
  317. delegateYield: function delegateYield(e, r, n) {
  318. return this.delegate = {
  319. iterator: values(e),
  320. resultName: r,
  321. nextLoc: n
  322. }, "next" === this.method && (this.arg = t), y;
  323. }
  324. }, e;
  325. }
  326. module.exports = _regeneratorRuntime, module.exports.__esModule = true, module.exports["default"] = module.exports;
  327.  
  328. /***/ }),
  329.  
  330. /***/ 215:
  331. /***/ ((module) => {
  332.  
  333. function _typeof(o) {
  334. "@babel/helpers - typeof";
  335.  
  336. return (module.exports = _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
  337. return typeof o;
  338. } : function (o) {
  339. return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
  340. }, module.exports.__esModule = true, module.exports["default"] = module.exports), _typeof(o);
  341. }
  342. module.exports = _typeof, module.exports.__esModule = true, module.exports["default"] = module.exports;
  343.  
  344. /***/ }),
  345.  
  346. /***/ 54:
  347. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  348.  
  349. // TODO(Babel 8): Remove this file.
  350.  
  351. var runtime = __webpack_require__(712)();
  352. module.exports = runtime;
  353.  
  354. // Copied from https://github.com/facebook/regenerator/blob/main/packages/runtime/runtime.js#L736=
  355. try {
  356. regeneratorRuntime = runtime;
  357. } catch (accidentalStrictMode) {
  358. if (typeof globalThis === "object") {
  359. globalThis.regeneratorRuntime = runtime;
  360. } else {
  361. Function("r", "regeneratorRuntime = r")(runtime);
  362. }
  363. }
  364.  
  365.  
  366. /***/ })
  367.  
  368. /******/ });
  369. /************************************************************************/
  370. /******/ // The module cache
  371. /******/ var __webpack_module_cache__ = {};
  372. /******/
  373. /******/ // The require function
  374. /******/ function __webpack_require__(moduleId) {
  375. /******/ // Check if module is in cache
  376. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  377. /******/ if (cachedModule !== undefined) {
  378. /******/ return cachedModule.exports;
  379. /******/ }
  380. /******/ // Create a new module (and put it into the cache)
  381. /******/ var module = __webpack_module_cache__[moduleId] = {
  382. /******/ // no module.id needed
  383. /******/ // no module.loaded needed
  384. /******/ exports: {}
  385. /******/ };
  386. /******/
  387. /******/ // Execute the module function
  388. /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  389. /******/
  390. /******/ // Return the exports of the module
  391. /******/ return module.exports;
  392. /******/ }
  393. /******/
  394. /************************************************************************/
  395. /******/ /* webpack/runtime/compat get default export */
  396. /******/ (() => {
  397. /******/ // getDefaultExport function for compatibility with non-harmony modules
  398. /******/ __webpack_require__.n = (module) => {
  399. /******/ var getter = module && module.__esModule ?
  400. /******/ () => (module['default']) :
  401. /******/ () => (module);
  402. /******/ __webpack_require__.d(getter, { a: getter });
  403. /******/ return getter;
  404. /******/ };
  405. /******/ })();
  406. /******/
  407. /******/ /* webpack/runtime/define property getters */
  408. /******/ (() => {
  409. /******/ // define getter functions for harmony exports
  410. /******/ __webpack_require__.d = (exports, definition) => {
  411. /******/ for(var key in definition) {
  412. /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  413. /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  414. /******/ }
  415. /******/ }
  416. /******/ };
  417. /******/ })();
  418. /******/
  419. /******/ /* webpack/runtime/hasOwnProperty shorthand */
  420. /******/ (() => {
  421. /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
  422. /******/ })();
  423. /******/
  424. /************************************************************************/
  425. var __webpack_exports__ = {};
  426. // This entry need to be wrapped in an IIFE because it need to be in strict mode.
  427. (() => {
  428. "use strict";
  429.  
  430. ;// CONCATENATED MODULE: ./node_modules/.pnpm/@babel+runtime@https+++registry.npmjs.org+@babel+runtime+-+runtime-7.22.15.tgz/node_modules/@babel/runtime/helpers/esm/arrayLikeToArray.js
  431. function _arrayLikeToArray(arr, len) {
  432. if (len == null || len > arr.length) len = arr.length;
  433. for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
  434. return arr2;
  435. }
  436. ;// CONCATENATED MODULE: ./node_modules/.pnpm/@babel+runtime@https+++registry.npmjs.org+@babel+runtime+-+runtime-7.22.15.tgz/node_modules/@babel/runtime/helpers/esm/arrayWithoutHoles.js
  437.  
  438. function _arrayWithoutHoles(arr) {
  439. if (Array.isArray(arr)) return _arrayLikeToArray(arr);
  440. }
  441. ;// CONCATENATED MODULE: ./node_modules/.pnpm/@babel+runtime@https+++registry.npmjs.org+@babel+runtime+-+runtime-7.22.15.tgz/node_modules/@babel/runtime/helpers/esm/iterableToArray.js
  442. function _iterableToArray(iter) {
  443. if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
  444. }
  445. ;// CONCATENATED MODULE: ./node_modules/.pnpm/@babel+runtime@https+++registry.npmjs.org+@babel+runtime+-+runtime-7.22.15.tgz/node_modules/@babel/runtime/helpers/esm/unsupportedIterableToArray.js
  446.  
  447. function _unsupportedIterableToArray(o, minLen) {
  448. if (!o) return;
  449. if (typeof o === "string") return _arrayLikeToArray(o, minLen);
  450. var n = Object.prototype.toString.call(o).slice(8, -1);
  451. if (n === "Object" && o.constructor) n = o.constructor.name;
  452. if (n === "Map" || n === "Set") return Array.from(o);
  453. if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
  454. }
  455. ;// CONCATENATED MODULE: ./node_modules/.pnpm/@babel+runtime@https+++registry.npmjs.org+@babel+runtime+-+runtime-7.22.15.tgz/node_modules/@babel/runtime/helpers/esm/nonIterableSpread.js
  456. function _nonIterableSpread() {
  457. throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  458. }
  459. ;// CONCATENATED MODULE: ./node_modules/.pnpm/@babel+runtime@https+++registry.npmjs.org+@babel+runtime+-+runtime-7.22.15.tgz/node_modules/@babel/runtime/helpers/esm/toConsumableArray.js
  460.  
  461.  
  462.  
  463.  
  464. function _toConsumableArray(arr) {
  465. return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
  466. }
  467. ;// CONCATENATED MODULE: ./node_modules/.pnpm/@babel+runtime@https+++registry.npmjs.org+@babel+runtime+-+runtime-7.22.15.tgz/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js
  468. function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
  469. try {
  470. var info = gen[key](arg);
  471. var value = info.value;
  472. } catch (error) {
  473. reject(error);
  474. return;
  475. }
  476. if (info.done) {
  477. resolve(value);
  478. } else {
  479. Promise.resolve(value).then(_next, _throw);
  480. }
  481. }
  482. function asyncToGenerator_asyncToGenerator(fn) {
  483. return function () {
  484. var self = this,
  485. args = arguments;
  486. return new Promise(function (resolve, reject) {
  487. var gen = fn.apply(self, args);
  488. function _next(value) {
  489. asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
  490. }
  491. function _throw(err) {
  492. asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
  493. }
  494. _next(undefined);
  495. });
  496. };
  497. }
  498. // EXTERNAL MODULE: ./node_modules/.pnpm/@babel+runtime@https+++registry.npmjs.org+@babel+runtime+-+runtime-7.22.15.tgz/node_modules/@babel/runtime/regenerator/index.js
  499. var regenerator = __webpack_require__(54);
  500. var regenerator_default = /*#__PURE__*/__webpack_require__.n(regenerator);
  501. ;// CONCATENATED MODULE: ./tools/GM.js
  502.  
  503.  
  504.  
  505.  
  506.  
  507. var _getElement;
  508.  
  509. function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
  510. function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
  511. /** @描述 函数文档 https://www.tampermonkey.net/documentation.php#api:GM_addElement */
  512.  
  513. /**
  514. * @description 创建element
  515. * @export
  516. * @param {*} tag
  517. * @param {*} [options={}]
  518. * @param {*} [win=window]
  519. * @returns {*}
  520. */
  521. function createElement(tag) {
  522. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  523. var win = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : window;
  524. if (!win.GM_createElement) {
  525. win.GM_createElement = GM_createElement;
  526. }
  527. return GM_createElement(tag, options);
  528. /**
  529. * @param {*} tag
  530. * @param {*} options {
  531. * idPrefix = `enjoy_${ENV_CRX}_${tag}`,
  532. * el = 'html',
  533. * autoInsert = true,
  534. * randomType = 'single',
  535. * id = '',
  536. * addPrefix = true,
  537. * insertType = tag === 'style' ? 'appendChild' : 'prepend',
  538. * }
  539. * @returns {*} dom
  540. */
  541. function GM_createElement(tag, options) {
  542. var _options$idPrefix = options.idPrefix,
  543. idPrefix = _options$idPrefix === void 0 ? "enjoy_".concat("YapiCopy", "_").concat(tag, "_") : _options$idPrefix,
  544. _options$el = options.el,
  545. el = _options$el === void 0 ? 'html' : _options$el,
  546. _options$autoInsert = options.autoInsert,
  547. autoInsert = _options$autoInsert === void 0 ? true : _options$autoInsert,
  548. _options$randomType = options.randomType,
  549. randomType = _options$randomType === void 0 ? 'single' : _options$randomType,
  550. _options$id = options.id,
  551. id = _options$id === void 0 ? '' : _options$id,
  552. _options$addPrefix = options.addPrefix,
  553. addPrefix = _options$addPrefix === void 0 ? true : _options$addPrefix,
  554. _options$insertType = options.insertType,
  555. insertType = _options$insertType === void 0 ? tag === 'style' ? 'appendChild' : 'prepend' : _options$insertType;
  556. if (addPrefix) {
  557. id = "".concat(idPrefix).concat(id);
  558. }
  559. if (randomType !== 'single') {
  560. id = "".concat(id, "_").concat(Math.floor(Math.random() * 1000));
  561. }
  562. options.id = id;
  563. var dom = document.querySelector("#".concat(id));
  564. if (!dom) {
  565. dom = document.createElement(tag);
  566. }
  567. for (var key in options) {
  568. if (Object.hasOwnProperty.call(options, key) && key !== 'el') {
  569. dom[key] = options[key];
  570. }
  571. }
  572. if (autoInsert) {
  573. if (typeof el === 'string') {
  574. el = document.querySelector(el);
  575. }
  576.  
  577. //insertType prepend | appendChild
  578. el[insertType](dom);
  579. }
  580. return dom;
  581. }
  582. }
  583.  
  584. /** @描述 是否匹配到目标url */
  585. function isMatched() {
  586. var urls = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  587. var currentUrl = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : location.href;
  588. if (typeof urls === 'string') {
  589. urls = [urls];
  590. }
  591. return !!urls.find(function (regUrl) {
  592. return new RegExp(regUrl).test(currentUrl);
  593. });
  594. }
  595. function prependMetaUF8() {
  596. return document.querySelector('meta[charset="UTF-8"]') || createElement('meta', {
  597. charset: 'utf-8'
  598. });
  599. }
  600.  
  601. /**
  602. * @description doCopy 复制文本到剪贴板
  603. * @export
  604. * @param {*} text
  605. */
  606. function doCopy(text) {
  607. var _navigator;
  608. if (document.hasFocus() && (_navigator = navigator) !== null && _navigator !== void 0 && (_navigator = _navigator.clipboard) !== null && _navigator !== void 0 && _navigator.writeText) {
  609. // localhost、127.0.0.1或者https中才能正常使用
  610. // 读取剪贴板
  611. // navigator.clipboard.readText().then((clipText) => {console.log('clipText=',clipText)})
  612.  
  613. // 写入剪贴板
  614. navigator.clipboard.writeText(text)["catch"](function (err) {
  615. return console.error("clipboard.writeText\uFF1A".concat(err));
  616. });
  617. return;
  618. }
  619. var textarea = document.createElement('textarea');
  620. document.body.appendChild(textarea);
  621. textarea.value = text;
  622. textarea.select();
  623. document.execCommand('Copy');
  624. setTimeout(function () {
  625. textarea.remove();
  626. }, 1000);
  627. }
  628.  
  629. /**
  630. * 检测element元素的可见性,即 非display:none
  631. * @param {*} element
  632. * @returns {*} {Boolean}
  633. */
  634. function checkVisibility(element) {
  635. if (element.checkVisibility) {
  636. return element.checkVisibility();
  637. }
  638. return !!element.offsetParent;
  639. }
  640. /**
  641. * @description 创建element的提示
  642. * @export
  643. * @param {*} [options={}]
  644. * @returns {*}
  645. */
  646. function createElementTipFn() {
  647. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  648. var _options$setTimeoutSt = options.setTimeoutStep,
  649. setTimeoutStep = _options$setTimeoutSt === void 0 ? 1000 : _options$setTimeoutSt,
  650. _options$backgroundCo = options.backgroundColors,
  651. backgroundColors = _options$backgroundCo === void 0 ? {
  652. warn: 'rgb(181 156 51 / 60%)',
  653. success: 'rgb(3 113 3 / 60%)',
  654. error: 'rgb(165 2 2 / 60%)',
  655. info: 'rgb(67 62 62 / 60%)'
  656. } : _options$backgroundCo,
  657. _options$color = options.color,
  658. color = _options$color === void 0 ? '#ffffff' : _options$color,
  659. _options$opacity = options.opacity,
  660. opacity = _options$opacity === void 0 ? 1 : _options$opacity;
  661. var setTimeoutStamp = 0;
  662. return function createElementTip() {
  663. var configs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  664. var content = configs.content,
  665. e = configs.e,
  666. _configs$type = configs.type,
  667. type = _configs$type === void 0 ? 'info' : _configs$type,
  668. _configs$tagType = configs.tagType,
  669. tagType = _configs$tagType === void 0 ? 'span' : _configs$tagType;
  670. if (!content) return;
  671. console.log("content => %O ", content);
  672. clearTimeout(setTimeoutStamp);
  673. var contentDom = createElement(tagType, {
  674. id: 'createElementTip',
  675. innerText: content,
  676. style: "\n font-size:14px;\n font-weight:600;\n color:".concat(color, ";\n position: fixed;\n left: ").concat(numbericalInterval(e.clientX - 46), "px;\n top: ").concat(numbericalInterval(e.clientY - 35, [5, window.innerHeight - 35]), "px;\n background-color:").concat(backgroundColors[type], ";\n opacity: ").concat(opacity, ";\n border-radius: 4px;\n padding: 4px 8px;\n box-shadow:0 0 5px 0 rgb(255 255 255 / 60%) inset;\n pointer-event:none;\n z-index:").concat((Math.floor(Date.now() / 1000) + '').slice(-5), ";\n\t\t\t\t\t\tdisplay:inline-block;\n ")
  677. });
  678. setTimeoutStamp = setTimeout(function () {
  679. // contentDom.remove()
  680. contentDom.style.display = 'none';
  681. }, setTimeoutStep);
  682. };
  683. }
  684. /**
  685. * @description dom是否可编辑
  686. * @param {*} [dom=document.activeElement]
  687. * @returns {*} {boolean}
  688. */
  689.  
  690. function isContentEditableOfDOM() {
  691. var dom = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document.activeElement;
  692. if (dom.tagName === 'INPUT' || dom.tagName === 'TEXTAREA') {
  693. return !dom.disabled;
  694. } else {
  695. return !!findParentElement(dom, function (dom) {
  696. return dom.contentEditable === 'true';
  697. }, null);
  698. }
  699. }
  700.  
  701. /**
  702. * @description 数字区间
  703. * @param {*} val
  704. * @param {*} [interval=[10, window.innerWidth]]
  705. * @returns {*}
  706. */
  707. function numbericalInterval(val) {
  708. var interval = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [5, window.innerWidth - 130];
  709. var indexStart = interval[0];
  710. var indexEnd = interval[1];
  711. if (val < indexStart) return indexStart;
  712. if (val > indexEnd) return indexEnd;
  713. return val;
  714. }
  715.  
  716. /**
  717. * @description 可滚动的dom
  718. * @param {*} dom
  719. * @returns {*}
  720. */
  721. function findHasScrollbarDom(dom) {
  722. if (!(dom instanceof HTMLElement)) {
  723. console.warn("\u53EF\u6EDA\u52A8\u7684dom\u51FD\u6570 findHasScrollbarDom:\u53C2\u6570dom\u5FC5\u987B\u4E3Aelement\u5143\u7D20 ");
  724. return void 0;
  725. }
  726. while (dom) {
  727. if (dom.offsetHeight < dom.scrollHeight && !(window.getComputedStyle(dom).overflowY == 'visible' || window.getComputedStyle(dom).overflowY == 'hidden')) {
  728. break;
  729. }
  730. dom = dom.parentElement;
  731. }
  732. if (!dom || dom === document.body) {
  733. // 始终是 documentElement等同于window
  734. dom = document.documentElement;
  735. }
  736. console.warn("\u9875\u9762\u6EDA\u52A8\u5143\u7D20\u7684tagName: ", dom.tagName.toLocaleLowerCase(), 'dom.className:', dom.className);
  737. return dom;
  738. }
  739.  
  740. /**
  741. * @description 获取方法配置
  742. * @param {string} [key='']
  743. * @param {*} [defaultOpt={ includedUrls: [] }]
  744. * @returns {*} {Object}
  745. **/
  746. function getSettingFromLocalStorage() {
  747. var _localStorage, _localStorage2;
  748. var fileName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  749. var defaultOpt = arguments.length > 1 ? arguments[1] : undefined;
  750. var mergedSettingOpt = _objectSpread({
  751. runType: '0',
  752. includedUrls: [],
  753. excludeUrls: []
  754. }, defaultOpt);
  755. var fullSettingKey = "enjoy_setting";
  756. var fullSettings = (_localStorage = localStorage) !== null && _localStorage !== void 0 && _localStorage[fullSettingKey] ? JSON.parse((_localStorage2 = localStorage) === null || _localStorage2 === void 0 ? void 0 : _localStorage2[fullSettingKey]) : {};
  757. var SETTING = _objectSpread(_objectSpread({}, mergedSettingOpt), fullSettings === null || fullSettings === void 0 ? void 0 : fullSettings[fileName]);
  758. fullSettings[fileName] = SETTING;
  759. fullSettings.runTypeDest = undefined;
  760. fullSettings.instructions = "\n\u4E00\u3001\u5339\u914D\u89C4\u5219\u4F18\u5148\u7EA7\uFF1Aruntype > * > excludedUrls > includedUrls\n\u4E8C\u3001runType\u662F\u9488\u5BF9\u5728\u5F53\u524D\u57DF\u540D\u89C4\u5219\uFF1A0(\u9ED8\u8BA4\u6267\u884C\u5339\u914D\u89C4\u5219)\uFF1B1(\u5F3A\u5236\u6267\u884C,\u5373\u8DF3\u8FC7\u5339\u914D\u89C4\u5219)\uFF1B2(\u4E0D\u6267\u884C)\n";
  761. localStorage[fullSettingKey] = JSON.stringify(fullSettings || {});
  762. return SETTING;
  763. }
  764.  
  765. /**
  766. * @description 是否执行该方法
  767. * @param {*} [settingOpt={}]
  768. * @returns {*} {Boolean}
  769. */
  770. function isExcutableBySetting() {
  771. var settingOpt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  772. var runType = settingOpt.runType,
  773. _settingOpt$excludeUr = settingOpt.excludeUrls,
  774. excludeUrls = _settingOpt$excludeUr === void 0 ? [] : _settingOpt$excludeUr,
  775. _settingOpt$includedU = settingOpt.includedUrls,
  776. includedUrls = _settingOpt$includedU === void 0 ? [] : _settingOpt$includedU;
  777. if (runType == '1') return true;
  778. if (runType == '2') return false;
  779. var HREF = location.href;
  780. if (excludeUrls !== null && excludeUrls !== void 0 && excludeUrls.length && isMatched(excludeUrls, HREF)) {
  781. return false;
  782. }
  783. if ((includedUrls === null || includedUrls === void 0 ? void 0 : includedUrls.length) === 0) return true;
  784. var findOne = isMatched(includedUrls, HREF);
  785. return !!findOne;
  786. }
  787.  
  788. /**
  789. * @description 是否不执行
  790. * @param {String} fileName
  791. * @param {Object} settingOpt { excludeUrls: [ ],feature:"feature",includedUrls: [ ],name: "name",runType: "0",}
  792. * @returns {Boolean}
  793. */
  794. function codeIsNotExcutable(fileName, settingOpt) {
  795. try {
  796. // logSettingOptWithColor()
  797. var setting = getSettingFromLocalStorage(fileName, settingOpt);
  798. return _objectSpread({
  799. notExcutable: !isExcutableBySetting(setting)
  800. }, setting);
  801. } catch (error) {
  802. // base64路径下,禁用storage
  803. console.error(error);
  804. return _objectSpread({
  805. notExcutable: true
  806. }, settingOpt);
  807. }
  808. }
  809.  
  810. /**
  811. * @description 彩色打印
  812. * @param {string} [key='enjoy_setting']
  813. */
  814. function logSettingOptWithColor(key) {
  815. var dataKey = 'is-log-of-enjoy';
  816. if (true) return;
  817. // if (document.body.getAttribute(dataKey)) return
  818. document.body.setAttribute(dataKey, '1');
  819.  
  820. // clearTimeout(window.EnjoyColorLogTimer || 0)
  821. window.EnjoyColorLogTimer = setTimeout(function () {
  822. var _key;
  823. (_key = key) !== null && _key !== void 0 ? _key : key = 'enjoy_setting';
  824. var SETTINGS = JSON.parse(localStorage[key] || '{}');
  825. console.log("%c\uD83D\uDC47 ".concat(key, " \u8BBE\u7F6E\u53C2\u6570\uFF1A"), 'background:#4e0ab780;color:#fff;', '\n', SETTINGS, "\n\nkeyNameList:", Object.keys(SETTINGS));
  826. console.log("%c\uD83D\uDC47\u81EA\u5B9A\u4E49\u914D\u7F6E\uFF0C\u4EE3\u7801\u5982\u4E0B\uFF1A", 'background:#4e0ab747;color:#fff;', "\n\u5F53\u524D\u57DF\u540D\u4E0B\u662F\u5426\u8FD0\u884C\u76F8\u5E94\u51FD\u6570,", "\n\u8BBE\u7F6ErunType(1\u3001\u5F3A\u5236\u8FD0\u884C\uFF1B2\u3001\u4E0D\u8FD0\u884C)\u3002", '\n\n', modifyRuntype.toString(), "\nmodifyRuntype('keyName',2)");
  827. }, 3 * 1000);
  828. }
  829. /**
  830. * @description 修改运行机制
  831. * @export
  832. * @param {string} keyName
  833. * @param {0|1|2} runType
  834. */
  835. function modifyRuntype(keyName, runType) {
  836. var keyOfSETTINGS = 'enjoy_setting';
  837. var SETTINGS = JSON.parse(localStorage[keyOfSETTINGS] || '{}');
  838. if (!SETTINGS[keyName]) return;
  839. SETTINGS[keyName].runType = runType || 2;
  840. localStorage[keyOfSETTINGS] = JSON.stringify(SETTINGS);
  841. }
  842.  
  843. /**
  844. * @description 查找特定条件的父级元素
  845. * @export
  846. * @param {Element} dom
  847. * @param {Function} callback
  848. * @param {Element} [defaultVal=document.documentElement]
  849. * @returns {Element}
  850. */
  851. function findParentElement(dom, callback) {
  852. var defaultVal = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : document.documentElement;
  853. if (!(dom instanceof HTMLElement)) {
  854. console.warn("\u67E5\u627E\u7279\u5B9A\u6761\u4EF6\u7684\u7236\u7EA7\u5143\u7D20\u51FD\u6570 findParentElement:\u53C2\u6570dom\u5FC5\u987B\u4E3Aelement\u5143\u7D20 ");
  855. return void 0;
  856. }
  857. while (dom) {
  858. if (callback(dom)) {
  859. break;
  860. }
  861. dom = dom.parentElement;
  862. }
  863. if (!dom || dom === document.body) {
  864. // 始终是 documentElement等同于window
  865. dom = defaultVal;
  866. }
  867. return dom;
  868. }
  869.  
  870. /** 原生横向滚动条 吸附 页面底部 */
  871. var StickyHorizontalNativeScrollBar = /*#__PURE__*/(/* unused pure expression or super */ null && (_createClass(function StickyHorizontalNativeScrollBar() {
  872. var _this = this;
  873. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  874. _classCallCheck(this, StickyHorizontalNativeScrollBar);
  875. /** 创建滚轴组件元素 */
  876. _defineProperty(this, "createScrollbar", function () {
  877. var style = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  878. if (_this.scrollbar) return _this.scrollbar;
  879. var timer = Date.now();
  880. _this.thumbId = "thumb".concat(timer);
  881. _this.scrollbarId = "scrollbar".concat(timer);
  882. _this.scrollbar = document.createElement('div');
  883. _this.scrollbar.setAttribute('id', _this.scrollbarId);
  884. _this.scrollbar.innerHTML = "\n\t\t\t<style>\n\t\t\t\t#".concat(_this.scrollbarId, " {\n\t\t\t\t\tposition: sticky;\n\t\t\t\t\twidth: 100%;\n\t\t\t\t\tbox-shadow: 0 15px 0 0 #fff;\n\t\t\t\t\tbottom: 8px;\n\t\t\t\t\tleft: 0;\n\t\t\t\t\theight: 17px;\n\t\t\t\t\toverflow-x: auto;\n\t\t\t\t\toverflow-y: hidden;\n\t\t\t\t\tmargin-top: -17px;\n\t\t\t\t\tz-index: 3;\n\t\t\t\t\t").concat(style, "\n\t\t\t\t}\n\t\t\t</style>\n\t\t\t<div id=\"").concat(_this.thumbId, "\" style=\"height: 1px;\"></div>\n\t\t");
  885. });
  886. /** 把滚轴组件元素插入目标元素的后面 */
  887. _defineProperty(this, "insertScrollbar", function (el) {
  888. _this.target = el;
  889. if (typeof el === 'string') {
  890. _this.target = document.querySelector(el);
  891. }
  892. if (!_this.target) throw Error('el Dom do not exit');
  893. _this.targetParentElement = document.querySelector(el).parentElement;
  894. if (!_this.targetParentElement.querySelector("#".concat(_this.scrollbarId))) {
  895. _this.targetParentElement.insertBefore(_this.scrollbar, _this.target.nextSibling);
  896. }
  897. return _this.target;
  898. });
  899. /** 设置 滚轴组件元素尺寸 */
  900. _defineProperty(this, "setScrollbarSize", throttle(function () {
  901. _this.scrollbar.style.width = _this.target.clientWidth + 'px';
  902. _this.scrollbar.querySelector("#".concat(_this.thumbId)).style.width = _this.target.scrollWidth + 'px';
  903. }, 100));
  904. /** 监听目标元素和滚轴元素的scroll和页面resize事件 */
  905. _defineProperty(this, "onEvent", function () {
  906. _this.target.addEventListener('scroll', _this.onScrollTarget);
  907. _this.scrollbar.addEventListener('scroll', _this.onScrollScrollbar);
  908. window.addEventListener('resize', _this.setScrollbarSize);
  909. });
  910. /** 移除事件 */
  911. _defineProperty(this, "removeEvent", function () {
  912. _this.target.removeEventListener('scroll', _this.onScrollTarget);
  913. _this.scrollbar.removeEventListener('scroll', _this.onScrollScrollbar);
  914. window.removeEventListener('resize', _this.setScrollbarSize);
  915. });
  916. _defineProperty(this, "onScrollTarget", throttle(function (e) {
  917. _this.scrollbar.scrollLeft = e.target.scrollLeft;
  918. }, 100));
  919. _defineProperty(this, "onScrollScrollbar", throttle(function (e) {
  920. _this.target.scrollLeft = e.target.scrollLeft;
  921. }, 100));
  922. var _el = options.el,
  923. _options$style = options.style,
  924. _style = _options$style === void 0 ? '' : _options$style;
  925. this.createScrollbar(_style);
  926. this.insertScrollbar(_el);
  927. this.setScrollbarSize();
  928. this.onEvent();
  929. })));
  930.  
  931. /** 插入横向滚动条 */
  932. var HorizontalScrollBar = /*#__PURE__*/(/* unused pure expression or super */ null && (function () {
  933. function HorizontalScrollBar() {
  934. var _this2 = this;
  935. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  936. _classCallCheck(this, HorizontalScrollBar);
  937. /** 创建滚轴组件元素 */
  938. _defineProperty(this, "createScrollbar", function (setStyle) {
  939. if (_this2.scrollbar) return _this2.scrollbar;
  940. var timer = Date.now();
  941. _this2.scrollbarId = "scrollbar".concat(timer);
  942. _this2.scrollbar = document.createElement('div');
  943. _this2.scrollbar.setAttribute('data-part', 'scrollbar');
  944. _this2.scrollbar.setAttribute('id', _this2.scrollbarId);
  945. _this2.scrollbar.innerHTML = "\n\t\t".concat(setStyle(_this2.scrollbarId) || _this2.setDefaultStyle(_this2.scrollbarId), "\n\t\t<div data-part=\"thumb\"></div>\n\t\t");
  946. });
  947. /** 把滚轴组件元素插入目标元素的后面 */
  948. _defineProperty(this, "insertScrollbar", function (el) {
  949. _this2.target = el;
  950. if (typeof el === 'string') {
  951. _this2.target = document.querySelector(el);
  952. }
  953. if (!_this2.target) throw Error('el Dom do not exit');
  954. _this2.targetParentElement = document.querySelector(el).parentElement;
  955. if (!_this2.targetParentElement.querySelector("#".concat(_this2.scrollbarId))) {
  956. _this2.targetParentElement.insertBefore(_this2.scrollbar, _this2.target.nextSibling);
  957. }
  958. return _this2.target;
  959. });
  960. /** 根据目标元素 设置 滚轴组件元素尺寸 */
  961. _defineProperty(this, "setScrollbarSize", function () {
  962. _this2.scrollbar.style.width = _this2.target.clientWidth + 'px';
  963. _this2.thumb = _this2.scrollbar.querySelector('[data-part="thumb"]');
  964. _this2.thumb.style.width = _this2.scrollbar.clientWidth * _this2.target.clientWidth / _this2.target.scrollWidth + 'px';
  965. _this2.offsetMax = _this2.scrollbar.clientWidth - _this2.thumb.clientWidth;
  966. _this2.rate = (_this2.target.scrollWidth - _this2.target.clientWidth) / _this2.offsetMax;
  967. });
  968. /** */
  969. _defineProperty(this, "onMouseDownOfThumb", function (e) {
  970. console.log("mousedown => %O ");
  971. _this2.prePageX = e.pageX;
  972. _this2.isMousedown = true;
  973. });
  974. /** */
  975. _defineProperty(this, "onMouseUpOfWindow", function (e) {
  976. _this2.isMousedown = false;
  977. });
  978. /** */
  979. _defineProperty(this, "requestAnimationFrameCallback", function (offsetLeft) {
  980. _this2.thumb.style.left = offsetLeft + 'px';
  981. _this2.target.scrollLeft = offsetLeft * _this2.rate;
  982. });
  983. /** */
  984. _defineProperty(this, "onMousemoveOfWindow", function (e) {
  985. if (_this2.isMousedown) {
  986. var offsetLeft = Number(_this2.thumb.style.left.replace('px', '')) + Number(e.pageX - _this2.prePageX);
  987. offsetLeft = Math.max(0, offsetLeft);
  988. offsetLeft = Math.min(offsetLeft, _this2.offsetMax);
  989. _this2.requestAnimationFrameCallback(offsetLeft);
  990. _this2.prePageX = e.pageX;
  991. }
  992. });
  993. /** 监听目标元素和滚轴元素的scroll和页面resize事件 */
  994. _defineProperty(this, "onEvent", function () {
  995. _this2.thumb.addEventListener('mousedown', _this2.onMouseDownOfThumb);
  996. window.addEventListener('mouseup', _this2.onMouseUpOfWindow);
  997. window.addEventListener('mousemove', _this2.onMousemoveOfWindow);
  998. window.addEventListener('resize', _this2.setScrollbarSize);
  999. });
  1000. /** 移除事件 */
  1001. _defineProperty(this, "removeEvent", function () {
  1002. _this2.thumb.removeEventListener('mousedown', _this2.onMouseDownOfThumb);
  1003. window.removeEventListener('mouseup', _this2.onMouseUpOfWindow);
  1004. window.removeEventListener('mousemove', _this2.onMousemoveOfWindow);
  1005. window.removeEventListener('resize', _this2.setScrollbarSize);
  1006. });
  1007. var _el2 = options.el,
  1008. _options$setStyle = options.setStyle,
  1009. _setStyle = _options$setStyle === void 0 ? function () {
  1010. return null;
  1011. } : _options$setStyle;
  1012. this.createScrollbar(_setStyle);
  1013. this.insertScrollbar(_el2);
  1014. this.setScrollbarSize();
  1015. this.onEvent();
  1016. }
  1017. _createClass(HorizontalScrollBar, [{
  1018. key: "setDefaultStyle",
  1019. value: function setDefaultStyle(scrollbarId) {
  1020. return "\n\t\t<style>\n\t\t\t#".concat(scrollbarId, " {\n\t\t\t\theight: 17px;\n\t\t\t\tbackground-color: #f1f1f1;\n\t\t\t\tposition: relative;\n\t\t\t}\n\t\t\t#").concat(scrollbarId, ">[data-part=\"thumb\"] {\n\t\t\t\theight: 100%;\n\t\t\t\tbackground-color: #c1c1c1;\n\t\t\t\tposition: absolute;\n\t\t\t}\n\t\t\t#").concat(scrollbarId, ">[data-part=\"thumb\"]:active {\n\t\t\t\tbackground-color: #787878;\n\t\t\t}\n\t\t</style>\n\t");
  1021. }
  1022. }]);
  1023. return HorizontalScrollBar;
  1024. }()));
  1025.  
  1026. /** 持久化数据状态 */
  1027. var PersistentStorage = /*#__PURE__*/(/* unused pure expression or super */ null && (function () {
  1028. function PersistentStorage() {
  1029. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1030. _classCallCheck(this, PersistentStorage);
  1031. var _options$valKey = options.valKey,
  1032. valKey = _options$valKey === void 0 ? 'valKey' : _options$valKey,
  1033. _options$storageType = options.storageType,
  1034. storageType = _options$storageType === void 0 ? 'sessionStorage' : _options$storageType;
  1035. this.valKey = valKey;
  1036. this.storageType = storageType;
  1037. }
  1038. _createClass(PersistentStorage, [{
  1039. key: "write",
  1040. value: function write(val) {
  1041. val = _typeof(val) === 'object' ? JSON.stringify(val) : val;
  1042. val && window[this.storageType].setItem(this.valKey, val);
  1043. }
  1044. }, {
  1045. key: "read",
  1046. value: function read() {
  1047. var val = window[this.storageType].getItem(this.valKey);
  1048. return val ? JSON.parse(val) : val;
  1049. }
  1050. }, {
  1051. key: "remove",
  1052. value: function remove() {
  1053. window[this.storageType].removeItem(this.valKey);
  1054. }
  1055. }]);
  1056. return PersistentStorage;
  1057. }()));
  1058.  
  1059. /**
  1060. * @description 节流函数
  1061. * @export
  1062. * @param {Function} func
  1063. * @param {Number} [wait=100]
  1064. * @returns {Function}
  1065. */
  1066. function throttle(func) {
  1067. var wait = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 100;
  1068. var isDoing = false;
  1069. return function () {
  1070. if (isDoing) return;
  1071. isDoing = true;
  1072. func.apply(void 0, arguments);
  1073. setTimeout(function () {
  1074. isDoing = false;
  1075. }, wait);
  1076. };
  1077. }
  1078.  
  1079. /**
  1080. * @description 防抖函数
  1081. * @export
  1082. * @param {Function} func
  1083. * @param {Number} [wait=100]
  1084. * @param {'end'|'front'} type
  1085. * @returns {Function}
  1086. */
  1087. function debounce(func) {
  1088. var wait = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 100;
  1089. var type = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'end';
  1090. var timer = 0;
  1091. return function () {
  1092. clearTimeout(timer);
  1093. for (var _len = arguments.length, rest = new Array(_len), _key2 = 0; _key2 < _len; _key2++) {
  1094. rest[_key2] = arguments[_key2];
  1095. }
  1096. timer = setTimeout.apply(void 0, [func, wait].concat(rest));
  1097. };
  1098. }
  1099.  
  1100. /**
  1101. * @description 等候
  1102. * @export
  1103. * @param {number} [interval=17]
  1104. * @returns {Promise}
  1105. */
  1106. function awaitTime() {
  1107. var interval = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 17;
  1108. return new Promise(function (resolve) {
  1109. setTimeout(resolve, interval);
  1110. });
  1111. }
  1112.  
  1113. /**
  1114. * @description 打开已在窗口仅激活,不刷新
  1115. * @export
  1116. * @class OpenPlus
  1117. */
  1118. var OpenPlus = /*#__PURE__*/(/* unused pure expression or super */ null && (_createClass(function OpenPlus() {
  1119. var _this3 = this;
  1120. var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1121. _classCallCheck(this, OpenPlus);
  1122. _defineProperty(this, "openPre", function () {
  1123. var callback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {
  1124. return null;
  1125. };
  1126. for (var _len2 = arguments.length, rest = new Array(_len2 > 1 ? _len2 - 1 : 0), _key3 = 1; _key3 < _len2; _key3++) {
  1127. rest[_key3 - 1] = arguments[_key3];
  1128. }
  1129. var win = _this3.open.apply(_this3, rest);
  1130. callback === null || callback === void 0 || callback();
  1131. return win;
  1132. });
  1133. _defineProperty(this, "open", function (href) {
  1134. var willOpenTab = _this3.win.tabsCacheOfOpenPlus[href];
  1135. for (var _len3 = arguments.length, rest = new Array(_len3 > 1 ? _len3 - 1 : 0), _key4 = 1; _key4 < _len3; _key4++) {
  1136. rest[_key4 - 1] = arguments[_key4];
  1137. }
  1138. if (willOpenTab === undefined) {
  1139. var _this3$win;
  1140. willOpenTab = (_this3$win = _this3.win).open.apply(_this3$win, [href].concat(rest));
  1141. _this3.win.nextOfOpenPlus.forEach(function (item) {
  1142. return item === null || item === void 0 ? void 0 : item();
  1143. });
  1144. return _this3.win.tabsCacheOfOpenPlus[href] = willOpenTab;
  1145. } else if (willOpenTab.closed === true) {
  1146. var _this3$win2;
  1147. return (_this3$win2 = _this3.win).open.apply(_this3$win2, [href].concat(rest));
  1148. } else if (willOpenTab.closed === false) {
  1149. willOpenTab.focus();
  1150. return willOpenTab;
  1151. }
  1152. });
  1153. var _opt$win = opt.win,
  1154. _win = _opt$win === void 0 ? window : _opt$win,
  1155. _opt$next = opt.next,
  1156. next = _opt$next === void 0 ? function () {
  1157. return null;
  1158. } : _opt$next;
  1159. this.win = _win;
  1160. this.win.tabsCacheOfOpenPlus = this.win.tabsCacheOfOpenPlus || {};
  1161. this.win.nextOfOpenPlus = this.win.nextOfOpenPlus || [];
  1162. this.win.nextOfOpenPlus.push(next);
  1163. })));
  1164. function modifyStorage() {
  1165. var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1166. var _opt$storageName = opt.storageName,
  1167. storageName = _opt$storageName === void 0 ? 'localStorage' : _opt$storageName,
  1168. chainKeys = opt.chainKeys,
  1169. _opt$doType = opt.doType,
  1170. doType = _opt$doType === void 0 ? 'get' : _opt$doType,
  1171. val = opt.val,
  1172. _opt$prefix = opt.prefix,
  1173. prefix = _opt$prefix === void 0 ? 'enjoy_setting' : _opt$prefix;
  1174. if (prefix) {
  1175. chainKeys = "".concat(prefix, ".").concat(chainKeys);
  1176. }
  1177. chainKeys = chainKeys.split('.');
  1178. var keyOfLevel1 = chainKeys.shift();
  1179. var keyOfEnd = chainKeys.pop();
  1180. var isObject = true;
  1181. var storage = null;
  1182. try {
  1183. storage = JSON.parse(window[storageName][keyOfLevel1]);
  1184. } catch (error) {
  1185. isObject = false;
  1186. storage = window[storageName][keyOfLevel1];
  1187. console.error("".concat(storageName, " ").concat(chainKeys, " \u4E00\u7EA7\u5C5E\u6027\u503C\u4E3A\u57FA\u672C\u7C7B\u578B"));
  1188. return;
  1189. }
  1190. var obj = storage;
  1191. chainKeys.forEach(function (key) {
  1192. obj = obj[key];
  1193. });
  1194. if (doType === 'set') {
  1195. obj[keyOfEnd] = val;
  1196. window[storageName][keyOfLevel1] = JSON.stringify(storage);
  1197. } else {
  1198. return obj[keyOfEnd];
  1199. }
  1200. }
  1201.  
  1202. /**
  1203. * @description 简便的Storage SimpleStorage({ prefix: 'prefix' })
  1204. * @param {*} opt
  1205. */
  1206. function storagex() {
  1207. var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1208. var Storage = /*#__PURE__*/_createClass(function Storage() {
  1209. var _this4 = this;
  1210. var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1211. _classCallCheck(this, Storage);
  1212. _defineProperty(this, "storage", null);
  1213. _defineProperty(this, "setItem", function (keys, val) {
  1214. _this4.formatChainKeys(keys);
  1215. _this4.getFirstLevelVal();
  1216. _this4.chainVal('set', val);
  1217. return void 0;
  1218. });
  1219. _defineProperty(this, "getItem", function (keys) {
  1220. _this4.formatChainKeys(keys);
  1221. _this4.getFirstLevelVal();
  1222. return _this4.chainVal('get');
  1223. });
  1224. _defineProperty(this, "removeItem", function (keys) {
  1225. _this4.formatChainKeys(keys);
  1226. _this4.getFirstLevelVal();
  1227. return _this4.chainVal('remove');
  1228. });
  1229. _defineProperty(this, "clear", function () {
  1230. var keysWithPrefix = Object.keys(_this4.storage).filter(function (item) {
  1231. return item.startsWith(_this4.prefix);
  1232. });
  1233. keysWithPrefix.forEach(function (key) {
  1234. return _this4.storage.removeItem(key);
  1235. });
  1236. return void 0;
  1237. });
  1238. _defineProperty(this, "getFirstLevelVal", function () {
  1239. var state = _this4.storage[_this4.prefix + _this4.startKey];
  1240. try {
  1241. state = JSON.parse(state);
  1242. } catch (error) {}
  1243. _this4.cache = state;
  1244. return state;
  1245. });
  1246. _defineProperty(this, "formatChainKeys", function (keys) {
  1247. keys = keys.split('.');
  1248. _this4.startKey = keys.shift();
  1249. _this4.endKey = keys.pop();
  1250. _this4.middlekeys = keys;
  1251. return keys;
  1252. });
  1253. _defineProperty(this, "chainVal", function (doType, val) {
  1254. var obj = _this4.cache;
  1255. _this4.middlekeys.forEach(function (key) {
  1256. obj = obj[key];
  1257. });
  1258. if (doType === 'set') {
  1259. if (_this4.endKey) {
  1260. obj[_this4.endKey] = val;
  1261. } else {
  1262. _this4.cache = val;
  1263. }
  1264. _this4.storage.setItem(_this4.prefix + _this4.startKey, _this4.isObject(_this4.cache) ? JSON.stringify(_this4.cache) : _this4.cache);
  1265. } else if (doType === 'get') {
  1266. if (_this4.endKey) {
  1267. return obj[_this4.endKey];
  1268. }
  1269. return _this4.cache;
  1270. } else if (doType === 'remove') {
  1271. if (_this4.endKey) {
  1272. var isDeleted = delete obj[_this4.endKey];
  1273. isDeleted && _this4.setItem(_this4.startKey, _this4.cache);
  1274. return isDeleted;
  1275. }
  1276. _this4.storage.removeItem(_this4.prefix + _this4.startKey);
  1277. }
  1278. });
  1279. _defineProperty(this, "isObject", function (value) {
  1280. var type = _typeof(value);
  1281. return value != null && (type === 'object' || type === 'function');
  1282. });
  1283. var prefix = opt.prefix,
  1284. storage = opt.storage;
  1285. this.prefix = prefix ? "".concat(prefix, "_") : '';
  1286. this.storage = storage;
  1287. });
  1288. if (opt.storage && sessionStorage.__proto__.setItemX) return opt.storage;
  1289. var storage = new Storage(opt);
  1290. if (opt.storage) return storage;
  1291. if (sessionStorage.__proto__.setItemX) return;
  1292. sessionStorage.__proto__.setItemX = function (key, val) {
  1293. storage.storage = this;
  1294. storage.setItem(key, val);
  1295. };
  1296. sessionStorage.__proto__.getItemX = function (key) {
  1297. storage.storage = this;
  1298. return storage.getItem(key);
  1299. };
  1300. sessionStorage.__proto__.removeItemX = function (key) {
  1301. storage.storage = this;
  1302. return storage.removeItem(key);
  1303. };
  1304. sessionStorage.__proto__.clearX = function () {
  1305. storage.storage = this;
  1306. return storage.clear();
  1307. };
  1308. }
  1309.  
  1310. /**
  1311. * @description 处理标记内容
  1312. * @param {*} opt
  1313. * @returns {*}
  1314. */
  1315. function operateComment(opt) {
  1316. var _opt$text = opt.text,
  1317. text = _opt$text === void 0 ? '' : _opt$text,
  1318. _opt$S = opt.S,
  1319. S = _opt$S === void 0 ? '/*' : _opt$S,
  1320. _opt$E = opt.E,
  1321. E = _opt$E === void 0 ? '*/' : _opt$E,
  1322. _opt$modify = opt.modify,
  1323. modify = _opt$modify === void 0 ? function (val) {
  1324. return val;
  1325. } : _opt$modify;
  1326. var stack = [];
  1327. var index = text.indexOf(S);
  1328. if (index === -1) return text;
  1329. while (index <= text.length - 1) {
  1330. if (text[index] + text[index + 1] == S) {
  1331. stack.push(index);
  1332. } else if (text[index] + text[index + 1] == E) {
  1333. var latestIndex = stack.pop();
  1334. if (latestIndex !== undefined) {
  1335. var middle = modify(text.slice(latestIndex + S.length, index));
  1336. text = text.slice(0, latestIndex) + middle + text.slice(index + S.length);
  1337. index = latestIndex + middle.length;
  1338. }
  1339. }
  1340. index++;
  1341. }
  1342. return text;
  1343. }
  1344.  
  1345. /** 添加动画函数 */
  1346. function addAnimation(dom, className) {
  1347. if (!dom || !className) return;
  1348. if (!dom.animationend) {
  1349. dom.animationend = function () {
  1350. dom.classList.remove(className);
  1351. };
  1352. }
  1353. dom.removeEventListener('animationend', dom.animationend);
  1354. dom.addEventListener('animationend', dom.animationend);
  1355. dom.classList.add(className);
  1356. }
  1357.  
  1358. // 判断当前浏览器运行环境
  1359. function getBrowserEnv() {
  1360. var userAgent = window.navigator.userAgent.toLowerCase();
  1361. var agents = ['Android', 'iPhone', 'SymbianOS', 'Windows Phone', 'iPad', 'iPod'];
  1362. // 是否为支付宝环境
  1363. var isAliPay = /alipayclient/.test(userAgent);
  1364. // 是否为淘宝环境
  1365. var isTaoBao = /windvane/.test(userAgent);
  1366. // 是否为企业微信环境
  1367. var isWxWork = /wxwork/.test(userAgent);
  1368. // 是否为微信环境
  1369. var isWeChat = /micromessenger/.test(userAgent) && !isWxWork;
  1370. // 是否为移动端
  1371. var isPhone = agents.some(function (x) {
  1372. return new RegExp(x.toLocaleLowerCase()).test(userAgent);
  1373. });
  1374. return {
  1375. isAliPay: isAliPay,
  1376. isTaoBao: isTaoBao,
  1377. isWxWork: isWxWork,
  1378. isWeChat: isWeChat,
  1379. isPhone: isPhone
  1380. };
  1381. }
  1382. var RegisterDbltouchEvent = /*#__PURE__*/(/* unused pure expression or super */ null && (function () {
  1383. function RegisterDbltouchEvent(el, fn) {
  1384. _classCallCheck(this, RegisterDbltouchEvent);
  1385. this.el = el || window;
  1386. this.callback = fn;
  1387. this.timer = null;
  1388. this.prevPosition = {};
  1389. this.isWaiting = false;
  1390.  
  1391. // 注册click事件,注意this指向
  1392. this.el.addEventListener('click', this.handleClick.bind(this), true);
  1393. }
  1394. _createClass(RegisterDbltouchEvent, [{
  1395. key: "handleClick",
  1396. value: function handleClick(evt) {
  1397. var _this5 = this;
  1398. var pageX = evt.pageX;
  1399. var pageY = evt.pageY;
  1400. if (this.timer) {
  1401. clearTimeout(this.timer);
  1402. this.timer = null;
  1403. }
  1404. if (!evt.isTrusted) {
  1405. return;
  1406. }
  1407. if (this.isWaiting) {
  1408. this.isWaiting = false;
  1409. var diffX = Math.abs(pageX - this.prevPosition.pageX);
  1410. var diffY = Math.abs(pageY - this.prevPosition.pageY);
  1411. // 如果满足位移小于10,则是双击
  1412. if (diffX <= 10 && diffY <= 10) {
  1413. // 取消当前事件传递,并派发1个自定义双击事件
  1414. evt.stopPropagation();
  1415. evt.target.dispatchEvent(new PointerEvent('dbltouch', {
  1416. cancelable: false,
  1417. bubbles: true
  1418. }));
  1419. // 也可以采用回调函数的方式
  1420. this.callback && this.callback(evt);
  1421. }
  1422. } else {
  1423. this.prevPostion = {
  1424. pageX: pageX,
  1425. pageY: pageY
  1426. };
  1427. // 阻止冒泡,不让事件继续传播
  1428. evt.stopPropagation();
  1429. // 开始等待第2次点击
  1430. this.isWaiting = true;
  1431. // 设置200ms倒计时,200ms后重新派发当前事件
  1432. this.timer = setTimeout(function () {
  1433. _this5.isWaiting = false;
  1434. evt.target.dispatchEvent(evt);
  1435. }, 200);
  1436. }
  1437. }
  1438. }]);
  1439. return RegisterDbltouchEvent;
  1440. }()));
  1441. /**移动端 双击 */
  1442. function addDbltouch() {
  1443. var dom = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window;
  1444. var handle = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (event) {
  1445. console.log('双击', event, Date.now());
  1446. };
  1447. var preTimestamp = 0;
  1448. dom.addEventListener('click', function (event) {
  1449. var currentTimestamp = Date.now();
  1450. if (currentTimestamp - preTimestamp < 200) handle(event);
  1451. preTimestamp = currentTimestamp;
  1452. });
  1453. }
  1454.  
  1455. /**
  1456. * @description 获取dom
  1457. * @export
  1458. * @param {*} element
  1459. * @param {*} selector
  1460. * @param {number} [timeout=80]
  1461. * @param {boolean} [isAlways=true]
  1462. * @returns {*}
  1463. */
  1464. function getElement(_x, _x2) {
  1465. return (_getElement = _getElement || _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(element, selector) {
  1466. var timeout,
  1467. isAlways,
  1468. count,
  1469. _args = arguments;
  1470. return _regeneratorRuntime.wrap(function _callee$(_context) {
  1471. while (1) switch (_context.prev = _context.next) {
  1472. case 0:
  1473. timeout = _args.length > 2 && _args[2] !== undefined ? _args[2] : 80;
  1474. isAlways = _args.length > 3 && _args[3] !== undefined ? _args[3] : true;
  1475. count = 0;
  1476. return _context.abrupt("return", new Promise(function (resolve, reject) {
  1477. var timeId = setInterval(function () {
  1478. if (timeout && count++ >= timeout) {
  1479. clearInterval(timeId);
  1480. console.warn('[utils.getElement] Element is not find.' + ' selector: ' + selector);
  1481. // 保持原生逻辑,即未找到时,返回null,便于之后执行埋点,比如错误上报
  1482. return resolve(null);
  1483. }
  1484. var node = element.querySelector(selector);
  1485. if (node) {
  1486. //node 总是返回 或 显示状态条件下,找到后即刻返回
  1487. if (isAlways || node.offsetParent) {
  1488. resolve(node);
  1489. clearInterval(timeId);
  1490. }
  1491. }
  1492. }, 200);
  1493. }));
  1494. case 4:
  1495. case "end":
  1496. return _context.stop();
  1497. }
  1498. }, _callee);
  1499. }))).apply(this, arguments);
  1500. }
  1501. ;// CONCATENATED MODULE: ./src/YapiCopy.js
  1502.  
  1503.  
  1504.  
  1505.  
  1506. run();
  1507. function run() {
  1508. var _expandCell, _cellecteParamsTxt;
  1509. createBtn();
  1510. window.cellecteParamsTxt = cellecteParamsTxt;
  1511. function createBtn() {
  1512. var _ref;
  1513. var btnDom = createElement('div', {
  1514. el: 'body',
  1515. insertType: 'appendChild',
  1516. innerHTML: "\n\t\t<div title='api \u4E00\u952E\u590D\u5236'>\uD83D\uDC26</div>\n\t\t<div title='params \u4E00\u952E\u590D\u5236'>\uD83D\uDC18</div>\n\t\t<div title='response \u4E00\u952E\u590D\u5236'>\uD83D\uDC1F</div>\n\t\t<style>\n\t\t#enjoy_YapiCopy_div_ {\n\t\t\twidth: 24px;\n\t\t\theight: 105px;\n\t\t\topacity: 0.4;\n\t\t\tbackground: #9bab9e;\n\t\t\tfont-weight: 800;\n\t\t\tborder-radius:0 5px 5px 0;\n\t\t\tcursor: pointer;\n\t\t\tcolor: #fff;\n\t\t\ttransition: all 0.2s;\n\t\t\tfont-size: 18px;\n\t\t\tposition: fixed;\n\t\t\tleft: 0;\n\t\t\ttop: 50vh;\n\t\t\tfont-size:12px;\n\t\t\tz-index: 1;\n\t\t}\n\n\t\t#enjoy_YapiCopy_div_:hover {\n\t\t\topacity: 0.5;\n\t\t\twidth: 35px;\n\t\t\theight: 105px;\n\t\t\tfont-size:16px;\n\t\t}\n\n\t\t#enjoy_YapiCopy_div_>div {\n\t\theight: 35px;\n\t\tline-height: 35px;\n\t\ttext-align: center;\n\t\tborder-radius:0 5px 5px 0;\n\t\ttransition: all 0.1s;\n\t\t}\n\n\t\t#enjoy_YapiCopy_div_>div:hover {\n\t\t\tbackground-color: #333333;\n\t\t\tfont-size: 25px;\n\t\t}\n\t\t.caseContainer .ant-table-thead th{\n\t\t\tcolor:#333;\n\t\t\tfont-weight:600;\n\t\t}\n\t\tbody,\n\t\t.ant-table{\n\t\t\tcolor:#333;\n\t\t}\n\n\t\t/* \u907F\u514D\u7531\u4E8E\u5D4C\u5957\u591A\u5C42\u5BFC\u81F4,\u7B2C\u4E00\u5217\u5B57\u6BB5\u6362\u884C\u663E\u793A */\n\t\ttable tr td:first-child {\n\t\t\ttext-wrap: nowrap !important;\n\t\t}\n\n\t\t.ant-breadcrumb-link {\n\t\t\tfont-size: 28px;\n\t\t\tfont-weight: 600;\n\t\t\ttext-shadow: 3px -3px 0px #6f6f6f;\n\t }\n\t\t/* \u5438\u9876 */\n\t\t.header-box.m-header {\n\t\t\tposition: sticky;\n\t\t\ttop: -10px;\n\t\t\tz-index: 1;\n\t\t}\n </style>\n "
  1517. });
  1518. btnDom.addEventListener('click', function (_x) {
  1519. return (_ref = _ref || asyncToGenerator_asyncToGenerator( /*#__PURE__*/regenerator_default().mark(function _callee(e) {
  1520. return regenerator_default().wrap(function _callee$(_context) {
  1521. while (1) switch (_context.prev = _context.next) {
  1522. case 0:
  1523. if (!(e.target.title === 'api 一键复制')) {
  1524. _context.next = 4;
  1525. break;
  1526. }
  1527. doCopy(cellecteApiTxt());
  1528. _context.next = 17;
  1529. break;
  1530. case 4:
  1531. if (!(e.target.title === 'params 一键复制')) {
  1532. _context.next = 12;
  1533. break;
  1534. }
  1535. _context.t0 = doCopy;
  1536. _context.next = 8;
  1537. return cellecteParamsTxt('请求参数结构', '.interface-title ~.colHeader + div table');
  1538. case 8:
  1539. _context.t1 = _context.sent;
  1540. (0, _context.t0)(_context.t1);
  1541. _context.next = 17;
  1542. break;
  1543. case 12:
  1544. _context.t2 = doCopy;
  1545. _context.next = 15;
  1546. return cellecteParamsTxt('返回数据结构', '.interface-title + div.ant-table-wrapper table');
  1547. case 15:
  1548. _context.t3 = _context.sent;
  1549. (0, _context.t2)(_context.t3);
  1550. case 17:
  1551. case "end":
  1552. return _context.stop();
  1553. }
  1554. }, _callee);
  1555. }))).apply(this, arguments);
  1556. });
  1557. }
  1558. function cellecteApiTxt() {
  1559. var _values$, _values$2;
  1560. var container = document.querySelector('.panel-view');
  1561. if (!container) return '未获取到dom';
  1562. var desc = container.querySelector('.colName').innerText || '';
  1563. var dirName = container.querySelector('.remark>.colValue').innerText || '';
  1564. var pageUrl = location.href;
  1565. var values = container.querySelectorAll('.colValue');
  1566. var method = ((_values$ = values[3]) === null || _values$ === void 0 ? void 0 : _values$.innerText.toLocaleLowerCase()) || '';
  1567. var apiUrl = ((_values$2 = values[4]) === null || _values$2 === void 0 ? void 0 : _values$2.innerText) || '';
  1568. var templateDesc = "\n * @param {Object} params";
  1569. var templateParams = "params, ";
  1570. var templateParams2 = "{ params, ...config }";
  1571. if (method === 'post') {
  1572. templateDesc = "\n * @param {Object} data";
  1573. templateParams = "data, ";
  1574. templateParams2 = " data, { ...config }";
  1575. }
  1576. templateDesc = '';
  1577. var paramsDesc = "\n\t\t* @param {Object} config\n\t\t* @returns {Promise<ResponseData>}";
  1578. paramsDesc = '';
  1579. var template = "\n/**\n * ".concat(dirName, " / ").concat(desc).concat(templateDesc).concat(paramsDesc, "\n * @see ").concat(decodeURIComponent(pageUrl), "\n */\nexport function ").concat(apiUrl.replace(/^.*\//, ''), "(").concat(templateParams, "config) {\n return http.").concat(method, "('").concat(apiUrl, "',").concat(templateParams2, ")\n}\n");
  1580. console.log(template);
  1581. return template;
  1582. }
  1583.  
  1584. /** 展开折叠项,直至没有可折叠项 */
  1585. function expandCell(_x2) {
  1586. return (_expandCell = _expandCell || asyncToGenerator_asyncToGenerator( /*#__PURE__*/regenerator_default().mark(function _callee2(tableDom) {
  1587. var collapsed;
  1588. return regenerator_default().wrap(function _callee2$(_context2) {
  1589. while (1) switch (_context2.prev = _context2.next) {
  1590. case 0:
  1591. collapsed = _toConsumableArray(tableDom.querySelectorAll('.ant-table-row-collapsed'));
  1592. case 1:
  1593. if (!collapsed.length) {
  1594. _context2.next = 7;
  1595. break;
  1596. }
  1597. _context2.next = 4;
  1598. return new Promise(function (resolve) {
  1599. collapsed.shift().click();
  1600. setTimeout(resolve, 60);
  1601. });
  1602. case 4:
  1603. collapsed = _toConsumableArray(tableDom.querySelectorAll('.ant-table-row-collapsed'));
  1604. _context2.next = 1;
  1605. break;
  1606. case 7:
  1607. case "end":
  1608. return _context2.stop();
  1609. }
  1610. }, _callee2);
  1611. }))).apply(this, arguments);
  1612. }
  1613. function cellecteParamsTxt() {
  1614. return (_cellecteParamsTxt = _cellecteParamsTxt || asyncToGenerator_asyncToGenerator( /*#__PURE__*/regenerator_default().mark(function _callee3() {
  1615. var desc,
  1616. selector,
  1617. tableDom,
  1618. keys,
  1619. values,
  1620. remarks,
  1621. maps,
  1622. temp,
  1623. tagStack,
  1624. template,
  1625. _args3 = arguments;
  1626. return regenerator_default().wrap(function _callee3$(_context3) {
  1627. while (1) switch (_context3.prev = _context3.next) {
  1628. case 0:
  1629. desc = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : '参数说明';
  1630. selector = _args3.length > 1 ? _args3[1] : undefined;
  1631. tableDom = document.querySelector(selector);
  1632. if (tableDom) {
  1633. _context3.next = 5;
  1634. break;
  1635. }
  1636. return _context3.abrupt("return", '未获取到dom');
  1637. case 5:
  1638. _context3.next = 7;
  1639. return expandCell(tableDom);
  1640. case 7:
  1641. keys = getCellContent(tableDom, 1);
  1642. values = getCellContent(tableDom, 2);
  1643. remarks = getCellContent(tableDom, 5);
  1644. maps = {
  1645. integer: '0',
  1646. string: "''",
  1647. "boolean": 'true',
  1648. object: '{}',
  1649. 'integer []': '[]',
  1650. 'string []': '[]',
  1651. 'object []': '[{}]'
  1652. };
  1653. temp = '\n';
  1654. tagStack = [];
  1655. keys.forEach(function (item, idx) {
  1656. if (!item) return;
  1657. var valStr = maps[values[idx]];
  1658. if (item.includes('<<')) {
  1659. // 属性名称的处理
  1660. var valStart = '';
  1661. if (values[idx].includes('object') || values[idx].includes('[]')) {
  1662. var _item$match, _keys;
  1663. // 属性值为 对象或数组类型的处理
  1664.  
  1665. var currentPaddingLeft = Number((_item$match = item.match(/(\d+)px<</)) === null || _item$match === void 0 ? void 0 : _item$match[1]);
  1666. var preItemPaddingLeft = Number((_keys = keys[idx - 1]) === null || _keys === void 0 || (_keys = _keys.match(/(\d+)px<</)) === null || _keys === void 0 ? void 0 : _keys[1]);
  1667. var str = '';
  1668. if ((currentPaddingLeft - preItemPaddingLeft) / 20 < 0) {
  1669. for (var _idx = 0, len = Math.abs((currentPaddingLeft - preItemPaddingLeft) / 20); _idx < len; _idx++) {
  1670. str = str + tagStack.pop() || '';
  1671. }
  1672. }
  1673. valStart = valStr.slice(0, valStr.length / 2);
  1674. tagStack.push(valStr.slice(-1 * valStr.length / 2) + ',\n');
  1675. valStr = valStart ? valStart : valStr + ',';
  1676. // 备注放在属性前,同时,置空属性后的注释
  1677. item = "".concat(str).concat(getRemarkWithoutExtraSpan(remarks[idx], true)).concat(item.replace(/(\d+px<<)/g, ''));
  1678. remarks[idx] = ''; //
  1679. } else {
  1680. var _item$match2, _keys2;
  1681. var _currentPaddingLeft = Number((_item$match2 = item.match(/(\d+)px<</)) === null || _item$match2 === void 0 ? void 0 : _item$match2[1]);
  1682. var _preItemPaddingLeft = Number((_keys2 = keys[idx - 1]) === null || _keys2 === void 0 || (_keys2 = _keys2.match(/(\d+)px<</)) === null || _keys2 === void 0 ? void 0 : _keys2[1]);
  1683. if (valStr === '0') {
  1684. var _remarks$idx$match;
  1685. // 数字类型,从备注中获取默认值
  1686. valStr = ((_remarks$idx$match = remarks[idx].match(/(\d+)/g)) === null || _remarks$idx$match === void 0 ? void 0 : _remarks$idx$match[0]) || 0;
  1687. } else if (valStr === "''") {
  1688. var _remarks$idx;
  1689. // 字符串类型,从备注中获取默认值
  1690. // valStr = valStr
  1691.  
  1692. valStr = "'".concat((_remarks$idx = remarks[idx]) === null || _remarks$idx === void 0 ? void 0 : _remarks$idx.split('的').filter(function (str) {
  1693. return str.trim();
  1694. }).slice(-1), "'");
  1695.  
  1696. // valStr = `'${remarks[idx]?.split('的').filter(str=>str.trim()).slice(-1)} - ${keys[idx].replace(/(\d+px<<)/g, '')}'`
  1697. }
  1698.  
  1699. if ((_currentPaddingLeft - _preItemPaddingLeft) / 20 < 0) {
  1700. var _str = '';
  1701. for (var _idx2 = 0, _len = Math.abs((_currentPaddingLeft - _preItemPaddingLeft) / 20); _idx2 < _len; _idx2++) {
  1702. _str = _str + tagStack.pop() || '';
  1703. }
  1704. valStr = valStr + ',';
  1705. item = "".concat(_str).concat(item.replace(/(\d+px<<)/g, ''));
  1706. } else {
  1707. item = item.replace(/(\d+px<<)/g, '');
  1708. valStr = valStr + ',';
  1709. }
  1710. }
  1711. }
  1712. temp += "".concat(item, ": ").concat(valStr, " ").concat(getRemarkWithoutExtraSpan(remarks[idx], false), "\n");
  1713. });
  1714. while (tagStack.length) {
  1715. temp += tagStack.pop();
  1716. }
  1717. template = "// ".concat(desc, "\nlet ").concat(desc.includes('参数') ? 'params' : 'res', " = {").concat(temp, "}");
  1718. console.log(template);
  1719. return _context3.abrupt("return", template);
  1720. case 18:
  1721. case "end":
  1722. return _context3.stop();
  1723. }
  1724. }, _callee3);
  1725. }))).apply(this, arguments);
  1726. }
  1727. /**
  1728. * @description 获取某列所有单元格的内容
  1729. * @param {*} tableDom
  1730. * @param {*} selectorIndex
  1731. * @returns {*}
  1732. */
  1733. function getCellContent(tableDom, selectorIndex) {
  1734. var res = _toConsumableArray(tableDom.querySelectorAll("tbody td:nth-child(".concat(selectorIndex, ")"))).map(function (item) {
  1735. var text = item.innerText || '';
  1736. var childNodes = item.childNodes;
  1737. var extraStrStart = '';
  1738. if (selectorIndex === 1) {
  1739. extraStrStart = childNodes[0].style.paddingLeft + '<<';
  1740. }
  1741. return extraStrStart + text || '';
  1742. });
  1743. return res;
  1744. }
  1745.  
  1746. /**
  1747. * @description 获取备注,并去除不必要的空格
  1748. * @param {*} remark
  1749. * @param {boolean} [endWithWrap=false]
  1750. * @returns {*}
  1751. */
  1752. function getRemarkWithoutExtraSpan(remark) {
  1753. var endWithWrap = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  1754. var str = '';
  1755. if (remark) {
  1756. var _remark, _remark2;
  1757. remark = (_remark = remark) === null || _remark === void 0 ? void 0 : _remark.replace(/[ \t\v\r\f]+/g, ' ');
  1758. if ((_remark2 = remark) !== null && _remark2 !== void 0 && _remark2.includes('\n') && remark.length > 120) {
  1759. str = "/* ".concat(remark, " */");
  1760. } else {
  1761. str = "// ".concat(remark.replace(/\s+/g, ' '));
  1762. }
  1763. if (endWithWrap) {
  1764. str = "".concat(str, "\n");
  1765. }
  1766. }
  1767. return str;
  1768. }
  1769. }
  1770. })();
  1771.  
  1772. /******/ })()
  1773. ;