0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Notifications APIを上書きしてまとめて通知する

Posted at

Notificationクラスを上書きしてキューにためておく。通知を制御するExtensionなんかが作れないかなーと思ってメモ

let queue = []

class MyNotification {
    constructor(title, options) {
        queue.push({title: title, options: options})
    }

    static async notify(notifications) {
        for (let i in notifications) {
            new OrgNotification(notifications[i].title, notifications[i].options)
            await new Promise(r => setTimeout(r, 1000))
        }
    }
}

OrgNotification = Notification
Notification = MyNotification

new Notification("title1")
new Notification("title2")
new Notification("title3")

await Notification.notify(queue)
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?