王一之 发表于 2023-5-14 16:14:46

PushCat调用库

待补充
```js
// ==UserScript==
// @name         PushCat浏览器端
// @namespace    https://bbs.tampermonkey.net.cn/
// @version      0.1.0
// @descriptionPushCat浏览器端,可作为接收设备通知,也可以作为发送端推送消息至其它设备
// @author       王一之
// @background
// @connect      sct.icodef.com
// @grant GM_notification
// @grant GM_xmlhttpRequest
// @require https://scriptcat.org/lib/946/%5E1.0.1/PushCat.js
// ==/UserScript==

const device = new PushCatDevice({
    name: "浏览器",
    accessKey: "jz5ud0hda4ahy9qp",
});

device.onError(data => {
    GM_notification({
      title: "设备注册失败",
      text: data.msg,
    })
});

device.onMessage(messages => {
    messages.forEach(msg => {
      GM_notification({
            title: msg.title,
            text: msg.content
      })
    });
});

// const push = new PushCat({
//   accessKey: "jz5ud0hda4ahy9qp",
// });

// push.send("title", "content");
```

POORZHA 发表于 2024-12-16 15:56:13

const push = new PushCat({
    devices: ['通知机器人'],
    accessKey: "xxxxxxxxxxx",
});
push.send("这是标题", "这是内容"); 大大,如果浏览器作为发送端推送消息至其它设备 这个指定设备是这么填的吗, 为啥我试了好几种都发到默认设备去了...

王一之 发表于 2024-12-16 16:02:12

POORZHA 发表于 2024-12-16 15:56
大大,如果浏览器作为发送端推送消息至其它设备 这个指定设备是这么填的吗, 为啥我试了好几种都发到默认设 ...

不是,下面这样试试

const push = new PushCat({
    accessKey: "xxxxxxxxxxx",
});
push.send("这是标题", "这是内容",{devices:['通知机器人']});

POORZHA 发表于 2024-12-16 16:27:23

不行捏,直接放数组也不行
push.send("这是标题", "这是内容",['通知机器人']);

王一之 发表于 2024-12-16 16:51:00

POORZHA 发表于 2024-12-16 16:27
不行捏,直接放数组也不行
push.send("这是标题", "这是内容",['通知机器人']);

这样,有个{ devices: ["脚本猫的工具箱"] },另外有点bug,哥哥更新到1.0.2版本

```js
// ==UserScript==
// @name         PushCat浏览器端
// @namespace    https://bbs.tampermonkey.net.cn/
// @version      0.1.0
// @descriptionPushCat浏览器端,可作为接收设备通知,也可以作为发送端推送消息至其它设备
// @author       王一之
// @background
// @connect      sct.icodef.com
// @grant GM_notification
// @grant GM_xmlhttpRequest
// @require https://scriptcat.org/lib/946/1.0.2/PushCat.js
// ==/UserScript==


const push = new PushCat({
    accessKey: "xxxxx",
});

push.send("title", "content", { devices: ["脚本猫的工具箱"] });

return new Promise(resolve => {

});
```

POORZHA 发表于 2024-12-16 17:19:41

好耶,1.0.2可以了,谢谢大大~~{:4_93:}{:4_93:}{:4_93:}
页: [1]
查看完整版本: PushCat调用库