vite-userscript-plugin 1.6.3 → 1.6.5
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.
- package/dist/index.cjs +4 -4
- package/dist/index.d.ts +5 -5
- package/dist/index.js +4 -4
- package/package.json +11 -11
- package/types/violentmonkey.d.ts +100 -42
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`)}};function
|
|
3
|
-
`,"")),""}inject(){return this.styles.size?`GM_addStyle(\`${[...this.styles.values()].join("")}\`)`:void 0}merge(
|
|
1
|
+
"use strict";var te=Object.create;var g=Object.defineProperty;var re=Object.getOwnPropertyDescriptor;var ne=Object.getOwnPropertyNames;var se=Object.getPrototypeOf,oe=Object.prototype.hasOwnProperty;var ie=(e,t,r)=>t in e?g(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var ae=(e,t)=>{for(var r in t)g(e,r,{get:t[r],enumerable:!0})},O=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ne(t))!oe.call(e,o)&&o!==r&&g(e,o,{get:()=>t[o],enumerable:!(n=re(t,o))||n.enumerable});return e};var h=(e,t,r)=>(r=e!=null?te(se(e)):{},O(t||!e||!e.__esModule?g(r,"default",{value:e,enumerable:!0}):r,e)),le=e=>O(g({},"__esModule",{value:!0}),e);var d=(e,t,r)=>(ie(e,typeof t!="symbol"?t+"":t,r),r);var me={};ae(me,{default:()=>I});module.exports=le(me);var c=require("fs"),K=require("http"),a=require("path"),A=require("url"),H=h(require("get-port"),1),W=h(require("open"),1),_=h(require("picocolors"),1),q=h(require("sanitize-filename"),1),B=h(require("serve-handler"),1),N=require("vite"),z=require("websocket");var y=class{constructor(t){this.config=t;d(this,"header",[]);d(this,"configKeys");d(this,"maxKeyLength");this.downloadMeta(),this.configKeys=Object.keys(this.config),this.maxKeyLength=Math.max(...this.configKeys.map(r=>r.length))+1}downloadMeta(){let{name:t,homepage:r,updateURL:n,downloadURL:o}=this.config;r&&!n&&!o&&(this.config.updateURL=new URL(`${t}.meta.js`,r).href,this.config.downloadURL=new URL(`${t}.user.js`,r).href)}addSpaces(t){return" ".repeat(this.maxKeyLength-t.length)}addMetadata(t,r){let n=typeof r=="boolean";n&&!r||(r=n?"":`${this.addSpaces(t)}${r}`,this.header.push(`// @${t}${r}`))}generate(){for(let[t,r]of Object.entries(this.config))if(Array.isArray(r))r.forEach(n=>this.addMetadata(t,n));else{if(r===void 0)continue;this.addMetadata(t,r)}return["// ==UserScript==",...this.header,"// ==/UserScript=="].join(`
|
|
2
|
+
`)}};function E({entry:e,header:t}){return{build:{lib:{entry:e,name:t.name,formats:["iife"],fileName:()=>`${t.name}.js`},rollupOptions:{output:{extend:!0}}}}}var L='console.warn("__STYLE__")',k=new RegExp(/\.(t|j)sx?$/),M=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"],w=ce.map(e=>[`GM_${e}`,`GM.${e}`]).flat();w.push(...pe);var V=require("vite");function P(e){return[...new Set(Array.isArray(e)?e:e?[e]:[])]}async function x({file:e,name:t,loader:r}){let{code:n}=await(0,V.transformWithEsbuild)(e,t,{loader:r,minify:!0,sourcemap:!1,legalComments:"none"});return n}function D(e){let t=[];for(let r of w)e.indexOf(r)!==-1&&t.push(r);return t}var G=class{constructor(){d(this,"styles",new Map)}async add(t,r){let n=await x({file:t,name:r,loader:"css"});return this.styles.set(r,n.replace(`
|
|
3
|
+
`,"")),""}inject(){return this.styles.size?`GM_addStyle(\`${[...this.styles.values()].join("")}\`)`:void 0}merge(t){let r=[];for(let n of t){let o=this.styles.get(n);!o||r.push([n,o])}this.styles.clear(),r.forEach(n=>this.styles.set(...n))}},$=new G;var de={};function I(e){let t,r,n=null,o=(0,a.dirname)((0,A.fileURLToPath)(de.url)),S=(0,N.createLogger)("info",{prefix:"[vite-userscript-plugin]",allowClearScreen:!0}),v=(0,K.createServer)((s,i)=>(0,B.default)(s,i,{public:t.build.outDir})),J=z.server;return new J({httpServer:v}).on("request",s=>{n=s.accept(null,s.origin)}),{name:"vite-userscript-plugin",apply:"build",config(){return E(e)},async configResolved(s){t=s,r=s.build.watch??!1,e.entry=(0,a.resolve)(s.root,e.entry),e.header.name=(0,q.default)(e.header.name),Array.from(["match","require","include","exclude","resource","connect"]).forEach(i=>{let p=e.header[i];e.header[i]=P(p)}),e.server={port:await(0,H.default)(),open:!1,...e.server}},async transform(s,i){let p=s;return M.test(i)&&(p=await $.add(s,i)),i.includes(e.entry)&&(p=s+L),{code:p,map:null}},generateBundle(s,i){for(let[p,f]of Object.entries(i)){let u=Object.keys(f.modules).filter(C=>M.test(C));u.length&&$.merge(u)}},async writeBundle(s,i){let{open:p,port:f}=e.server,T=`${e.header.name}.user.js`,u=`${e.header.name}.proxy.user.js`,C=`${e.header.name}.meta.js`;for(let[m]of Object.entries(i))if(k.test(m)){let b=t.root,j=t.build.outDir,R=(0,a.resolve)(b,j,m),Y=(0,a.resolve)(b,j,T),Q=(0,a.resolve)(b,j,u),X=(0,a.resolve)(b,j,C),U=(0,a.resolve)(o,`ws-${e.header.name}.js`);try{let l=(0,c.readFileSync)(R,"utf8");if(l=l.replace(L,`${$.inject()}`),l=await x({file:l,name:m,loader:"js"}),e.header.grant=P(r?w:[...D(l),...e.header.grant??[]]),r){let Z=(0,c.readFileSync)((0,a.resolve)(o,"ws.js"),"utf8"),ee=await x({file:Z.replace("__WS__",`ws://localhost:${f}`),name:U,loader:"js"});(0,c.writeFileSync)(U,ee),(0,c.writeFileSync)(Q,new y({...e.header,require:[...e.header.require,"file://"+U,"file://"+R]}).generate())}let F=new y(e.header).generate();(0,c.writeFileSync)(R,l),(0,c.writeFileSync)(X,F),(0,c.writeFileSync)(Y,`${F}
|
|
4
4
|
|
|
5
|
-
${l}`)}catch(l){console.log(l)}}if(
|
|
5
|
+
${l}`)}catch(l){console.log(l)}}if(r&&!v.listening){let m=`http://localhost:${f}`;v.listen(f,()=>{S.clearScreen("info"),S.info(_.default.blue(`Running at: ${_.default.gray(m)}`))}),p&&await(0,W.default)(`${m}/${u}`)}else r||(v.close(),process.exit(0))},buildEnd(){r&&(S.clearScreen("info"),n&&n.sendUTF(JSON.stringify({message:"reload"})))}}}0&&(module.exports={});
|
package/dist/index.d.ts
CHANGED
|
@@ -3,11 +3,11 @@ import { PluginOption } from 'vite';
|
|
|
3
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
4
|
declare const GMwindow: readonly ["unsafeWindow", "window.onurlchange", "window.focus", "window.close"];
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
11
|
[property: string]: string | boolean | number | string[] | undefined;
|
|
12
12
|
/**
|
|
13
13
|
* The name of the script.
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
`)}};function
|
|
3
|
-
`,"")),""}inject(){return this.styles.size?`GM_addStyle(\`${[...this.styles.values()].join("")}\`)`:void 0}merge(r){let t=[];for(let n of r){let l=this.styles.get(n);!l||t.push([n,l])}this.styles.clear(),t.forEach(n=>this.styles.set(...n))}},b=new
|
|
1
|
+
var W=Object.defineProperty;var q=(e,r,t)=>r in e?W(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t;var m=(e,r,t)=>(q(e,typeof r!="symbol"?r+"":r,t),t);import{readFileSync as O,writeFileSync as y}from"fs";import{createServer as I}from"http";import{dirname as J,resolve as c}from"path";import{fileURLToPath as Y}from"url";import Q from"get-port";import X from"open";import E from"picocolors";import Z from"sanitize-filename";import ee from"serve-handler";import{createLogger as te}from"vite";import{server as re}from"websocket";var u=class{constructor(r){this.config=r;m(this,"header",[]);m(this,"configKeys");m(this,"maxKeyLength");this.downloadMeta(),this.configKeys=Object.keys(this.config),this.maxKeyLength=Math.max(...this.configKeys.map(t=>t.length))+1}downloadMeta(){let{name:r,homepage:t,updateURL:n,downloadURL:l}=this.config;t&&!n&&!l&&(this.config.updateURL=new URL(`${r}.meta.js`,t).href,this.config.downloadURL=new URL(`${r}.user.js`,t).href)}addSpaces(r){return" ".repeat(this.maxKeyLength-r.length)}addMetadata(r,t){let n=typeof t=="boolean";n&&!t||(t=n?"":`${this.addSpaces(r)}${t}`,this.header.push(`// @${r}${t}`))}generate(){for(let[r,t]of Object.entries(this.config))if(Array.isArray(t))t.forEach(n=>this.addMetadata(r,n));else{if(t===void 0)continue;this.addMetadata(r,t)}return["// ==UserScript==",...this.header,"// ==/UserScript=="].join(`
|
|
2
|
+
`)}};function _({entry:e,header:r}){return{build:{lib:{entry:e,name:r.name,formats:["iife"],fileName:()=>`${r.name}.js`},rollupOptions:{output:{extend:!0}}}}}var R='console.warn("__STYLE__")',T=new RegExp(/\.(t|j)sx?$/),U=new RegExp(/\.(s[ac]|c|le)ss$/),B=["setValue","getValue","deleteValue","listValues","setClipboard","addStyle","addElement","addValueChangeListener","removeValueChangeListener","registerMenuCommand","unregisterMenuCommand","download","getTab","getTabs","saveTab","openInTab","notification","getResourceURL","getResourceText","xmlhttpRequest","log","info"],N=["unsafeWindow","window.onurlchange","window.focus","window.close"],g=B.map(e=>[`GM_${e}`,`GM.${e}`]).flat();g.push(...N);import{transformWithEsbuild as z}from"vite";function L(e){return[...new Set(Array.isArray(e)?e:e?[e]:[])]}async function h({file:e,name:r,loader:t}){let{code:n}=await z(e,r,{loader:t,minify:!0,sourcemap:!1,legalComments:"none"});return n}function F(e){let r=[];for(let t of g)e.indexOf(t)!==-1&&r.push(t);return r}var M=class{constructor(){m(this,"styles",new Map)}async add(r,t){let n=await h({file:r,name:t,loader:"css"});return this.styles.set(t,n.replace(`
|
|
3
|
+
`,"")),""}inject(){return this.styles.size?`GM_addStyle(\`${[...this.styles.values()].join("")}\`)`:void 0}merge(r){let t=[];for(let n of r){let l=this.styles.get(n);!l||t.push([n,l])}this.styles.clear(),t.forEach(n=>this.styles.set(...n))}},b=new M;function ne(e){let r,t,n=null,l=J(Y(import.meta.url)),j=te("info",{prefix:"[vite-userscript-plugin]",allowClearScreen:!0}),w=I((s,o)=>ee(s,o,{public:r.build.outDir})),k=re;return new k({httpServer:w}).on("request",s=>{n=s.accept(null,s.origin)}),{name:"vite-userscript-plugin",apply:"build",config(){return _(e)},async configResolved(s){r=s,t=s.build.watch??!1,e.entry=c(s.root,e.entry),e.header.name=Z(e.header.name),Array.from(["match","require","include","exclude","resource","connect"]).forEach(o=>{let a=e.header[o];e.header[o]=L(a)}),e.server={port:await Q(),open:!1,...e.server}},async transform(s,o){let a=s;return U.test(o)&&(a=await b.add(s,o)),o.includes(e.entry)&&(a=s+R),{code:a,map:null}},generateBundle(s,o){for(let[a,d]of Object.entries(o)){let f=Object.keys(d.modules).filter($=>U.test($));f.length&&b.merge(f)}},async writeBundle(s,o){let{open:a,port:d}=e.server,P=`${e.header.name}.user.js`,f=`${e.header.name}.proxy.user.js`,$=`${e.header.name}.meta.js`;for(let[p]of Object.entries(o))if(T.test(p)){let x=r.root,v=r.build.outDir,S=c(x,v,p),V=c(x,v,P),D=c(x,v,f),K=c(x,v,$),C=c(l,`ws-${e.header.name}.js`);try{let i=O(S,"utf8");if(i=i.replace(R,`${b.inject()}`),i=await h({file:i,name:p,loader:"js"}),e.header.grant=L(t?g:[...F(i),...e.header.grant??[]]),t){let A=O(c(l,"ws.js"),"utf8"),H=await h({file:A.replace("__WS__",`ws://localhost:${d}`),name:C,loader:"js"});y(C,H),y(D,new u({...e.header,require:[...e.header.require,"file://"+C,"file://"+S]}).generate())}let G=new u(e.header).generate();y(S,i),y(K,G),y(V,`${G}
|
|
4
4
|
|
|
5
|
-
${i}`)}catch(i){console.log(i)}}if(t&&!
|
|
5
|
+
${i}`)}catch(i){console.log(i)}}if(t&&!w.listening){let p=`http://localhost:${d}`;w.listen(d,()=>{j.clearScreen("info"),j.info(E.blue(`Running at: ${E.gray(p)}`))}),a&&await X(`${p}/${f}`)}else t||(w.close(),process.exit(0))},buildEnd(){t&&(j.clearScreen("info"),n&&n.sendUTF(JSON.stringify({message:"reload"})))}}}export{ne as default};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-userscript-plugin",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -39,22 +39,22 @@
|
|
|
39
39
|
"open": "^8.4.0",
|
|
40
40
|
"picocolors": "^1.0.0",
|
|
41
41
|
"sanitize-filename": "^1.6.3",
|
|
42
|
-
"serve-handler": "^6.1.
|
|
42
|
+
"serve-handler": "^6.1.5",
|
|
43
43
|
"websocket": "^1.0.34"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@crashmax/prettier-config": "^2.0
|
|
46
|
+
"@crashmax/prettier-config": "^2.1.0",
|
|
47
47
|
"@crashmax/tsconfig": "^1.0.2",
|
|
48
|
-
"@types/node": "^18.
|
|
48
|
+
"@types/node": "^18.11.9",
|
|
49
49
|
"@types/serve-handler": "^6.1.1",
|
|
50
50
|
"@types/websocket": "^1.0.5",
|
|
51
|
-
"@vitest/ui": "^0.
|
|
52
|
-
"tsup": "^6.
|
|
53
|
-
"turbo": "^1.
|
|
54
|
-
"typescript": "^4.
|
|
55
|
-
"vite": "^3.
|
|
56
|
-
"vite-plugin-dts": "^1.
|
|
57
|
-
"vitest": "^0.
|
|
51
|
+
"@vitest/ui": "^0.25.3",
|
|
52
|
+
"tsup": "^6.5.0",
|
|
53
|
+
"turbo": "^1.6.3",
|
|
54
|
+
"typescript": "^4.9.3",
|
|
55
|
+
"vite": "^3.2.4",
|
|
56
|
+
"vite-plugin-dts": "^1.7.1",
|
|
57
|
+
"vitest": "^0.25.3"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
60
|
"vite": ">=2.9.0"
|
package/types/violentmonkey.d.ts
CHANGED
|
@@ -17,15 +17,36 @@ declare interface VMScriptGMInfoPlatform {
|
|
|
17
17
|
os: 'mac' | 'win' | 'android' | 'cros' | 'linux' | 'openbsd' | 'fuchsia'
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* GM_info.script and GM.info.script
|
|
22
|
+
* Non-optional string property will be an empty string '' if omitted.
|
|
23
|
+
*/
|
|
20
24
|
declare interface VMScriptGMInfoScriptMeta {
|
|
25
|
+
antifeature?: string[]
|
|
26
|
+
author?: string
|
|
27
|
+
compatible?: string[]
|
|
28
|
+
connect?: string[]
|
|
21
29
|
description: string
|
|
30
|
+
downloadURL?: string
|
|
31
|
+
excludeMatches: string[]
|
|
22
32
|
excludes: string[]
|
|
33
|
+
/** Empty is the same as `@grant none` */
|
|
34
|
+
grant: string[]
|
|
35
|
+
/** Use homepageURL instead */
|
|
36
|
+
homepage?: string
|
|
37
|
+
homepageURL?: string
|
|
38
|
+
icon?: string
|
|
23
39
|
includes: string[]
|
|
24
40
|
matches: string[]
|
|
25
41
|
name: string
|
|
26
42
|
namespace: string
|
|
27
|
-
|
|
28
|
-
|
|
43
|
+
noframes?: boolean
|
|
44
|
+
require: string[]
|
|
45
|
+
resources: { name: string; url: string }[]
|
|
46
|
+
runAt: VMScriptRunAt | ''
|
|
47
|
+
supportURL?: string
|
|
48
|
+
unwrap?: boolean
|
|
49
|
+
updateURL?: string
|
|
29
50
|
version: string
|
|
30
51
|
}
|
|
31
52
|
|
|
@@ -58,6 +79,9 @@ declare interface VMScriptGMInfoObject {
|
|
|
58
79
|
*/
|
|
59
80
|
declare const GM_info: VMScriptGMInfoObject
|
|
60
81
|
|
|
82
|
+
/** The original console.log */
|
|
83
|
+
declare function GM_log(...args: any): void
|
|
84
|
+
|
|
61
85
|
/** Retrieves a value for current script from storage. */
|
|
62
86
|
declare function GM_getValue<T>(name: string, defaultValue?: T): T
|
|
63
87
|
/** Sets a key / value pair for current script to storage. */
|
|
@@ -196,7 +220,7 @@ declare function GM_registerMenuCommand(
|
|
|
196
220
|
/** The name to show in the popup menu. */
|
|
197
221
|
caption: string,
|
|
198
222
|
/** Callback function when the command is clicked in the menu. */
|
|
199
|
-
onClick: (event: MouseEvent) => void
|
|
223
|
+
onClick: (event: MouseEvent | KeyboardEvent) => void
|
|
200
224
|
): string
|
|
201
225
|
/** Unregisters a command which has been registered to Violentmonkey popup menu. */
|
|
202
226
|
declare function GM_unregisterMenuCommand(
|
|
@@ -264,30 +288,47 @@ declare type VMScriptResponseType =
|
|
|
264
288
|
| 'arraybuffer'
|
|
265
289
|
| 'document'
|
|
266
290
|
|
|
291
|
+
/**
|
|
292
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest#properties
|
|
293
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/ProgressEvent#properties
|
|
294
|
+
*/
|
|
267
295
|
declare interface VMScriptResponseObject<T> {
|
|
268
296
|
status: number
|
|
269
297
|
statusText: string
|
|
270
298
|
readyState: number
|
|
271
299
|
responseHeaders: string
|
|
272
|
-
response: T
|
|
273
|
-
responseText: string |
|
|
300
|
+
response: T | null
|
|
301
|
+
responseText: string | undefined
|
|
302
|
+
responseXML: Document | null
|
|
274
303
|
/** The final URL after redirection. */
|
|
275
304
|
finalUrl: string
|
|
305
|
+
lengthComputable?: boolean
|
|
306
|
+
loaded?: number
|
|
307
|
+
total?: number
|
|
276
308
|
/** The same `context` object you specified in `details`. */
|
|
277
309
|
context?: unknown
|
|
278
310
|
}
|
|
279
311
|
|
|
280
|
-
|
|
312
|
+
type TypedArray =
|
|
313
|
+
| Uint8Array
|
|
314
|
+
| Uint8ClampedArray
|
|
315
|
+
| Uint16Array
|
|
316
|
+
| Uint32Array
|
|
317
|
+
| Int8Array
|
|
318
|
+
| Int16Array
|
|
319
|
+
| Int32Array
|
|
320
|
+
| BigUint64Array
|
|
321
|
+
| BigInt64Array
|
|
322
|
+
| Float32Array
|
|
323
|
+
| Float64Array
|
|
324
|
+
|
|
325
|
+
interface GMRequestBase<T> {
|
|
281
326
|
/** URL relative to current page is also allowed. */
|
|
282
327
|
url: string
|
|
283
|
-
/** HTTP method, default as `GET`. */
|
|
284
|
-
method?: string
|
|
285
328
|
/** User for authentication. */
|
|
286
329
|
user?: string
|
|
287
330
|
/** Password for authentication. */
|
|
288
331
|
password?: string
|
|
289
|
-
/** A MIME type to specify with the request. */
|
|
290
|
-
overrideMimeType?: string
|
|
291
332
|
/**
|
|
292
333
|
* Some special headers are also allowed:
|
|
293
334
|
*
|
|
@@ -298,22 +339,8 @@ declare interface VMScriptGMXHRDetails<T> {
|
|
|
298
339
|
* - `User-Agent`
|
|
299
340
|
*/
|
|
300
341
|
headers?: Record<string, string>
|
|
301
|
-
/**
|
|
302
|
-
* One of the following:
|
|
303
|
-
*
|
|
304
|
-
* - `text` (default value)
|
|
305
|
-
* - `json`
|
|
306
|
-
* - `blob`
|
|
307
|
-
* - `arraybuffer`
|
|
308
|
-
* - `document`
|
|
309
|
-
*/
|
|
310
|
-
responseType?: VMScriptResponseType
|
|
311
342
|
/** Time to wait for the request, none by default. */
|
|
312
343
|
timeout?: number
|
|
313
|
-
/** Data to send with the request, usually for `POST` and `PUT` requests. */
|
|
314
|
-
data?: string | FormData | Blob
|
|
315
|
-
/** Send the `data` string as a `blob`. This is for compatibility with Tampermonkey/Greasemonkey, where only `string` type is allowed in `data`. */
|
|
316
|
-
binary?: boolean
|
|
317
344
|
/** Can be an object and will be assigned to context of the response object. */
|
|
318
345
|
context?: unknown
|
|
319
346
|
/** When set to `true`, no cookie will be sent with the request and the response cookies will be ignored. The default value is `false`. */
|
|
@@ -328,23 +355,43 @@ declare interface VMScriptGMXHRDetails<T> {
|
|
|
328
355
|
ontimeout?: (resp: VMScriptResponseObject<T>) => void
|
|
329
356
|
}
|
|
330
357
|
|
|
358
|
+
declare interface VMScriptGMXHRDetails<T> extends GMRequestBase<T> {
|
|
359
|
+
/** HTTP method, default as `GET`. */
|
|
360
|
+
method?: string
|
|
361
|
+
/** A MIME type to specify with the request. */
|
|
362
|
+
overrideMimeType?: string
|
|
363
|
+
/**
|
|
364
|
+
* One of the following:
|
|
365
|
+
*
|
|
366
|
+
* - `text` (default value)
|
|
367
|
+
* - `json`
|
|
368
|
+
* - `blob`
|
|
369
|
+
* - `arraybuffer`
|
|
370
|
+
* - `document`
|
|
371
|
+
*/
|
|
372
|
+
responseType?: VMScriptResponseType
|
|
373
|
+
/** Data to send with the request, usually for `POST` and `PUT` requests. */
|
|
374
|
+
data?:
|
|
375
|
+
| string
|
|
376
|
+
| ArrayBuffer
|
|
377
|
+
| Blob
|
|
378
|
+
| DataView
|
|
379
|
+
| FormData
|
|
380
|
+
| ReadableStream
|
|
381
|
+
| TypedArray
|
|
382
|
+
| URLSearchParams
|
|
383
|
+
/** Send the `data` string as a `blob`. This is for compatibility with Tampermonkey/Greasemonkey, where only `string` type is allowed in `data`. */
|
|
384
|
+
binary?: boolean
|
|
385
|
+
}
|
|
386
|
+
|
|
331
387
|
/** Makes a request like XMLHttpRequest, with some special capabilities, not restricted by same-origin policy. */
|
|
332
|
-
declare function GM_xmlhttpRequest<
|
|
333
|
-
|
|
334
|
-
): VMScriptXHRControl
|
|
388
|
+
declare function GM_xmlhttpRequest<
|
|
389
|
+
T = string | Blob | ArrayBuffer | Document | object
|
|
390
|
+
>(details: VMScriptGMXHRDetails<T>): VMScriptXHRControl
|
|
335
391
|
|
|
336
|
-
declare interface VMScriptGMDownloadOptions {
|
|
337
|
-
/** The URL to download. */
|
|
338
|
-
url: string
|
|
392
|
+
declare interface VMScriptGMDownloadOptions extends GMRequestBase<Blob> {
|
|
339
393
|
/** The filename to save as. */
|
|
340
|
-
name
|
|
341
|
-
/** The function to call when download starts successfully. */
|
|
342
|
-
onload?: () => void
|
|
343
|
-
headers?: Record<string, string>
|
|
344
|
-
timeout?: number
|
|
345
|
-
onerror?: (resp: VMScriptResponseObject<Blob>) => void
|
|
346
|
-
onprogress?: (resp: VMScriptResponseObject<Blob>) => void
|
|
347
|
-
ontimeout?: (resp: VMScriptResponseObject<Blob>) => void
|
|
394
|
+
name: string
|
|
348
395
|
}
|
|
349
396
|
|
|
350
397
|
/** Downloads a URL to a local file. */
|
|
@@ -353,18 +400,29 @@ declare function GM_download(
|
|
|
353
400
|
/** The URL to download. */
|
|
354
401
|
url: string,
|
|
355
402
|
/** The filename to save as. */
|
|
356
|
-
name
|
|
403
|
+
name: string
|
|
357
404
|
): void
|
|
358
405
|
|
|
359
|
-
|
|
406
|
+
/** Aliases for GM_ methods that are not included in Greasemonkey4 API */
|
|
407
|
+
declare interface VMScriptGMObjectVMExtensions {
|
|
408
|
+
addElement: typeof GM_addElement
|
|
409
|
+
addStyle: typeof GM_addStyle
|
|
410
|
+
addValueChangeListener: typeof GM_addValueChangeListener
|
|
411
|
+
download: typeof GM_download
|
|
412
|
+
getResourceText: typeof GM_getResourceText
|
|
413
|
+
log: typeof GM_log
|
|
414
|
+
removeValueChangeListener: typeof GM_removeValueChangeListener
|
|
415
|
+
unregisterMenuCommand: typeof GM_unregisterMenuCommand
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/** The Greasemonkey4 API, https://wiki.greasespot.net/Greasemonkey_Manual:API */
|
|
419
|
+
declare interface VMScriptGMObject extends VMScriptGMObjectVMExtensions {
|
|
360
420
|
unsafeWindow: Window
|
|
361
421
|
info: typeof GM_info
|
|
362
422
|
getValue: <T>(name: string, defaultValue?: T) => Promise<T>
|
|
363
423
|
setValue: <T>(name: string, value: T) => Promise<void>
|
|
364
424
|
deleteValue: (name: string) => Promise<void>
|
|
365
425
|
listValues: () => Promise<string[]>
|
|
366
|
-
addStyle: typeof GM_addStyle
|
|
367
|
-
addElement: typeof GM_addElement
|
|
368
426
|
registerMenuCommand: typeof GM_registerMenuCommand
|
|
369
427
|
getResourceUrl: (name: string, isBlobUrl?: boolean) => Promise<string>
|
|
370
428
|
notification: typeof GM_notification
|