vite-userscript-plugin 1.10.0 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,10 +9,21 @@ declare type VMScriptRunAt =
9
9
  /** Injection mode of a script. */
10
10
  declare type VMScriptInjectInto = 'auto' | 'page' | 'content'
11
11
 
12
+ declare type GenericObject = Record<string, unknown>
13
+
12
14
  declare interface VMScriptGMInfoPlatform {
13
- arch: 'arm' | 'arm64' | 'x86-32' | 'x86-64' | 'mips' | 'mips64'
14
- /** `chrome`, `firefox` or whatever was returned by the API. */
15
- browserName: string
15
+ arch:
16
+ | 'aarch64'
17
+ | 'arm'
18
+ | 'arm64'
19
+ | 'mips'
20
+ | 'mips64'
21
+ | 'ppc64'
22
+ | 's390x'
23
+ | 'sparc64'
24
+ | 'x86-32'
25
+ | 'x86-64'
26
+ browserName: 'chrome' | 'firefox' | string
16
27
  browserVersion: string
17
28
  os: 'mac' | 'win' | 'android' | 'cros' | 'linux' | 'openbsd' | 'fuchsia'
18
29
  }
@@ -53,6 +64,10 @@ declare interface VMScriptGMInfoScriptMeta {
53
64
  declare interface VMScriptGMInfoObject {
54
65
  /** Unique ID of the script. */
55
66
  uuid: string
67
+ /** The injection mode of current script. */
68
+ injectInto: VMScriptInjectInto
69
+ /** Contains structured fields from the *Metadata Block*. */
70
+ script: VMScriptGMInfoScriptMeta
56
71
  /** The meta block of the script. */
57
72
  scriptMetaStr: string
58
73
  /** Whether the script will be updated automatically. */
@@ -68,10 +83,14 @@ declare interface VMScriptGMInfoObject {
68
83
  * extension API (`browser.runtime.getPlatformInfo` and `getBrowserInfo`).
69
84
  */
70
85
  platform: VMScriptGMInfoPlatform
71
- /** Contains structured fields from the *Metadata Block*. */
72
- script: VMScriptGMInfoScriptMeta
73
- /** The injection mode of current script. */
74
- injectInto: VMScriptInjectInto
86
+ /**
87
+ * A copy of navigator.userAgentData from the content script of the extension.
88
+ * @since VM2.20.2 */
89
+ userAgentData?: {
90
+ brands: { brand: string; version: string }[]
91
+ mobile: boolean
92
+ platform: string
93
+ }
75
94
  }
76
95
 
77
96
  /**
@@ -84,10 +103,18 @@ declare function GM_log(...args: any): void
84
103
 
85
104
  /** Retrieves a value for current script from storage. */
86
105
  declare function GM_getValue<T>(name: string, defaultValue?: T): T
106
+ /** @since VM2.19.1 */
107
+ declare function GM_getValues(names: string[]): GenericObject
108
+ /** @since VM2.19.1 */
109
+ declare function GM_getValues(namesWithDefaults: GenericObject): GenericObject
87
110
  /** Sets a key / value pair for current script to storage. */
88
111
  declare function GM_setValue<T>(name: string, value: T): void
112
+ /** @since VM2.19.1 */
113
+ declare function GM_setValues(values: GenericObject): void
89
114
  /** Deletes an existing key / value pair for current script from storage. */
90
115
  declare function GM_deleteValue(name: string): void
116
+ /** @since VM2.19.1 */
117
+ declare function GM_deleteValues(names: string[]): void
91
118
  /** Returns an array of keys of all available values within this script. */
92
119
  declare function GM_listValues(): string[]
93
120
 
@@ -214,13 +241,25 @@ declare function GM_openInTab(
214
241
 
215
242
  /**
216
243
  * Registers a command in Violentmonkey popup menu.
244
+ * Returns the command's id since VM2.12.5, see description of the `id` parameter.
217
245
  * If you want to add a shortcut, please see `@violentmonkey/shortcut`.
218
246
  */
219
247
  declare function GM_registerMenuCommand(
220
248
  /** The name to show in the popup menu. */
221
249
  caption: string,
222
250
  /** Callback function when the command is clicked in the menu. */
223
- onClick: (event: MouseEvent | KeyboardEvent) => void
251
+ onClick: (event: MouseEvent | KeyboardEvent) => void,
252
+ /** @since VM2.15.9 */
253
+ options?: {
254
+ /** Default: the `caption` parameter.
255
+ * In 2.15.9-2.16.1 the default was a randomly generated string. */
256
+ id?: string
257
+ /** A hint shown in the status bar when hovering the command. */
258
+ title?: string
259
+ /** Default: `true`.
260
+ * Whether to auto-close the popup after the user invoked the command. */
261
+ autoClose?: boolean
262
+ }
224
263
  ): string
225
264
  /** Unregisters a command which has been registered to Violentmonkey popup menu. */
226
265
  declare function GM_unregisterMenuCommand(
@@ -244,6 +283,30 @@ declare interface VMScriptGMNotificationOptions {
244
283
  title?: string
245
284
  /** URL of an image to show in the notification. */
246
285
  image?: string
286
+ /** No sounds/vibrations when showing the notification.
287
+ * @since VM2.15.2, Chrome 70. */
288
+ silent?: boolean
289
+ /**
290
+ * Unique name of the notification, e.g. 'abc', same as the web Notification API.
291
+ * Names are scoped to each userscript i.e. your tag won't clash with another script's tag.
292
+ * The purpose of a tagged notification is to replace an older notification with the same tag,
293
+ * even if it was shown in another tab (or before this tab was navigated elsewhere
294
+ * and your notification had `zombieTimeout`).
295
+ * @since VM2.15.4
296
+ */
297
+ tag?: string
298
+ /**
299
+ * Number of milliseconds to keep the notification after the userscript "dies",
300
+ * i.e. when its tab or frame is reloaded/closed/navigated. If not specified or invalid,
301
+ * the default behavior is to immediately remove the notifications.
302
+ * @since VM2.15.4
303
+ */
304
+ zombieTimeout?: number
305
+ /**
306
+ * URL to open when a zombie notification is clicked, see `zombieTimeout` for more info.
307
+ * @since VM2.16.1
308
+ */
309
+ zombieUrl?: string
247
310
  /** Callback when the notification is clicked by user. */
248
311
  onclick?: () => void
249
312
  /** Callback when the notification is closed, either by user or by system. */
@@ -408,10 +471,20 @@ declare interface VMScriptGMObjectVMExtensions {
408
471
  addElement: typeof GM_addElement
409
472
  addStyle: typeof GM_addStyle
410
473
  addValueChangeListener: typeof GM_addValueChangeListener
411
- download: typeof GM_download
474
+ /** @since VM2.19.1 */
475
+ deleteValues: (names: string[]) => Promise<void>
476
+ download:
477
+ | ((options: VMScriptGMDownloadOptions) => Promise<Blob> | void)
478
+ | ((url: string, name: string) => Promise<Blob> | void)
412
479
  getResourceText: typeof GM_getResourceText
480
+ /** @since VM2.19.1 */
481
+ getValues:
482
+ | ((names: string[]) => Promise<GenericObject>)
483
+ | ((namesWithDefaults: GenericObject) => Promise<GenericObject>)
413
484
  log: typeof GM_log
414
485
  removeValueChangeListener: typeof GM_removeValueChangeListener
486
+ /** @since VM2.19.1 */
487
+ setValues: (values: GenericObject) => Promise<void>
415
488
  unregisterMenuCommand: typeof GM_unregisterMenuCommand
416
489
  }
417
490
 
@@ -428,7 +501,9 @@ declare interface VMScriptGMObject extends VMScriptGMObjectVMExtensions {
428
501
  notification: typeof GM_notification
429
502
  openInTab: typeof GM_openInTab
430
503
  setClipboard: typeof GM_setClipboard
431
- xmlHttpRequest: typeof GM_xmlhttpRequest
504
+ xmlHttpRequest: <T = string | Blob | ArrayBuffer | Document | object>(
505
+ details: VMScriptGMXHRDetails<T>
506
+ ) => Promise<T> & VMScriptXHRControl
432
507
  }
433
508
 
434
509
  declare const GM: VMScriptGMObject
package/dist/index.cjs DELETED
@@ -1,5 +0,0 @@
1
- "use strict";var re=Object.create;var v=Object.defineProperty;var se=Object.getOwnPropertyDescriptor;var ne=Object.getOwnPropertyNames;var oe=Object.getPrototypeOf,ie=Object.prototype.hasOwnProperty;var ae=(e,t)=>{for(var r in t)v(e,r,{get:t[r],enumerable:!0})},E=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of ne(t))!ie.call(e,n)&&n!==r&&v(e,n,{get:()=>t[n],enumerable:!(s=se(t,n))||s.enumerable});return e};var j=(e,t,r)=>(r=e!=null?re(oe(e)):{},E(t||!e||!e.__esModule?v(r,"default",{value:e,enumerable:!0}):r,e)),le=e=>E(v({},"__esModule",{value:!0}),e);var ue={};ae(ue,{default:()=>K});module.exports=le(ue);var c=require("fs"),V=require("http"),p=require("path"),H=j(require("get-port"),1),W=j(require("open"),1),M=j(require("picocolors"),1),q=j(require("serve-handler"),1),z=require("vite"),B=require("websocket");var g=class{constructor(t){this.config=t;this.addHomepageMeta(),this.maxKeyLength=Math.max(...Object.keys(this.config).map(r=>r.length))+1}header=[];maxKeyLength;addHomepageMeta(){let t=this.config.homepage??this.config.homepageURL;t&&(this.config.updateURL=new URL(`${this.config.name}.meta.js`,t).href,this.config.downloadURL=new URL(`${this.config.name}.user.js`,t).href)}addSpaces(t){return" ".repeat(this.maxKeyLength-t.length)}addMetadata(t,r){r=Array.isArray(r)?r.join(" "):r===!0?"":r,this.header.push(`// @${t}${this.addSpaces(t)}${r}`)}generate(){for(let[t,r]of Object.entries(this.config))if(Array.isArray(r))r.forEach(s=>this.addMetadata(t,s));else{if(r===void 0)continue;this.addMetadata(t,r)}return["// ==UserScript==",...this.header,"// ==/UserScript=="].join(`
2
- `)}};var _=require("path"),D=require("url"),me={},L=(0,_.dirname)((0,D.fileURLToPath)(me.url)),$="vite-userscript-plugin",R='console.warn("__STYLE__")',N=new RegExp(/\.(t|j)sx?$/),C=new RegExp(/\.(s[ac]|c|le)ss$/),ce=["setValue","getValue","deleteValue","listValues","setClipboard","addStyle","addElement","addValueChangeListener","removeValueChangeListener","registerMenuCommand","unregisterMenuCommand","download","getTab","getTabs","saveTab","openInTab","notification","getResourceURL","getResourceText","xmlhttpRequest","log","info"],pe=["unsafeWindow","window.onurlchange","window.focus","window.close"],h=ce.map(e=>[`GM_${e}`,`GM.${e}`]).flat();h.push(...pe);var k=require("vite");function O(e){return[...new Set(Array.isArray(e)?e:e?[e]:[])]}async function y({minify:e,file:t,name:r,loader:s},n){let{code:d}=await(0,k.transformWithEsbuild)(t,r,{minify:e,loader:s,sourcemap:!1,legalComments:"none",...n});return d}function A(e){let t=[];for(let r of h)e.indexOf(r)!==-1&&t.push(r);return t}var U=class{styles=new Map;async add(t,r,s){let n=await y({name:t,file:r,minify:s,loader:"css"});return this.styles.set(t,n.replace(`
3
- `,"")),""}inject(){return this.styles.size?`GM_addStyle(\`${[...this.styles.values()].join("")}\`)`:void 0}merge(t){let r=[];for(let s of t){let n=this.styles.get(s);n&&r.push([s,n])}this.styles.clear(),r.forEach(s=>this.styles.set(...s))}},S=new U;function K(e){try{let t,r,s=null,n=e.fileName??e.header.name,d=(0,z.createLogger)("info",{prefix:`[${$}]`,allowClearScreen:!0}),w=(0,V.createServer)((o,i)=>(0,q.default)(o,i,{public:t.build.outDir})),I=B.server;return new I({httpServer:w}).on("request",o=>{s=o.accept(null,o.origin)}),{name:$,apply:"build",config(){return{build:{target:"esnext",minify:!1,lib:{name:n,entry:e.entry,formats:["iife"],fileName:()=>`${n}.js`},rollupOptions:{output:{extend:!0}}}}},async configResolved(o){t=o,r=o.build.watch??!1,e.entry=(0,p.resolve)(o.root,e.entry),Array.from(["match","require","include","exclude","resource","connect"]).forEach(i=>{let a=e.header[i];e.header[i]=O(a)}),e.server={port:await(0,H.default)(),open:!1,...e.server}},async transform(o,i){let a=o;return C.test(i)&&(a=await S.add(i,a,!r)),i.includes(e.entry)&&(a=o+R),{code:a,map:null}},generateBundle(o,i){for(let a of Object.values(i)){if(a.type==="asset")continue;let m=Object.keys(a.modules).filter(u=>C.test(u));m.length&&S.merge(m)}},async writeBundle(o,i){let{open:a,port:m}=e.server,u=o.sanitizeFileName(n),J=`${u}.user.js`,G=`${u}.proxy.user.js`,Y=`${u}.meta.js`;for(let[f]of Object.entries(i))if(N.test(f)){let x=t.root,b=t.build.outDir,P=(0,p.resolve)(x,b,f),Q=(0,p.resolve)(x,b,J),X=(0,p.resolve)(x,b,G),Z=(0,p.resolve)(x,b,Y),T=(0,p.resolve)(L,`ws-${u}.js`);try{let l=(0,c.readFileSync)(P,"utf8");if(l=l.replace(R,`${S.inject()}`),l=await y({minify:!r,file:l,name:f,loader:"js"},e.esbuildTransformOptions),e.header.grant=O(r?h:[...A(l),...e.header.grant??[]]),r){let ee=(0,c.readFileSync)((0,p.resolve)(L,"ws.js"),"utf8"),te=await y({minify:!r,file:ee.replace("__WS__",`ws://localhost:${m}`),name:T,loader:"js"},e.esbuildTransformOptions);(0,c.writeFileSync)(T,te),(0,c.writeFileSync)(X,new g({...e.header,require:[...e.header.require??[],"file://"+T,"file://"+P]}).generate())}let F=new g(e.header).generate();(0,c.writeFileSync)(P,l),(0,c.writeFileSync)(Z,F),(0,c.writeFileSync)(Q,`${F}
4
-
5
- ${l}`)}catch(l){console.log(l)}}if(r&&!w.listening){let f=`http://localhost:${m}`;w.listen(m,()=>{d.clearScreen("info"),d.info(M.default.bold(`${M.default.cyan(">>> [vite-userscript-plugin]")} ${M.default.gray(f)}`))}),a&&await(0,W.default)(`${f}/${G}`)}else r||(w.close(),process.exit(0))},buildEnd(){r&&(d.clearScreen("info"),s&&s.sendUTF(JSON.stringify({message:"reload"})))}}}catch(t){return console.error(t),{name:$}}}
package/dist/index.d.cts DELETED
@@ -1,187 +0,0 @@
1
- import { EsbuildTransformOptions, PluginOption } from 'vite';
2
-
3
- declare const GM: readonly ["setValue", "getValue", "deleteValue", "listValues", "setClipboard", "addStyle", "addElement", "addValueChangeListener", "removeValueChangeListener", "registerMenuCommand", "unregisterMenuCommand", "download", "getTab", "getTabs", "saveTab", "openInTab", "notification", "getResourceURL", "getResourceText", "xmlhttpRequest", "log", "info"];
4
- declare const GMwindow: readonly ["unsafeWindow", "window.onurlchange", "window.focus", "window.close"];
5
-
6
- type RunAt = 'document-start' | 'document-body' | 'document-end' | 'document-idle' | 'context-menu';
7
- type GMLiterals<T extends string> = [`GM_${T}` | `GM.${T}`];
8
- type GMWindow = typeof GMwindow[number];
9
- type Grants = GMWindow | GMLiterals<typeof GM[number]>[number];
10
- type HeaderConfig = {
11
- [property: string]: any;
12
- /**
13
- * @see https://www.tampermonkey.net/documentation.php#meta:name
14
- */
15
- name: string;
16
- /**
17
- * @see https://www.tampermonkey.net/documentation.php#meta:namespace
18
- */
19
- namespace?: string;
20
- /**
21
- * @see https://www.tampermonkey.net/documentation.php#meta:copyright
22
- */
23
- copyright?: string;
24
- /**
25
- * @see https://www.tampermonkey.net/documentation.php#meta:version
26
- */
27
- version: string;
28
- /**
29
- * @see https://www.tampermonkey.net/documentation.php#meta:description
30
- */
31
- description?: string;
32
- /**
33
- * @see https://www.tampermonkey.net/documentation.php#meta:icon
34
- */
35
- icon?: string;
36
- /**
37
- * @see https://www.tampermonkey.net/documentation.php#meta:icon
38
- */
39
- iconURL?: string;
40
- /**
41
- * @see https://www.tampermonkey.net/documentation.php#meta:icon
42
- */
43
- defaulticon?: string;
44
- /**
45
- * @see https://www.tampermonkey.net/documentation.php#meta:icon64
46
- */
47
- icon64?: string;
48
- /**
49
- * @see https://www.tampermonkey.net/documentation.php#meta:icon64
50
- */
51
- icon64URL?: string;
52
- /**
53
- * @see https://www.tampermonkey.net/documentation.php#meta:grant
54
- */
55
- grant?: Grants[];
56
- /**
57
- * @see https://www.tampermonkey.net/documentation.php#meta:author
58
- */
59
- author?: string;
60
- /**
61
- * @see https://www.tampermonkey.net/documentation.php#meta:homepage
62
- */
63
- homepage?: string;
64
- /**
65
- * @see https://www.tampermonkey.net/documentation.php#meta:homepage
66
- */
67
- homepageURL?: string;
68
- /**
69
- * @see https://www.tampermonkey.net/documentation.php#meta:homepage
70
- */
71
- website?: string;
72
- /**
73
- * @see https://www.tampermonkey.net/documentation.php#meta:homepage
74
- */
75
- source?: string;
76
- /**
77
- * @see https://www.tampermonkey.net/documentation.phpmeta:antifeature
78
- */
79
- antifeature?: [type: string, description: string][];
80
- /**
81
- * @see https://www.tampermonkey.net/documentation.php#meta:require
82
- */
83
- require?: string[] | string;
84
- /**
85
- * @see https://www.tampermonkey.net/documentation.php#meta:resource
86
- */
87
- resource?: [key: string, value: string][];
88
- /**
89
- * @see https://www.tampermonkey.net/documentation.php#meta:include
90
- */
91
- include?: string[] | string;
92
- /**
93
- * @see https://www.tampermonkey.net/documentation.php#meta:match
94
- * @see https://violentmonkey.github.io/api/metadata-block/#match--exclude-match
95
- */
96
- match: string[] | string;
97
- /**
98
- * @see https://violentmonkey.github.io/api/metadata-block/#match--exclude-match
99
- */
100
- 'exclude-match'?: string[] | string;
101
- /**
102
- * @see https://www.tampermonkey.net/documentation.php#meta:exclude
103
- */
104
- exclude?: string[] | string;
105
- /**
106
- * @see https://www.tampermonkey.net/documentation.php#meta:run_at
107
- */
108
- 'run-at'?: RunAt;
109
- /**
110
- * @see https://www.tampermonkey.net/documentation.phpmeta:sandbox
111
- */
112
- sandbox?: string;
113
- /**
114
- * @see https://www.tampermonkey.net/documentation.php#meta:connect
115
- */
116
- connect?: string[] | string;
117
- /**
118
- * @see https://www.tampermonkey.net/documentation.php#meta:noframes
119
- */
120
- noframes?: boolean;
121
- /**
122
- * @see https://www.tampermonkey.net/documentation.php#meta:updateURL
123
- */
124
- updateURL?: string;
125
- /**
126
- * @see https://www.tampermonkey.net/documentation.php#meta:downloadURL
127
- */
128
- downloadURL?: string;
129
- /**
130
- * @see https://www.tampermonkey.net/documentation.php#meta:supportURL
131
- */
132
- supportURL?: string;
133
- /**
134
- * @see https://www.tampermonkey.net/documentation.php#meta:webRequest
135
- */
136
- webRequest?: string[];
137
- /**
138
- * @see https://www.tampermonkey.net/documentation.php#meta:unwrap
139
- */
140
- unwrap?: boolean;
141
- };
142
- interface ServerConfig {
143
- /**
144
- * {@link https://github.com/sindresorhus/get-port}
145
- */
146
- port?: number;
147
- /**
148
- * @default false
149
- */
150
- open?: boolean;
151
- }
152
- interface UserscriptPluginConfig {
153
- /**
154
- * Path of userscript entry.
155
- */
156
- entry: string;
157
- /**
158
- * Userscript file name.
159
- */
160
- fileName?: string;
161
- /**
162
- * Userscript header config.
163
- *
164
- * @see https://www.tampermonkey.net/documentation.php
165
- */
166
- header: HeaderConfig;
167
- /**
168
- * Server config.
169
- */
170
- server?: ServerConfig;
171
- /**
172
- * Override default esbuild transform options.
173
- *
174
- * @default
175
- * ```json
176
- * {
177
- * "minify": true,
178
- * "legalComments": "none"
179
- * }
180
- * ```
181
- */
182
- esbuildTransformOptions?: Omit<EsbuildTransformOptions, 'format' | 'target' | 'loader' | 'sourcemap'>;
183
- }
184
-
185
- declare function UserscriptPlugin(config: UserscriptPluginConfig): PluginOption;
186
-
187
- export { UserscriptPluginConfig, UserscriptPlugin as default };