From e5486cb6529bce16eb9aab47f977268b9e14b220 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=89=AF?= <841369634@qq.com> Date: Mon, 22 Apr 2024 15:02:59 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AF=A1=E6=94=B9=E7=8C=B4=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=EF=BC=8C=E9=80=9A=E7=9F=A5=E5=8A=9F=E8=83=BD=E4=BC=98=E5=8C=96?= =?UTF-8?q?=EF=BC=8C=E8=BF=9E=E7=BB=AD=E5=8F=91=E8=B5=B7=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E4=BC=9A=E5=85=88=E5=85=B3=E9=97=AD=E4=B8=8A?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E9=80=9A=E7=9F=A5=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tampermonkey.js | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/tampermonkey.js b/tampermonkey.js index 4aae2fc..4dbc6ce 100644 --- a/tampermonkey.js +++ b/tampermonkey.js @@ -19,7 +19,13 @@ pluginElement: null, // 插件div menusElement: null, // 菜单列表div menus: {}, // 菜单集合 - menuIndex: 0 // 菜单索引,用于生成menuCmdId + menuIndex: 0, // 菜单索引,用于生成menuCmdId + lastNotification: null // 最后一次通知 + /*{ + obj: null, // 通知对象 + options: null, // 通知选项 + timeout: null // 通知定时器 + }*/ }; // 创建插件样式 @@ -323,9 +329,27 @@ // 显示通知方法 const showNotification = () => { + // 先关闭上一个通知 + let lastNotification = context.lastNotification; + if (lastNotification) { + if (lastNotification.timeout) { + clearTimeout(lastNotification.timeout); + } + lastNotification.obj.close(); + if (lastNotification.options && typeof lastNotification.options.ondone === "function") lastNotification.options.ondone(); + context.lastNotification = null; + } + const notification = new Notification(text); + lastNotification = { + obj: notification, + options: options, + timeout: null + } + context.lastNotification = lastNotification; if (options.timeout) { - setTimeout(function () { + lastNotification.timeout = setTimeout(function () { + context.lastNotification = null // 清除最后一个通知 notification.close(); if (options.ondone) options.ondone(); // 回调 }, options.timeout)