|
5 | 5 | // @description 用来发送一个浏览器通知, 支持图标/文字/进度条(进度条只在 Chrome 有效) |
6 | 6 | // @author You |
7 | 7 | // @match https://bbs.tampermonkey.net.cn/ |
8 | | -// @grant GM_notification |
| 8 | +// @grant GM_notification |
9 | 9 | // ==/UserScript== |
10 | 10 |
|
| 11 | +/** |
| 12 | + * @typedef {import('../src/types/scriptcat')} ScriptCat |
| 13 | + */ |
| 14 | + |
11 | 15 | let i; |
12 | 16 | GM_notification({ |
13 | | - title: '倒计时', |
14 | | - text: '准备进入倒计时,创建和获取通知id', |
15 | | - ondone: (byUser) => { |
16 | | - console.log('done user:', byUser); |
| 17 | + title: "倒计时", |
| 18 | + text: "准备进入倒计时,创建和获取通知id", |
| 19 | + ondone: (byUser) => { |
| 20 | + console.log("done user:", byUser); |
| 21 | + clearInterval(i); |
| 22 | + }, |
| 23 | + onclick: () => { |
| 24 | + console.log("click"); |
| 25 | + }, |
| 26 | + oncreate: (id) => { |
| 27 | + let t = 1; |
| 28 | + i = setInterval(() => { |
| 29 | + GM_updateNotification(id, { |
| 30 | + title: "倒计时", |
| 31 | + text: 60 - t + "s倒计时", |
| 32 | + progress: (100 / 60) * t, |
| 33 | + }); |
| 34 | + if (t == 60) { |
17 | 35 | clearInterval(i); |
18 | | - }, |
19 | | - onclick: () => { |
20 | | - console.log('click'); |
21 | | - }, |
22 | | - oncreate: (id) => { |
23 | | - let t = 1; |
24 | | - i = setInterval(() => { |
25 | | - GM_updateNotification(id, { |
26 | | - title: '倒计时', |
27 | | - text: (60 - t) + 's倒计时', |
28 | | - progress: 100 / 60 * t |
29 | | - }); |
30 | | - if (t == 60) { |
31 | | - clearInterval(i); |
32 | | - GM_updateNotification(id, { |
33 | | - title: '倒计时', |
34 | | - text: '倒计时结束', |
35 | | - progress: 100 |
36 | | - }); |
37 | | - } |
38 | | - t++; |
39 | | - }, 1000); |
40 | | - }, |
41 | | - // 开启进度条模式 |
42 | | - progress: 0, |
| 36 | + GM_updateNotification(id, { |
| 37 | + title: "倒计时", |
| 38 | + text: "倒计时结束", |
| 39 | + progress: 100, |
| 40 | + }); |
| 41 | + } |
| 42 | + t++; |
| 43 | + }, 1000); |
| 44 | + }, |
| 45 | + // 开启进度条模式 |
| 46 | + progress: 0, |
| 47 | +}); |
| 48 | + |
| 49 | +// 示例2: 综合功能通知 - 使用更多特性 |
| 50 | +GM_notification({ |
| 51 | + title: "综合功能通知", |
| 52 | + text: "这是一个展示多种特性的通知示例", |
| 53 | + tag: "feature-demo", // 使用相同的tag可以覆盖之前的通知,否则会创建新的通知 |
| 54 | + image: "https://bbs.tampermonkey.net.cn/favicon.ico", // 自定义图标 |
| 55 | + timeout: 10000, // 10秒后自动关闭 |
| 56 | + url: "https://bbs.tampermonkey.net.cn/", // 关联URL |
| 57 | + onclick: (event) => { |
| 58 | + console.log("通知被点击:", event); |
| 59 | + // event.preventDefault(); // 阻止打开url |
| 60 | + }, |
| 61 | + oncreate: (event) => { |
| 62 | + console.log("综合功能通知已创建,ID:", event.id); |
| 63 | + }, |
| 64 | + ondone: (user) => { |
| 65 | + console.log("综合功能通知完成,用户操作:", user); |
| 66 | + }, |
43 | 67 | }); |
0 commit comments