抱歉,您的浏览器无法访问本站
本页面需要浏览器支持(启用)JavaScript
了解详情 >

官方文档写的已经够清楚了.这里记录一些我遇到的问题.

中文配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
// vite.config.ts
export type MonkeyUserScript = {
/**
* 用户脚本入口文件路径
*/
entry: string;
userscript?: MonkeyUserScript;
format?: Format;

/**
* vite-plugin-monkey/dist/client 的别名
* @default '$'
* @example
* // vite-env.d.ts 用于类型提示
*
* // 如果使用默认值 `$`
* /// <reference types="vite-plugin-monkey/client" />
*
* // 如果使用其他别名 other_alias
* declare module other_alias {
* export * from 'vite-plugin-monkey/dist/client';
* }
*/
clientAlias?: string;
server?: {
/**
* 当用户脚本注释发生变化时,自动在默认浏览器中打开安装地址
*
* 并设置 `viteConfig.server.open ??= monkeyConfig.server.open`
* @default
* process.platform == 'win32' || process.platform == 'darwin' // 如果是Win/Mac平台
*/
open?: boolean;

/**
* 名称前缀,用于区分 server.user.js 和 build.user.js 在猴子扩展安装列表中的名称,如果不需要前缀,设置为false
* @default 'server:'
*/
prefix?: string | ((name: string) => string) | false;

/**
* 将 GM_api 挂载到 unsafeWindow 上,不推荐使用,应该通过 ESM 导入使用 GM_api,或使用 [unplugin-auto-import](https://github.com/antfu/unplugin-auto-import)
* @default false
* @example
* // 如果设置为 true,可以使用 `vite-plugin-monkey/global` 进行类型提示
* // vite-env.d.ts
* /// <reference types="vite-plugin-monkey/global" />
*/
mountGmApi?: boolean;
};
build?: {
/**
* 构建的用户脚本文件名
*
* 应该以 '.user.js' 结尾
* @default (package.json.name??'monkey')+'.user.js'
*/
fileName?: string;

/**
* 构建的只包含注释的用户脚本文件名,可以用于 userscript.updateURL
*
* 检查更新时,只下载这个小的文件而不是整个脚本
*
* 应该以 '.meta.js' 结尾,如果设置为 false,不会生成此文件
*
* 如果设置为 true,会等于 fileName.replace(/\\.user\\.js$/, '.meta.js')
*
* @default false
*/
metaFileName?: string | boolean | ((fileName: string) => string);

/**
* 这个配置可以是数组或对象,数组=Object.entries(对象)
*
* 如果值是字符串或函数,它或它的返回值是 exportVarName
*
* 如果值是数组,第一个项或它的返回值是 exportVarName,之后的项都是 [require url]
*
* 如果模块未导入,插件不会向用户脚本添加 require url
*
* @example
* { // 映射结构
* vue:'Vue',
* // 如果这样设置
* // 需要在 `vite build` 时手动设置 userscript.require = ['https://unpkg.com/[email protected]/dist/vue.global.js']
*
* vuex:['Vuex', (version, name)=>`https://unpkg.com/${name}@${version}/dist/vuex.global.js`],
* // 插件会自动将此 url 添加到 userscript.require
*
* 'prettier/parser-babel': [
* 'prettierPlugins.babel',
* (version, name, importName) => {
* // name == `prettier`
* // importName == `prettier/parser-babel`
* const subpath = `${importName.split('/').at(-1)}.js`;
* return `https://unpkg.com/${name}@${version}/${subpath}`;
* },
* ],
* // 有时导入名与包名不同
* }
* @example
* [ // 数组结构,这个例子来自 [playground/ex-vue-demi](https://github.com/lisonge/vite-plugin-monkey/tree/main/playground/ex-vue-demi)
* [
* 'vue',
* cdn
* .jsdelivr('Vue', 'dist/vue.global.prod.js')
* .concat('https://unpkg.com/vue-demi@latest/lib/index.iife.js')
* .concat(
* await util.fn2dataUrl(() => {
* window.Vue = Vue;
* }),
* ),
* ],
* ['pinia', cdn.jsdelivr('Pinia', 'dist/pinia.iife.prod.js')],
* [
* 'element-plus',
* cdn.jsdelivr('ElementPlus', 'dist/index.full.min.js'),
* ],
* ]
*/
externalGlobals?: ExternalGlobals;

/**
* 根据最终代码包,自动向用户脚本注释授予 GM_* 或 GM.* 权限
*
* 移除无用代码,然后如果代码包含 'GM_xxx',向 \@grant 添加 GM_xxx
* @default true
*/
autoGrant?: boolean;

/**
* @deprecated 使用 vite>=4.2.0 中的 [viteConfig.build.cssMinify](https://vitejs.dev/config/build-options.html#build-cssminify)
*
* 现在 minifyCss 不起作用
*/
minifyCss?: boolean;

/**
* @example
* { // 默认资源名是包的导入名
* 'element-plus/dist/index.css': pkg=>`https://unpkg.com/${pkg.name}@${pkg.version}/${pkg.resolveName}`,
* 'element-plus/dist/index.css': {
* resourceName: pkg=>pkg.importName,
* resourceUrl: pkg=>`https://unpkg.com/${pkg.name}@${pkg.version}/${pkg.resolveName}`,
* loader: pkg=>{ // 默认有支持 [css, json, vite支持的资源, ?url, ?raw] 后缀名文件的 loader
* const css = GM_getResourceText(pkg.resourceName);
* GM_addStyle(css);
* return css;
* },
* nodeLoader: pkg=>{
* return [
* `export default (()=>{`,
* `const css = GM_getResourceText(${JSON.stringify(pkg.resourceName)});`,
* `GM_addStyle(css);`,
* `return css;`,
* `})();`
* ].join('');
* },
* },
* 'element-plus/dist/index.css': [
* (version, name, importName, resolveName)=>importName,
* (version, name, importName, resolveName)=>`https://unpkg.com/${name}@${version}/${resolveName}`,
* // 向下兼容 externalGlobals cdn 函数,如果参数都是空字符串,插件会使用默认值
* ],
* 'element-plus/dist/index.css': cdn.jsdelivr(),
* }
*/
externalResource?: ExternalResource;

/**
* 当使用动态导入时,插件会使用 systemjs 构建你的代码
*
* `cdn.jsdelivr()[1]` 例子 -> [dynamic-import.user.js](https://github.com/lisonge/vite-plugin-monkey/blob/7645b185605faf9b48c43116db5ea01726188e03/playground/dynamic-import/dist/dynamic-import.user.js)
*
* `'inline'` 例子 -> [test-v3.user.js](https://github.com/lisonge/vite-plugin-monkey/blob/7645b185605faf9b48c43116db5ea01726188e03/playground/test-v3/dist/test-v3.user.js)
*
* @default
* cdn.jsdelivr()[1]
*/
systemjs?: 'inline' | ModuleToUrlFc;

/**
* @default
* const defaultFc = () => {
* return (e: string) => {
* if (typeof GM_addStyle == 'function') {
* GM_addStyle(e);
* return;
* }
* const o = document.createElement('style');
* o.textContent = e;
* document.head.append(o);
* };
* };
* @example
* const defaultFc1 = () => {
* return (e: string) => {
* const o = document.createElement('style');
* o.textContent = e;
* document.head.append(o);
* };
* };
* const defaultFc2 = (css:string)=>{
* const t = JSON.stringify(css)
* return `(e=>{const o=document.createElement("style");o.textContent=e,document.head.append(o)})(${t})`
* }
*/
cssSideEffects?: (
css: string,
) => IPromise<string | ((css: string) => void)>;
};
};

Refused to load the script

出现这个的原因是内容安全策略(CSP),只会在server时出现这个问题,下载插件Disable-CSPCSP Unblock

评论




站点访问量 Loading… 站点访客数 Loading…