8000 add pr#49 · Nikki-Gu/jupyter-notify@080d556 · GitHub
[go: up one dir, main page]

Skip to content

Commit

Permalink
add pr#49
Browse files Browse the repository at this point in the history
  • Loading branch information
谷卓遥 committed Jun 8, 2024
1 parent 9ee27fb commit 080d556
Showing 1 changed file with 39 additions and 35 deletions.
74 changes: 39 additions & 35 deletions jupyternotify/js/notify.js
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();
};
}
}
}
}
)
}

0 comments on commit 080d556

Please sign in to comment.
0