Last active
April 13, 2023 19:31
-
-
Save zonaro/9b12f9f5e93e6c98378091337a758a0c to your computer and use it in GitHub Desktop.
notificationOverAlert.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.oldAlert = window.alert | |
window.alert = function (message) { | |
var __notification = null; | |
if (!("Notification" in window)) { | |
window.oldAlert(message); | |
} else if (Notification.permission === "granted") { | |
__notification = new Notification(message); | |
} else if (Notification.permission !== 'denied') { | |
Notification.requestPermission(function (permission) { | |
// If the user accepts, let's create a notification | |
if (permission === "granted") { | |
__notification = new Notification(message); | |
} | |
}); | |
} else { | |
window.oldAlert(message); | |
} | |
if (__notification !== null) { | |
__notification.onclick = function () { | |
window.oldAlert(message); | |
} | |
} else { | |
window.oldAlert(message); | |
} | |
return __notification; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment