上一主题 下一主题
ScriptCat,新一代的脚本管理器脚本站,与全世界分享你的用户脚本油猴脚本开发指南教程目录
返回列表 发新帖

分享下脚本引入Vuetify

[复制链接]
  • TA的每日心情
    开心
    7 小时前
  • 签到天数: 302 天

    [LV.8]以坛为家I

    6

    主题

    29

    回帖

    216

    积分

    高级工程师

    积分
    216

    挑战者 lv2

    发表于 2024-7-23 20:45:22 | 显示全部楼层 | 阅读模式

    发现网上好像没有,所以分享出来
    不是很懂vue有什么错误,麻烦大家指点。
    部分网站挂载全屏,内容会显示不出来。不知道是为什么,所以最好给挂载的内容设置个长宽

    function importVuetify() {
        const vuetifyCSS = unsafeWindow.document.createElement('link');
        vuetifyCSS.rel = 'stylesheet';
        vuetifyCSS.href = 'https://cdn.jsdelivr.net/npm/vuetify@3.3.9/dist/vuetify.min.css';
        unsafeWindow.document.head.appendChild(vuetifyCSS);
        const script = unsafeWindow.document.createElement('script');
        script.src = 'https://unpkg.com/vue@3/dist/vue.global.js';
        unsafeWindow.document.head.appendChild(script);
        script.onload = function () {
            GM_xmlhttpRequest(
                {
                    method: 'GET',
                    url: 'https://cdn.jsdelivr.net/npm/vuetify@3.3.9/dist/vuetify.min.js',
                    onload: function (response) {
                        let text = response.responseText;
                        text = text.replace('"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Vuetify={},e.Vue)',
                            'e = unsafeWindow;t(e.Vuetify = {}, e.Vue);'
                        );
                        eval(text);
                        Vue = unsafeWindow.Vue;
                        Vuetify = unsafeWindow.Vuetify;
                        initApp();
                    }
                }
            );
        };
    }
    
    function initApp() {
        // 创建一个新的div元素来放置我们的Vue应用
        let app = unsafeWindow.document.createElement('div');
        app.id = 'vuetify-app1111';
        app.style.position = 'fixed';
        app.style.top = '20px';
        app.style.right = '20px';
        app.style.zIndex = '9999';
        app.style.width = '300px';  // 设置宽度
        app.style.height = 'auto';  // 高度自适应
        app.style.backgroundColor = 'white';  // 设置背景色
        app.style.boxShadow = '0 0 10px rgba(0,0,0,0.1)';  // 添加阴影效果
        app.style.borderRadius = '8px';  // 圆角
        app.style.overflow = 'hidden';  // 隐藏溢出内容
        unsafeWindow.document.body.appendChild(app);
    
        // 初始化Vue应用
        const { createApp } = Vue;
        const vuetify = Vuetify.createVuetify();
    
        createApp({
            data() {
                return {
                    message: 'Hello Vuetify!'
                };
            },
            template: `
                <v-app>
                    <v-main>
                        <v-container>
                            <v-btn color="primary">{{ message }}</v-btn>
                            <v-text-field label="Input" variant="outlined" class="mt-4"></v-text-field>
                            <v-switch label="Toggle me" class="mt-4"></v-switch>
                        </v-container>
                    </v-main>
                </v-app>
            `
        }).use(vuetify).mount('#vuetify-app1111');
        const remove_popup_hander = (event) => {
            if (!app.contains(event.target)) {
                app.remove();
                unsafeWindow.document.removeEventListener('click', remove_popup_hander);
            }
        };
        unsafeWindow.document.addEventListener('click', remove_popup_hander);
    }
    已有1人评分好评 油猫币 理由
    王一之 + 1 + 4 感谢分享

    查看全部评分 总评分:好评 +1  油猫币 +4 

  • TA的每日心情
    擦汗
    2024-7-16 09:20
  • 签到天数: 192 天

    [LV.7]常住居民III

    691

    主题

    5563

    回帖

    6462

    积分

    管理员

    非物质文化遗产社会摇传承人

    积分
    6462

    荣誉开发者管理员油中2周年生态建设者喜迎中秋

    发表于 2024-7-24 12:18:55 | 显示全部楼层
    按道理来说直接require也行
    等我明天凹一下
    混的人。
    ------------------------------------------
    進撃!永遠の帝国の破壊虎---李恒道

    入驻了爱发电https://afdian.net/a/lihengdao666
    个人宣言:この世界で私に胜てる人とコードはまだ生まれていません。死ぬのが怖くなければ来てください。
    回复

    使用道具 举报

    发表回复

    本版积分规则

    快速回复 返回顶部 返回列表