Skip to content

Commit 7baf553

Browse files
authored
Merge pull request #6 from WindLeaf233/main
feat: add keyed resource header support
2 parents a458709 + 08fb516 commit 7baf553

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
"GM.xmlHttpRequest"
5151
],
5252
"exclude": [],
53-
"resources": []
53+
"resources": [],
54+
"keyedResources": {}
5455
},
5556
"dependencies": {
5657
"@trim21/gm-fetch": "^0.1.13",

plugins/userscript.plugin.ts

+10
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ interface UserScriptOptions {
3636
exclude: string[];
3737
require: string[];
3838
resources: string[];
39+
keyedResources: { [key: string]: string };
3940
connect: string[];
4041
'run-at': string;
4142
grant: string[];
@@ -209,6 +210,15 @@ export function generateHeader() {
209210
headers.push(`// @resource ${resource}`);
210211
}
211212
}
213+
// Add userscript header's resources.
214+
// Some of the resources should contain a specified name, for which userscripts can get value from it
215+
// eg. // @resource mycss http://link.to/some.css
216+
// Userscripts have the ability to apply css with `GM_addStyle(GM_getResourceText('mycss'))`
217+
if (userscript.keyedResources) {
218+
for (const dependencyName in userscript.keyedResources) {
219+
headers.push(`// @resource ${dependencyName} ${userscript.keyedResources[dependencyName]}`);
220+
}
221+
}
212222
// Add userscript header's connects.
213223
if (userscript.connect && userscript.connect instanceof Array) {
214224
for (const connect of userscript.connect) {

0 commit comments

Comments
 (0)