YapiCopy

Yapi接口数据一键复制

ของเมื่อวันที่ 21-09-2023 ดู เวอร์ชันล่าสุด

  1. // ==UserScript==
  2. // @name YapiCopy
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.4.4
  5. // @description Yapi接口数据一键复制
  6. // @author Enjoy
  7. // @icon https://foruda.gitee.com/avatar/1671100286067517749/4867929_enjoy_li_1671100285.png!avatar60
  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. /***/ 664:
  21. /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
  22.  
  23. "use strict";
  24. __webpack_require__.r(__webpack_exports__);
  25. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  26. /* harmony export */ createElement: () => (/* binding */ createElement),
  27. /* harmony export */ isOperated: () => (/* binding */ isOperated),
  28. /* harmony export */ prependMetaUF8: () => (/* binding */ prependMetaUF8)
  29. /* harmony export */ });
  30. /** @描述 函数文档 https://www.tampermonkey.net/documentation.php#api:GM_addElement */
  31. // $GM.createElement
  32. function createElement(tag) {
  33. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  34. var win = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : window;
  35. if (!win.GM_createElement) {
  36. win.GM_createElement = GM_createElement;
  37. }
  38. return GM_createElement(tag, options);
  39. function GM_createElement(tag, options) {
  40. var idPrefix = "enjoy_".concat("YapiCopy", "_").concat(tag);
  41. var _options$el = options.el,
  42. el = _options$el === void 0 ? 'html' : _options$el,
  43. _options$autoInsert = options.autoInsert,
  44. autoInsert = _options$autoInsert === void 0 ? true : _options$autoInsert,
  45. _options$modeType = options.modeType,
  46. modeType = _options$modeType === void 0 ? 'single' : _options$modeType,
  47. _options$id = options.id,
  48. id = _options$id === void 0 ? '' : _options$id,
  49. _options$addPrefix = options.addPrefix,
  50. addPrefix = _options$addPrefix === void 0 ? true : _options$addPrefix,
  51. _options$insertType = options.insertType,
  52. insertType = _options$insertType === void 0 ? tag === 'style' ? 'appendChild' : 'prepend' : _options$insertType;
  53. if (addPrefix) {
  54. id = "".concat(idPrefix, "_").concat(id);
  55. }
  56. if (modeType !== 'single') {
  57. id = "".concat(id, "_").concat(Math.floor(Math.random() * 1000));
  58. }
  59. options.id = id;
  60. var dom = document.querySelector("#".concat(id));
  61. if (!dom) {
  62. dom = document.createElement(tag);
  63. }
  64. for (var key in options) {
  65. if (Object.hasOwnProperty.call(options, key) && key !== 'el') {
  66. dom[key] = options[key];
  67. }
  68. }
  69. if (autoInsert) {
  70. if (typeof el === 'string') {
  71. el = document.querySelector(el);
  72. }
  73. //insertType prepend | appendChild
  74. el[insertType](dom);
  75. }
  76. return dom;
  77. }
  78. }
  79. /** @描述 进入可以操作的页面 */
  80. function isOperated() {
  81. var urls = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  82. var currentUrl = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : location.href;
  83. if (typeof urls === 'string') {
  84. urls = [urls];
  85. }
  86. return !!urls.find(function (regUrl) {
  87. return new RegExp(regUrl).test(currentUrl);
  88. });
  89. }
  90. function prependMetaUF8() {
  91. return document.querySelector('meta[charset="UTF-8"]') || createElement('meta', {
  92. charset: 'utf-8'
  93. });
  94. }
  95.  
  96. /***/ }),
  97.  
  98. /***/ 728:
  99. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  100.  
  101. var _typeof = (__webpack_require__(202)["default"]);
  102. function _regeneratorRuntime() {
  103. "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
  104. module.exports = _regeneratorRuntime = function _regeneratorRuntime() {
  105. return exports;
  106. }, module.exports.__esModule = true, module.exports["default"] = module.exports;
  107. var exports = {},
  108. Op = Object.prototype,
  109. hasOwn = Op.hasOwnProperty,
  110. defineProperty = Object.defineProperty || function (obj, key, desc) {
  111. obj[key] = desc.value;
  112. },
  113. $Symbol = "function" == typeof Symbol ? Symbol : {},
  114. iteratorSymbol = $Symbol.iterator || "@@iterator",
  115. asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
  116. toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
  117. function define(obj, key, value) {
  118. return Object.defineProperty(obj, key, {
  119. value: value,
  120. enumerable: !0,
  121. configurable: !0,
  122. writable: !0
  123. }), obj[key];
  124. }
  125. try {
  126. define({}, "");
  127. } catch (err) {
  128. define = function define(obj, key, value) {
  129. return obj[key] = value;
  130. };
  131. }
  132. function wrap(innerFn, outerFn, self, tryLocsList) {
  133. var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
  134. generator = Object.create(protoGenerator.prototype),
  135. context = new Context(tryLocsList || []);
  136. return defineProperty(generator, "_invoke", {
  137. value: makeInvokeMethod(innerFn, self, context)
  138. }), generator;
  139. }
  140. function tryCatch(fn, obj, arg) {
  141. try {
  142. return {
  143. type: "normal",
  144. arg: fn.call(obj, arg)
  145. };
  146. } catch (err) {
  147. return {
  148. type: "throw",
  149. arg: err
  150. };
  151. }
  152. }
  153. exports.wrap = wrap;
  154. var ContinueSentinel = {};
  155. function Generator() {}
  156. function GeneratorFunction() {}
  157. function GeneratorFunctionPrototype() {}
  158. var IteratorPrototype = {};
  159. define(IteratorPrototype, iteratorSymbol, function () {
  160. return this;
  161. });
  162. var getProto = Object.getPrototypeOf,
  163. NativeIteratorPrototype = getProto && getProto(getProto(values([])));
  164. NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
  165. var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
  166. function defineIteratorMethods(prototype) {
  167. ["next", "throw", "return"].forEach(function (method) {
  168. define(prototype, method, function (arg) {
  169. return this._invoke(method, arg);
  170. });
  171. });
  172. }
  173. function AsyncIterator(generator, PromiseImpl) {
  174. function invoke(method, arg, resolve, reject) {
  175. var record = tryCatch(generator[method], generator, arg);
  176. if ("throw" !== record.type) {
  177. var result = record.arg,
  178. value = result.value;
  179. return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
  180. invoke("next", value, resolve, reject);
  181. }, function (err) {
  182. invoke("throw", err, resolve, reject);
  183. }) : PromiseImpl.resolve(value).then(function (unwrapped) {
  184. result.value = unwrapped, resolve(result);
  185. }, function (error) {
  186. return invoke("throw", error, resolve, reject);
  187. });
  188. }
  189. reject(record.arg);
  190. }
  191. var previousPromise;
  192. defineProperty(this, "_invoke", {
  193. value: function value(method, arg) {
  194. function callInvokeWithMethodAndArg() {
  195. return new PromiseImpl(function (resolve, reject) {
  196. invoke(method, arg, resolve, reject);
  197. });
  198. }
  199. return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
  200. }
  201. });
  202. }
  203. function makeInvokeMethod(innerFn, self, context) {
  204. var state = "suspendedStart";
  205. return function (method, arg) {
  206. if ("executing" === state) throw new Error("Generator is already running");
  207. if ("completed" === state) {
  208. if ("throw" === method) throw arg;
  209. return {
  210. value: void 0,
  211. done: !0
  212. };
  213. }
  214. for (context.method = method, context.arg = arg;;) {
  215. var delegate = context.delegate;
  216. if (delegate) {
  217. var delegateResult = maybeInvokeDelegate(delegate, context);
  218. if (delegateResult) {
  219. if (delegateResult === ContinueSentinel) continue;
  220. return delegateResult;
  221. }
  222. }
  223. if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
  224. if ("suspendedStart" === state) throw state = "completed", context.arg;
  225. context.dispatchException(context.arg);
  226. } else "return" === context.method && context.abrupt("return", context.arg);
  227. state = "executing";
  228. var record = tryCatch(innerFn, self, context);
  229. if ("normal" === record.type) {
  230. if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
  231. return {
  232. value: record.arg,
  233. done: context.done
  234. };
  235. }
  236. "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
  237. }
  238. };
  239. }
  240. function maybeInvokeDelegate(delegate, context) {
  241. var methodName = context.method,
  242. method = delegate.iterator[methodName];
  243. if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel;
  244. var record = tryCatch(method, delegate.iterator, context.arg);
  245. if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
  246. var info = record.arg;
  247. return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
  248. }
  249. function pushTryEntry(locs) {
  250. var entry = {
  251. tryLoc: locs[0]
  252. };
  253. 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
  254. }
  255. function resetTryEntry(entry) {
  256. var record = entry.completion || {};
  257. record.type = "normal", delete record.arg, entry.completion = record;
  258. }
  259. function Context(tryLocsList) {
  260. this.tryEntries = [{
  261. tryLoc: "root"
  262. }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
  263. }
  264. function values(iterable) {
  265. if (iterable || "" === iterable) {
  266. var iteratorMethod = iterable[iteratorSymbol];
  267. if (iteratorMethod) return iteratorMethod.call(iterable);
  268. if ("function" == typeof iterable.next) return iterable;
  269. if (!isNaN(iterable.length)) {
  270. var i = -1,
  271. next = function next() {
  272. for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
  273. return next.value = undefined, next.done = !0, next;
  274. };
  275. return next.next = next;
  276. }
  277. }
  278. throw new TypeError(_typeof(iterable) + " is not iterable");
  279. }
  280. return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", {
  281. value: GeneratorFunctionPrototype,
  282. configurable: !0
  283. }), defineProperty(GeneratorFunctionPrototype, "constructor", {
  284. value: GeneratorFunction,
  285. configurable: !0
  286. }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
  287. var ctor = "function" == typeof genFun && genFun.constructor;
  288. return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
  289. }, exports.mark = function (genFun) {
  290. return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
  291. }, exports.awrap = function (arg) {
  292. return {
  293. __await: arg
  294. };
  295. }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
  296. return this;
  297. }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
  298. void 0 === PromiseImpl && (PromiseImpl = Promise);
  299. var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
  300. return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
  301. return result.done ? result.value : iter.next();
  302. });
  303. }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
  304. return this;
  305. }), define(Gp, "toString", function () {
  306. return "[object Generator]";
  307. }), exports.keys = function (val) {
  308. var object = Object(val),
  309. keys = [];
  310. for (var key in object) keys.push(key);
  311. return keys.reverse(), function next() {
  312. for (; keys.length;) {
  313. var key = keys.pop();
  314. if (key in object) return next.value = key, next.done = !1, next;
  315. }
  316. return next.done = !0, next;
  317. };
  318. }, exports.values = values, Context.prototype = {
  319. constructor: Context,
  320. reset: function reset(skipTempReset) {
  321. if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
  322. },
  323. stop: function stop() {
  324. this.done = !0;
  325. var rootRecord = this.tryEntries[0].completion;
  326. if ("throw" === rootRecord.type) throw rootRecord.arg;
  327. return this.rval;
  328. },
  329. dispatchException: function dispatchException(exception) {
  330. if (this.done) throw exception;
  331. var context = this;
  332. function handle(loc, caught) {
  333. return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
  334. }
  335. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  336. var entry = this.tryEntries[i],
  337. record = entry.completion;
  338. if ("root" === entry.tryLoc) return handle("end");
  339. if (entry.tryLoc <= this.prev) {
  340. var hasCatch = hasOwn.call(entry, "catchLoc"),
  341. hasFinally = hasOwn.call(entry, "finallyLoc");
  342. if (hasCatch && hasFinally) {
  343. if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
  344. if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
  345. } else if (hasCatch) {
  346. if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
  347. } else {
  348. if (!hasFinally) throw new Error("try statement without catch or finally");
  349. if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
  350. }
  351. }
  352. }
  353. },
  354. abrupt: function abrupt(type, arg) {
  355. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  356. var entry = this.tryEntries[i];
  357. if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
  358. var finallyEntry = entry;
  359. break;
  360. }
  361. }
  362. finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
  363. var record = finallyEntry ? finallyEntry.completion : {};
  364. return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
  365. },
  366. complete: function complete(record, afterLoc) {
  367. if ("throw" === record.type) throw record.arg;
  368. return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
  369. },
  370. finish: function finish(finallyLoc) {
  371. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  372. var entry = this.tryEntries[i];
  373. if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
  374. }
  375. },
  376. "catch": function _catch(tryLoc) {
  377. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  378. var entry = this.tryEntries[i];
  379. if (entry.tryLoc === tryLoc) {
  380. var record = entry.completion;
  381. if ("throw" === record.type) {
  382. var thrown = record.arg;
  383. resetTryEntry(entry);
  384. }
  385. return thrown;
  386. }
  387. }
  388. throw new Error("illegal catch attempt");
  389. },
  390. delegateYield: function delegateYield(iterable, resultName, nextLoc) {
  391. return this.delegate = {
  392. iterator: values(iterable),
  393. resultName: resultName,
  394. nextLoc: nextLoc
  395. }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
  396. }
  397. }, exports;
  398. }
  399. module.exports = _regeneratorRuntime, module.exports.__esModule = true, module.exports["default"] = module.exports;
  400.  
  401. /***/ }),
  402.  
  403. /***/ 202:
  404. /***/ ((module) => {
  405.  
  406. function _typeof(obj) {
  407. "@babel/helpers - typeof";
  408.  
  409. return (module.exports = _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
  410. return typeof obj;
  411. } : function (obj) {
  412. return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  413. }, module.exports.__esModule = true, module.exports["default"] = module.exports), _typeof(obj);
  414. }
  415. module.exports = _typeof, module.exports.__esModule = true, module.exports["default"] = module.exports;
  416.  
  417. /***/ }),
  418.  
  419. /***/ 170:
  420. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  421.  
  422. // TODO(Babel 8): Remove this file.
  423.  
  424. var runtime = __webpack_require__(728)();
  425. module.exports = runtime;
  426.  
  427. // Copied from https://github.com/facebook/regenerator/blob/main/packages/runtime/runtime.js#L736=
  428. try {
  429. regeneratorRuntime = runtime;
  430. } catch (accidentalStrictMode) {
  431. if (typeof globalThis === "object") {
  432. globalThis.regeneratorRuntime = runtime;
  433. } else {
  434. Function("r", "regeneratorRuntime = r")(runtime);
  435. }
  436. }
  437.  
  438.  
  439. /***/ })
  440.  
  441. /******/ });
  442. /************************************************************************/
  443. /******/ // The module cache
  444. /******/ var __webpack_module_cache__ = {};
  445. /******/
  446. /******/ // The require function
  447. /******/ function __webpack_require__(moduleId) {
  448. /******/ // Check if module is in cache
  449. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  450. /******/ if (cachedModule !== undefined) {
  451. /******/ return cachedModule.exports;
  452. /******/ }
  453. /******/ // Create a new module (and put it into the cache)
  454. /******/ var module = __webpack_module_cache__[moduleId] = {
  455. /******/ // no module.id needed
  456. /******/ // no module.loaded needed
  457. /******/ exports: {}
  458. /******/ };
  459. /******/
  460. /******/ // Execute the module function
  461. /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  462. /******/
  463. /******/ // Return the exports of the module
  464. /******/ return module.exports;
  465. /******/ }
  466. /******/
  467. /************************************************************************/
  468. /******/ /* webpack/runtime/compat get default export */
  469. /******/ (() => {
  470. /******/ // getDefaultExport function for compatibility with non-harmony modules
  471. /******/ __webpack_require__.n = (module) => {
  472. /******/ var getter = module && module.__esModule ?
  473. /******/ () => (module['default']) :
  474. /******/ () => (module);
  475. /******/ __webpack_require__.d(getter, { a: getter });
  476. /******/ return getter;
  477. /******/ };
  478. /******/ })();
  479. /******/
  480. /******/ /* webpack/runtime/define property getters */
  481. /******/ (() => {
  482. /******/ // define getter functions for harmony exports
  483. /******/ __webpack_require__.d = (exports, definition) => {
  484. /******/ for(var key in definition) {
  485. /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  486. /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  487. /******/ }
  488. /******/ }
  489. /******/ };
  490. /******/ })();
  491. /******/
  492. /******/ /* webpack/runtime/hasOwnProperty shorthand */
  493. /******/ (() => {
  494. /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
  495. /******/ })();
  496. /******/
  497. /******/ /* webpack/runtime/make namespace object */
  498. /******/ (() => {
  499. /******/ // define __esModule on exports
  500. /******/ __webpack_require__.r = (exports) => {
  501. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  502. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  503. /******/ }
  504. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  505. /******/ };
  506. /******/ })();
  507. /******/
  508. /************************************************************************/
  509. var __webpack_exports__ = {};
  510. // This entry need to be wrapped in an IIFE because it need to be in strict mode.
  511. (() => {
  512. "use strict";
  513.  
  514. ;// CONCATENATED MODULE: ./node_modules/.pnpm/registry.npmjs.org+@babel+runtime@7.22.10/node_modules/@babel/runtime/helpers/esm/arrayLikeToArray.js
  515. function _arrayLikeToArray(arr, len) {
  516. if (len == null || len > arr.length) len = arr.length;
  517. for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
  518. return arr2;
  519. }
  520. ;// CONCATENATED MODULE: ./node_modules/.pnpm/registry.npmjs.org+@babel+runtime@7.22.10/node_modules/@babel/runtime/helpers/esm/arrayWithoutHoles.js
  521.  
  522. function _arrayWithoutHoles(arr) {
  523. if (Array.isArray(arr)) return _arrayLikeToArray(arr);
  524. }
  525. ;// CONCATENATED MODULE: ./node_modules/.pnpm/registry.npmjs.org+@babel+runtime@7.22.10/node_modules/@babel/runtime/helpers/esm/iterableToArray.js
  526. function _iterableToArray(iter) {
  527. if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
  528. }
  529. ;// CONCATENATED MODULE: ./node_modules/.pnpm/registry.npmjs.org+@babel+runtime@7.22.10/node_modules/@babel/runtime/helpers/esm/unsupportedIterableToArray.js
  530.  
  531. function _unsupportedIterableToArray(o, minLen) {
  532. if (!o) return;
  533. if (typeof o === "string") return _arrayLikeToArray(o, minLen);
  534. var n = Object.prototype.toString.call(o).slice(8, -1);
  535. if (n === "Object" && o.constructor) n = o.constructor.name;
  536. if (n === "Map" || n === "Set") return Array.from(o);
  537. if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
  538. }
  539. ;// CONCATENATED MODULE: ./node_modules/.pnpm/registry.npmjs.org+@babel+runtime@7.22.10/node_modules/@babel/runtime/helpers/esm/nonIterableSpread.js
  540. function _nonIterableSpread() {
  541. throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  542. }
  543. ;// CONCATENATED MODULE: ./node_modules/.pnpm/registry.npmjs.org+@babel+runtime@7.22.10/node_modules/@babel/runtime/helpers/esm/toConsumableArray.js
  544.  
  545.  
  546.  
  547.  
  548. function _toConsumableArray(arr) {
  549. return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
  550. }
  551. ;// CONCATENATED MODULE: ./node_modules/.pnpm/registry.npmjs.org+@babel+runtime@7.22.10/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js
  552. function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
  553. try {
  554. var info = gen[key](arg);
  555. var value = info.value;
  556. } catch (error) {
  557. reject(error);
  558. return;
  559. }
  560. if (info.done) {
  561. resolve(value);
  562. } else {
  563. Promise.resolve(value).then(_next, _throw);
  564. }
  565. }
  566. function _asyncToGenerator(fn) {
  567. return function () {
  568. var self = this,
  569. args = arguments;
  570. return new Promise(function (resolve, reject) {
  571. var gen = fn.apply(self, args);
  572. function _next(value) {
  573. asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
  574. }
  575. function _throw(err) {
  576. asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
  577. }
  578. _next(undefined);
  579. });
  580. };
  581. }
  582. // EXTERNAL MODULE: ./node_modules/.pnpm/registry.npmjs.org+@babel+runtime@7.22.10/node_modules/@babel/runtime/regenerator/index.js
  583. var regenerator = __webpack_require__(170);
  584. var regenerator_default = /*#__PURE__*/__webpack_require__.n(regenerator);
  585. ;// CONCATENATED MODULE: ./src/YapiCopy.js
  586. /* provided dependency */ var $GM = __webpack_require__(664);
  587.  
  588.  
  589.  
  590.  
  591. run();
  592. function run() {
  593. createBtn();
  594. window.cellecteParamsTxt = cellecteParamsTxt;
  595. function createBtn() {
  596. var btnDom = $GM.createElement('div', {
  597. innerHTML: "\n <div title='api \u4E00\u952E\u590D\u5236'>\uD83D\uDC26</div>\n <div title='params \u4E00\u952E\u590D\u5236'>\uD83D\uDC0D</div>\n <div title='response \u4E00\u952E\u590D\u5236'>\uD83D\uDC1F</div>\n <style>\n #enjoy_YapiCopy_div_ {\n width: 15px;\n height: 105px;\n opacity: 0.4;\n background: #9bab9e;\n font-weight: 800;\n border-radius:0 5px 5px 0;\n cursor: pointer;\n color: #fff;\n transition: all 0.2s;\n font-size: 18px;\n position: fixed;\n left: 0;\n top: 50vh;\n font-size:12px;\n z-index: 1;\n }\n\n #enjoy_YapiCopy_div_:hover {\n opacity: 0.5;\n width: 35px;\n height: 105px;\n font-size:16px;\n }\n\n #enjoy_YapiCopy_div_>div {\n height: 35px;\n line-height: 35px;\n text-align: center;\n border-radius:0 5px 5px 0;\n transition: all 0.1s;\n }\n\n #enjoy_YapiCopy_div_>div:hover {\n background-color: #333333;\n font-size: 25px;\n }\n </style>\n "
  598. });
  599. btnDom.addEventListener('click', /*#__PURE__*/function () {
  600. var _ref = _asyncToGenerator( /*#__PURE__*/regenerator_default().mark(function _callee(e) {
  601. return regenerator_default().wrap(function _callee$(_context) {
  602. while (1) switch (_context.prev = _context.next) {
  603. case 0:
  604. if (!(e.target.title === 'api 一键复制')) {
  605. _context.next = 4;
  606. break;
  607. }
  608. doCopy(cellecteApiTxt());
  609. _context.next = 17;
  610. break;
  611. case 4:
  612. if (!(e.target.title === 'params 一键复制')) {
  613. _context.next = 12;
  614. break;
  615. }
  616. _context.t0 = doCopy;
  617. _context.next = 8;
  618. return cellecteParamsTxt('请求参数结构', 1);
  619. case 8:
  620. _context.t1 = _context.sent;
  621. (0, _context.t0)(_context.t1);
  622. _context.next = 17;
  623. break;
  624. case 12:
  625. _context.t2 = doCopy;
  626. _context.next = 15;
  627. return cellecteParamsTxt('返回数据结构', 2);
  628. case 15:
  629. _context.t3 = _context.sent;
  630. (0, _context.t2)(_context.t3);
  631. case 17:
  632. case "end":
  633. return _context.stop();
  634. }
  635. }, _callee);
  636. }));
  637. return function (_x) {
  638. return _ref.apply(this, arguments);
  639. };
  640. }());
  641. }
  642. function doCopy(newValue) {
  643. var selector = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'textarea';
  644. var textarea = $GM.createElement('textarea', {
  645. el: 'body',
  646. id: selector,
  647. style: 'position: absolute;left: -500px;top: -500px;max-width: 50px;opacity: 0;'
  648. });
  649. textarea.value = newValue;
  650. textarea.select();
  651. setTimeout(function () {
  652. document.execCommand('Copy');
  653. }, 200);
  654. }
  655. function cellecteApiTxt() {
  656. var _values$, _values$2;
  657. var desc = document.querySelector('.colName').innerText || '';
  658. var dirName = document.querySelector('.remark>.colValue').innerText || '';
  659. var pageUrl = location.href;
  660. var values = document.querySelectorAll('.colValue');
  661. var method = ((_values$ = values[3]) === null || _values$ === void 0 ? void 0 : _values$.innerText.toLocaleLowerCase()) || '';
  662. var apiUrl = ((_values$2 = values[4]) === null || _values$2 === void 0 ? void 0 : _values$2.innerText) || '';
  663. var templateDesc = "";
  664. var templateParams = "";
  665. if (method === 'post') {
  666. templateDesc = "\n * @param {Object} data";
  667. templateParams = "data, ";
  668. }
  669. var template = "\n/**\n * ".concat(desc, " - ").concat(dirName).concat(templateDesc, "\n * @param {Object} [config]\n * @returns {Promise<ResponseData>}\n * @see ").concat(decodeURIComponent(pageUrl), "\n */\nexport function ").concat(apiUrl.replace(/^.*\//, ''), "(").concat(templateParams, "config) {\n return http.").concat(method, "('").concat(apiUrl, "',").concat(templateParams, "{ ...config })\n}\n");
  670. console.log(template);
  671. return template;
  672. }
  673. function expandCell(_x2) {
  674. return _expandCell.apply(this, arguments);
  675. }
  676. function _expandCell() {
  677. _expandCell = _asyncToGenerator( /*#__PURE__*/regenerator_default().mark(function _callee2(tableDom) {
  678. var collapsed;
  679. return regenerator_default().wrap(function _callee2$(_context2) {
  680. while (1) switch (_context2.prev = _context2.next) {
  681. case 0:
  682. collapsed = _toConsumableArray(tableDom.querySelectorAll('.ant-table-row-collapsed'));
  683. collapsed.forEach(function (item) {
  684. item.click();
  685. });
  686. _context2.next = 4;
  687. return new Promise(function (resolve) {
  688. setTimeout(resolve, 200);
  689. });
  690. case 4:
  691. return _context2.abrupt("return", _context2.sent);
  692. case 5:
  693. case "end":
  694. return _context2.stop();
  695. }
  696. }, _callee2);
  697. }));
  698. return _expandCell.apply(this, arguments);
  699. }
  700. function cellecteParamsTxt() {
  701. return _cellecteParamsTxt.apply(this, arguments);
  702. }
  703. function _cellecteParamsTxt() {
  704. _cellecteParamsTxt = _asyncToGenerator( /*#__PURE__*/regenerator_default().mark(function _callee3() {
  705. var _document$querySelect;
  706. var desc,
  707. index,
  708. tableDom,
  709. keys,
  710. values,
  711. descs,
  712. maps,
  713. temp,
  714. tagStack,
  715. template,
  716. _args3 = arguments;
  717. return regenerator_default().wrap(function _callee3$(_context3) {
  718. while (1) switch (_context3.prev = _context3.next) {
  719. case 0:
  720. desc = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : '参数说明';
  721. index = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : 1;
  722. tableDom = (_document$querySelect = document.querySelectorAll('table')) === null || _document$querySelect === void 0 ? void 0 : _document$querySelect[index];
  723. if (tableDom) {
  724. _context3.next = 5;
  725. break;
  726. }
  727. return _context3.abrupt("return", '');
  728. case 5:
  729. _context3.next = 7;
  730. return expandCell(tableDom);
  731. case 7:
  732. keys = getCellContent(tableDom, 1);
  733. values = getCellContent(tableDom, 2);
  734. descs = getCellContent(tableDom, 5);
  735. maps = {
  736. integer: '0',
  737. string: "''",
  738. "boolean": 'true',
  739. object: '{}',
  740. 'integer []': '[]',
  741. 'string []': '[]',
  742. 'object []': '[{}]'
  743. };
  744. temp = '\n';
  745. tagStack = [];
  746. keys.forEach(function (item, idx) {
  747. if (!item) return;
  748. var valStart = '';
  749. var flag = maps[values[idx]];
  750. if (item.includes('<<')) {
  751. valStart = flag.slice(0, flag.length / 2);
  752. tagStack.push(flag.slice(-1 * flag.length / 2) + ',\n');
  753. flag = valStart ? valStart : flag + ',';
  754. item = "".concat(descs[idx] ? '//' + descs[idx] + '\n' : '').concat(item.replace('<<', ''));
  755. descs[idx] = '';
  756. } else if (item.includes('>>')) {
  757. item = "".concat(tagStack.pop()).concat(descs[idx] ? '//' + descs[idx] + '\n' : '').concat(item.replace('>>', ''));
  758. descs[idx] = '';
  759. flag = flag + ',';
  760. } else {
  761. flag = flag + ',';
  762. }
  763. temp += "".concat(item, ": ").concat(flag, " ").concat(descs[idx] ? '//' + descs[idx] : '', "\n");
  764. });
  765. while (tagStack.length) {
  766. temp += tagStack.pop();
  767. }
  768. template = "// ".concat(desc, "\nconst ").concat(desc.includes('参数') ? 'data' : 'res', " = {").concat(temp, "}");
  769. console.log(template);
  770. return _context3.abrupt("return", template);
  771. case 18:
  772. case "end":
  773. return _context3.stop();
  774. }
  775. }, _callee3);
  776. }));
  777. return _cellecteParamsTxt.apply(this, arguments);
  778. }
  779. function getCellContent(tableDom, selectorIndex) {
  780. var levelStack = [];
  781. var classPrefix = 'ant-table-row-indent indent-level-';
  782. var res = _toConsumableArray(tableDom.querySelectorAll("tbody td:nth-child(".concat(selectorIndex, ")"))).map(function (item) {
  783. var text = item.innerText || '';
  784. var childNodes = item.childNodes;
  785. var extraStrStart = '';
  786. if (selectorIndex === 1) {
  787. var _childNodes$, _childNodes$2;
  788. if ((_childNodes$ = childNodes[1]) !== null && _childNodes$ !== void 0 && (_childNodes$ = _childNodes$.classList) !== null && _childNodes$ !== void 0 && (_childNodes$ = _childNodes$.value) !== null && _childNodes$ !== void 0 && _childNodes$.includes('ant-table-row-expanded')) {
  789. extraStrStart = '<<';
  790. levelStack.push(childNodes[0].classList.value.replace(new RegExp("".concat(classPrefix, "(\\d+)"), 'g'), '$1'));
  791. } else if (levelStack.length && (_childNodes$2 = childNodes[0]) !== null && _childNodes$2 !== void 0 && (_childNodes$2 = _childNodes$2.classList) !== null && _childNodes$2 !== void 0 && _childNodes$2.value.includes(levelStack.at(-1))) {
  792. extraStrStart = '>>';
  793. levelStack.pop();
  794. }
  795. }
  796. return extraStrStart + text || '';
  797. });
  798. return res;
  799. }
  800. }
  801. })();
  802.  
  803. /******/ })()
  804. ;