Skip to content

Instantly share code, notes, and snippets.

@zonaro
Last active April 13, 2023 19:31
Show Gist options
  • Save zonaro/9b12f9f5e93e6c98378091337a758a0c to your computer and use it in GitHub Desktop.
Save zonaro/9b12f9f5e93e6c98378091337a758a0c to your computer and use it in GitHub Desktop.
notificationOverAlert.js
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