-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathUploadVerificationCode.js
56 lines (51 loc) · 1.55 KB
/
UploadVerificationCode.js
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
// START User Config
const url = 'http://192.168.5.194:5033'
const username = 'admin'
const token = 'admin'
const showToastNotification = true
// END User Config
const axios = require('axios');
const authHeader = 'basic ' + $base64.encode(`${username}:${token}`)
let urlWithoutSlash = url
while (urlWithoutSlash.endsWith('/'))
urlWithoutSlash = url.substring(0, url.length - 1)
const apiUrl = urlWithoutSlash + '/SyncClipboard.json'
function upload(text) {
if (text !== null && text.length !== 0) {
return axios({
method: 'put',
url: apiUrl,
headers: {
'authorization': authHeader,
'Content-Type': 'application/json',
},
data: {
'File': '',
'Clipboard': text,
'Type': 'Text'
}
}).then(res => {
if (res.status < 200 || res.status >= 300) {
throw res.status + ' ' + res.statusText
}
}).then(() => {
if (showToastNotification) {
toast('验证码已上传')
}
}).catch(error => {
if (showToastNotification) {
toast('验证码上传失败: \n' + error)
}
})
}
}
events.observeNotification();
events.onNotification(notification => {
const text = notification.getText();
if (text !== null && text.includes('验证')) {
var res = /\d{4,}/.exec(notification.getText())
if (res !== null) {
upload(res[0])
}
}
})