forked from ShopRunner/jupyter-notify
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
谷卓遥
committed
Jun 8, 2024
1 parent
9ee27fb
commit 080d556
Showing
1 changed file
with
39 additions
and
35 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,43 @@ | ||
$(document).ready( | ||
function() { | ||
function appendUniqueDiv(){ | ||
// append a div with our uuid so we can check that it's already | ||
// been sent and avoid duplicates on page reload | ||
var notifiedDiv = document.createElement("div") | ||
notifiedDiv.id = "%(notification_uuid)s" | ||
element.append(notifiedDiv) | ||
} | ||
if (document.readyState === "complete" || (document.readyState !== "loading" && !document.documentElement.doScroll)) { | ||
installJupyterNotify(); | ||
} else { | ||
document.addEventListener("DOMContentLoaded", installJupyterNotify); | ||
} | ||
|
||
function installJupyterNotify() { | ||
function appendUniqueDiv(){ | ||
// append a div with our uuid so we can check that it's already | ||
// been sent and avoid duplicates on page reload | ||
var notifiedDiv = document.createElement("div") | ||
notifiedDiv.id = "%(notification_uuid)s" | ||
element.append(notifiedDiv) | ||
} | ||
|
||
// only send notifications if the pageload is complete; this will | ||
// help stop extra notifications when a saved notebook is loaded, | ||
// which during testing gives us state "interactive", not "complete" | ||
if (document.readyState === 'complete') { | ||
// check for the div that signifies that the notification | ||
// was already sent | ||
if (document.getElementById("%(notification_uuid)s") === null) { | ||
var notificationPayload = %(options)s; | ||
if (Notification.permission !== 'denied') { | ||
if (Notification.permission !== 'granted') { | ||
Notification.requestPermission(function (permission) { | ||
if(!('permission' in Notification)) { | ||
Notification.permission = permission | ||
} | ||
}) | ||
} | ||
if (Notification.permission === 'granted') { | ||
var notification = new Notification("Jupyter Notebook", notificationPayload) | ||
appendUniqueDiv() | ||
notification.onclick = function () { | ||
window.focus(); | ||
this.close(); | ||
}; | ||
} | ||
} | ||
// only send notifications if the pageload is complete; this will | ||
// help stop extra notifications when a saved notebook is loaded, | ||
// which during testing gives us state "interactive", not "complete" | ||
if (document.readyState === 'complete') { | ||
// check for the div that signifies that the notification | ||
// was already sent | ||
if (document.getElementById("%(notification_uuid)s") === null) { | ||
var notificationPayload = %(options)s; | ||
if (Notification.permission !== 'denied') { | ||
if (Notification.permission !== 'granted') { | ||
Notification.requestPermission(function (permission) { | ||
if(!('permission' in Notification)) { | ||
Notification.permission = permission | ||
} | ||
}) | ||
} | ||
if (Notification.permission === 'granted') { | ||
var notification = new Notification("Jupyter Notebook", notificationPayload) | ||
appendUniqueDiv() | ||
notification.onclick = function () { | ||
window.focus(); | ||
this.close(); | ||
}; | ||
} | ||
} | ||
} | ||
} | ||
) | ||
} |