Notifier

1

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.gf.qytechs.cn/scripts/478724/1289430/Notifier.js

  1. 'use strict';
  2.  
  3. if (typeof Notification !== "function") throw Error("Not Support yet!");
  4.  
  5. const notify = (() => {
  6. const open = (typeof GM_openInTab === "function") ?
  7. GM_openInTab : (uri) => window.open(uri, "_blank");
  8.  
  9. if (typeof GM_notification === "function") {
  10. const ver = GM_info.version;
  11. const handler = GM_info.scriptHandler;
  12. if (handler === "Violentmonkey" && ver >= "2.15.4") {
  13. const V2_15_4 = (opti) => {
  14. const noti = GM_notification({
  15. onclick: () => (open(opti.url), noti.remove()),
  16. ...opti
  17. });
  18. return noti;
  19. };
  20. if (ver > "2.16.1") // v 2.16.1 has some bugs
  21. return (opti) => {
  22. opti.zombieUrl = opti.url;
  23. opti.zombieTimeout = 2147483647;
  24. return V2_15_4(opti);
  25. };
  26. return V2_15_4;
  27. } else if (handler === "Tampermonkey" && ver >= "5.0")
  28. return GM_notification;
  29. }
  30. return ({text, title, image, silent, tag, url: uri, ondone}) => {
  31. Notification.requestPermission();
  32. const options = {
  33. body: text,
  34. silent, tag,
  35. data: uri,
  36. icon: image,
  37. };
  38. if (!!tag) options.renotify = true;
  39. const noti = new Notification(title, options);
  40. noti.onclick = () => (open(noti.data), noti.close());
  41. noti.onclose = ondone;
  42. return {remove: () => noti.close()};
  43. };
  44. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址