yapiTots

yapi to ts

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         yapiTots
// @namespace    yapiTots
// @version      0.0.5
// @description  yapi to ts
// @license      MIT
// @author       hjl
// @match        http://192.168.140.245:3000/*
// @icon         https://img2.baidu.com/it/u=3318407772,3634490264&fm=253&fmt=auto?w=1200&h=767
// @grant        none
// ==/UserScript==

window.whiteList = ['http://192.168.140.245:3000']

if(!window.whiteList.includes(window.location.origin)){
    return
}


const vueUrl ='https://6465-develop-0ggt1xa152c00a65-1323643080.tcb.qcloud.la/yapi-ts/vue.js'
const axiosUrl = 'https://6465-develop-0ggt1xa152c00a65-1323643080.tcb.qcloud.la/yapi-ts/axios.js'



const elementCss='https://6465-develop-0ggt1xa152c00a65-1323643080.tcb.qcloud.la/yapi-ts/element-ui.css'
const elementJs ='https://6465-develop-0ggt1xa152c00a65-1323643080.tcb.qcloud.la/yapi-ts/element-ui.js'

function loadFiles(fileArray, callback) {
    let loadedCount = 0;

    function loadFile(file, type) {
        return new Promise((resolve, reject) => {
            if (type === 'js') {
                const script = document.createElement('script');
                script.src = file;
                script.onload = () => {
                    loadedCount++;
                    resolve();
                };
                script.onerror = () => {
                    reject(new Error(`Failed to load script: ${file}`));
                };
                document.head.appendChild(script);
            } else if (type === 'css') {
                const link = document.createElement('link');
                link.rel = 'stylesheet';
                link.href = file;
                link.onload = () => {
                    loadedCount++;
                    resolve();
                };
                link.onerror = () => {
                    reject(new Error(`Failed to load stylesheet: ${file}`));
                };
                document.head.appendChild(link);
            }
        });
    }

    function checkAllLoaded() {
        if (loadedCount === fileArray.length) {
            callback();
        }
    }

    fileArray.forEach(file => {
        const fileParts = file.split('.');
        const fileType = fileParts[fileParts.length - 1];
        loadFile(file, fileType).then(checkAllLoaded).catch(error => {
            console.error(error);
            checkAllLoaded();
        });
    });
}



function createScript (url,onLoad){
    var script = document.createElement('script');
    script.src = url;
    if(onLoad){
        script.onload=onLoad
    }
    return script
}


function createLink (url,onLoad){
    var link = document.createElement('link');
    link.href = url;
    link.setAttribute('rel','stylesheet');

    link.setAttribute('type','text/css');
    if(onLoad){
        link.onload=onLoad
    }
    return link
}

const app = document.createElement('div');

app.id='app'
document.body.appendChild(app);

        // 使用示例
loadFiles([ vueUrl, axiosUrl,elementCss,elementJs], () => {
    document.body.appendChild(createScript(`https://xyfali.postar.cn/risk-message/createTs.js?time=${new Date().getTime()}`))
});