mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-08-03 15:46:23 -07:00
33 lines
No EOL
697 B
TypeScript
33 lines
No EOL
697 B
TypeScript
import $ from "jquery";
|
|
|
|
const noteCloseTime = 4*1000; // 4 seconds
|
|
const noteIcon = webroot + "/favicon.png";
|
|
|
|
function canNotify() {
|
|
return (location.protocol === "https:")
|
|
&& (typeof Notification !== "undefined");
|
|
}
|
|
|
|
export function notify(title: string, body: string, img = noteIcon) {
|
|
const n = new Notification(title, {
|
|
body: body,
|
|
image: img,
|
|
icon: noteIcon
|
|
});
|
|
setTimeout(() => {
|
|
n.close();
|
|
}, noteCloseTime);
|
|
}
|
|
|
|
$(() => {
|
|
if(!canNotify())
|
|
return;
|
|
|
|
Notification.requestPermission().then(granted => {
|
|
if(granted !== "granted")
|
|
return Promise.reject("denied");
|
|
}).catch(err => {
|
|
if(err !== "denied")
|
|
console.log(`Error starting notifications: ${err}`);
|
|
});
|
|
}); |