yapiTots

yapi to ts

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