forked from snsogbl/clip-save
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpushMessagePushover.js
More file actions
64 lines (56 loc) · 1.4 KB
/
pushMessagePushover.js
File metadata and controls
64 lines (56 loc) · 1.4 KB
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
57
58
59
60
61
62
63
/**
* 将剪贴板内容推送到 Pushover
* @author ClipSave
* @param {string} token - Pushover token
* @param {string} user - Pushover user key
* @param {string} device - Pushover device name
* @param {string} message - 消息内容,从剪贴板内容获取
* @returns {object} - 推送结果
* @returns {object} - 错误信息
*/
// 从剪贴板项获取消息内容
if (item.ContentType !== 'Text') {
return {
error: '不支持的类型'
};
}
const message = item.Content || '';
if (!message) {
return {
error: '剪贴板内容为空,无法发送推送'
};
}
// 构建请求数据
const reqdata = {
token: 'your pushover token',
user: 'your pushover user key',
device: 'your device name',
message: message
};
// 发送 POST 请求到 Pushover API
try {
const urlStr = 'https://api.pushover.net/1/messages.json';
const response = await fetch(urlStr, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(reqdata)
});
if (!response.ok) {
const errorText = await response.text();
return {
error: `推送失败: ${response.status} ${response.statusText} - ${errorText}`
};
}
const resultBody = await response.json();
return {
success: true,
message: '推送成功',
response: resultBody
};
} catch (error) {
return {
error: `推送失败: ${error.message || String(error)}`
};
}