xshell 0.0.16 → 0.0.17
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/chalk.browser.d.ts +2 -0
- package/chalk.browser.js +21 -0
- package/chalk.browser.js.map +1 -0
- package/net.browser.d.ts +23 -0
- package/net.browser.js +70 -0
- package/net.browser.js.map +1 -0
- package/package.json +1 -1
- package/prototype.browser.d.ts +130 -0
- package/prototype.browser.js +421 -0
- package/prototype.browser.js.map +1 -0
- package/toaster.browser.d.ts +9 -0
- package/toaster.browser.js +45 -0
- package/toaster.browser.js.map +1 -0
- package/tsconfig.json +0 -1
- package/utils.browser.d.ts +3 -0
- package/utils.browser.js +27 -0
- package/utils.browser.js.map +1 -0
- package/chalk.browser.ts +0 -41
- package/net.browser.ts +0 -141
- package/prototype.browser.ts +0 -728
- package/toaster.browser.ts +0 -50
- package/utils.browser.ts +0 -25
package/chalk.browser.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { Instance as Chalk } from 'chalk'
|
|
2
|
-
|
|
3
|
-
const chalk = new Chalk({ level: 2 })
|
|
4
|
-
|
|
5
|
-
const {
|
|
6
|
-
red,
|
|
7
|
-
green,
|
|
8
|
-
yellow,
|
|
9
|
-
blue,
|
|
10
|
-
magenta,
|
|
11
|
-
cyan,
|
|
12
|
-
grey,
|
|
13
|
-
|
|
14
|
-
redBright: red_,
|
|
15
|
-
greenBright: green_,
|
|
16
|
-
yellowBright: yellow_,
|
|
17
|
-
blueBright: blue_,
|
|
18
|
-
magentaBright: magenta_,
|
|
19
|
-
cyanBright: cyan_,
|
|
20
|
-
|
|
21
|
-
underline,
|
|
22
|
-
} = chalk
|
|
23
|
-
|
|
24
|
-
export {
|
|
25
|
-
red,
|
|
26
|
-
green,
|
|
27
|
-
yellow,
|
|
28
|
-
blue,
|
|
29
|
-
magenta,
|
|
30
|
-
cyan,
|
|
31
|
-
grey,
|
|
32
|
-
|
|
33
|
-
red_,
|
|
34
|
-
green_,
|
|
35
|
-
yellow_,
|
|
36
|
-
blue_,
|
|
37
|
-
magenta_,
|
|
38
|
-
cyan_,
|
|
39
|
-
|
|
40
|
-
underline
|
|
41
|
-
}
|
package/net.browser.ts
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
export interface RequestOptions {
|
|
2
|
-
method?: 'get' | 'post' | 'put' | 'head' | 'delete' | 'patch'
|
|
3
|
-
|
|
4
|
-
queries?: Record<string, any>
|
|
5
|
-
|
|
6
|
-
headers?: Record<string, string>
|
|
7
|
-
|
|
8
|
-
body?: string | object | HTMLFormElement
|
|
9
|
-
|
|
10
|
-
type?: 'application/json' | 'application/x-www-form-urlencoded' | 'multipart/form-data'
|
|
11
|
-
|
|
12
|
-
cors?: boolean
|
|
13
|
-
|
|
14
|
-
by?: 'fetch' | 'GM_xmlhttpRequest'
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface RequestRawOptions extends RequestOptions {
|
|
18
|
-
raw: true
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
- url: 可以只有 pathname 部分
|
|
23
|
-
- options:
|
|
24
|
-
- type: `'application/json'` 请求的 content-type 头 (如果有 body)
|
|
25
|
-
- by: `window.GM_xmlhttpRequest ? 'GM_xmlhttpRequest' : 'fetch'` 发起请求所使用的底层方法
|
|
26
|
-
*/
|
|
27
|
-
export async function request (url: string | URL): Promise<string>
|
|
28
|
-
export async function request (url: string | URL, options: RequestRawOptions): Promise<Response>
|
|
29
|
-
export async function request (url: string | URL, options: RequestOptions): Promise<string>
|
|
30
|
-
export async function request (url: string | URL, {
|
|
31
|
-
method,
|
|
32
|
-
|
|
33
|
-
queries,
|
|
34
|
-
|
|
35
|
-
headers,
|
|
36
|
-
|
|
37
|
-
body,
|
|
38
|
-
|
|
39
|
-
type = 'application/json',
|
|
40
|
-
|
|
41
|
-
cors,
|
|
42
|
-
|
|
43
|
-
by = window.GM_xmlhttpRequest ? 'GM_xmlhttpRequest' : 'fetch',
|
|
44
|
-
|
|
45
|
-
raw,
|
|
46
|
-
}: RequestOptions & { raw?: boolean } = { }) {
|
|
47
|
-
url = new URL(url, location.href)
|
|
48
|
-
|
|
49
|
-
if (queries)
|
|
50
|
-
for (const key in queries) {
|
|
51
|
-
let value = queries[key]
|
|
52
|
-
if (typeof value === 'boolean')
|
|
53
|
-
value = value ? '1' : '0'
|
|
54
|
-
url.searchParams.append(key, value)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (body && !method)
|
|
58
|
-
method = 'post'
|
|
59
|
-
|
|
60
|
-
if (type === 'application/json' && typeof body !== 'undefined' && typeof body !== 'string')
|
|
61
|
-
body = JSON.stringify(body)
|
|
62
|
-
|
|
63
|
-
url = url.toString()
|
|
64
|
-
|
|
65
|
-
if (by === 'fetch') {
|
|
66
|
-
const options: RequestInit = {
|
|
67
|
-
... method ? { method: method.toUpperCase() } : { },
|
|
68
|
-
|
|
69
|
-
... cors ? { mode: 'cors' } : { },
|
|
70
|
-
|
|
71
|
-
credentials: 'include',
|
|
72
|
-
|
|
73
|
-
headers: {
|
|
74
|
-
... body ? { 'content-type': type } : { },
|
|
75
|
-
... headers,
|
|
76
|
-
},
|
|
77
|
-
|
|
78
|
-
... body ? { body: body as string } : { },
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const response = await fetch(
|
|
82
|
-
url,
|
|
83
|
-
options
|
|
84
|
-
)
|
|
85
|
-
|
|
86
|
-
if (!response.ok)
|
|
87
|
-
throw Object.assign(
|
|
88
|
-
new Error(`StatusCodeError: ${response.status}`),
|
|
89
|
-
{ url, response, ...options }
|
|
90
|
-
)
|
|
91
|
-
|
|
92
|
-
if (raw)
|
|
93
|
-
return response
|
|
94
|
-
|
|
95
|
-
return response.text()
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
return new Promise((resolve, reject) => {
|
|
100
|
-
GM_xmlhttpRequest({
|
|
101
|
-
... method ? { method: (method as any).toUpperCase() } : { },
|
|
102
|
-
|
|
103
|
-
url: url as string,
|
|
104
|
-
|
|
105
|
-
headers: {
|
|
106
|
-
... body ? { 'content-type': type } : { },
|
|
107
|
-
... headers,
|
|
108
|
-
},
|
|
109
|
-
|
|
110
|
-
... body ? { data: body as string, } : { },
|
|
111
|
-
|
|
112
|
-
onload (response) {
|
|
113
|
-
if (!(200 <= response.status && response.status <= 299)) {
|
|
114
|
-
reject(
|
|
115
|
-
Object.assign(
|
|
116
|
-
new Error(`StatusCodeError: ${response.status}`),
|
|
117
|
-
{ url, queries, method, headers, body, response }
|
|
118
|
-
)
|
|
119
|
-
)
|
|
120
|
-
return
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
resolve(response.responseText)
|
|
124
|
-
}
|
|
125
|
-
})
|
|
126
|
-
})
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
/** 发起 http 请求并将响应体作为 json 解析 */
|
|
131
|
-
export async function request_json <T = any> (url: string, options?: RequestOptions): Promise<T> {
|
|
132
|
-
const resp = await request(url, options)
|
|
133
|
-
if (!resp) return
|
|
134
|
-
try {
|
|
135
|
-
return JSON.parse(resp)
|
|
136
|
-
} catch (error) {
|
|
137
|
-
console.error(resp)
|
|
138
|
-
throw error
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|