yapiTots

yapi to ts

目前为 2024-10-21 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name yapiTots
  3. // @namespace yapiTots
  4. // @version 0.0.4
  5. // @description yapi to ts
  6. // @license MIT
  7. // @author hjl
  8. // @match http://192.168.140.245:3000/*
  9. // @icon https://img2.baidu.com/it/u=3318407772,3634490264&fm=253&fmt=auto?w=1200&h=767
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. window.whiteList = ['http://192.168.140.245:3000']
  14.  
  15. if(!window.whiteList.includes(window.location.origin)){
  16. return
  17. }
  18.  
  19. const dayJsUrl = 'https://unpkg.com/dayjs@1.11.7/dayjs.min.js'
  20. const vueUrl ='https://6465-develop-0ggt1xa152c00a65-1323643080.tcb.qcloud.la/yapi-ts/vue.js'
  21. const axiosUrl = 'https://6465-develop-0ggt1xa152c00a65-1323643080.tcb.qcloud.la/yapi-ts/axios.js'
  22.  
  23.  
  24.  
  25. const elementCss='https://6465-develop-0ggt1xa152c00a65-1323643080.tcb.qcloud.la/yapi-ts/element-ui.css'
  26. const elementJs ='https://6465-develop-0ggt1xa152c00a65-1323643080.tcb.qcloud.la/yapi-ts/element-ui.js'
  27.  
  28. function loadFiles(fileArray, callback) {
  29. let loadedCount = 0;
  30.  
  31. function loadFile(file, type) {
  32. return new Promise((resolve, reject) => {
  33. if (type === 'js') {
  34. const script = document.createElement('script');
  35. script.src = file;
  36. script.onload = () => {
  37. loadedCount++;
  38. resolve();
  39. };
  40. script.onerror = () => {
  41. reject(new Error(`Failed to load script: ${file}`));
  42. };
  43. document.head.appendChild(script);
  44. } else if (type === 'css') {
  45. const link = document.createElement('link');
  46. link.rel = 'stylesheet';
  47. link.href = file;
  48. link.onload = () => {
  49. loadedCount++;
  50. resolve();
  51. };
  52. link.onerror = () => {
  53. reject(new Error(`Failed to load stylesheet: ${file}`));
  54. };
  55. document.head.appendChild(link);
  56. }
  57. });
  58. }
  59.  
  60. function checkAllLoaded() {
  61. if (loadedCount === fileArray.length) {
  62. callback();
  63. }
  64. }
  65.  
  66. fileArray.forEach(file => {
  67. const fileParts = file.split('.');
  68. const fileType = fileParts[fileParts.length - 1];
  69. loadFile(file, fileType).then(checkAllLoaded).catch(error => {
  70. console.error(error);
  71. checkAllLoaded();
  72. });
  73. });
  74. }
  75.  
  76.  
  77.  
  78. function createScript (url,onLoad){
  79. var script = document.createElement('script');
  80. script.src = url;
  81. if(onLoad){
  82. script.onload=onLoad
  83. }
  84. return script
  85. }
  86.  
  87.  
  88. function createLink (url,onLoad){
  89. var link = document.createElement('link');
  90. link.href = url;
  91. link.setAttribute('rel','stylesheet');
  92.  
  93. link.setAttribute('type','text/css');
  94. if(onLoad){
  95. link.onload=onLoad
  96. }
  97. return link
  98. }
  99.  
  100. const app = document.createElement('div');
  101.  
  102. app.id='app'
  103. document.body.appendChild(app);
  104.  
  105. // 使用示例
  106. loadFiles([dayJsUrl, vueUrl, axiosUrl,elementCss,elementJs], () => {
  107. document.body.appendChild(createScript(`https://xyfali.postar.cn/risk-message/createTs.js?time=${new Date().getTime()}`))
  108. });
  109.  
  110.