Removed wake up notifications
This commit is contained in:
parent
60f39df682
commit
8d5f132743
1 changed files with 4 additions and 108 deletions
110
index.html
110
index.html
|
@ -180,14 +180,6 @@
|
|||
<br />
|
||||
<br />
|
||||
<a href="mailto:max@giller.dev">Write me an e-mail</a>
|
||||
<h1>Settings</h1>
|
||||
<table class="settings-table">
|
||||
<tr>
|
||||
<td><input type="checkbox" id="notifications" name="notifications" value="notifications" /></td>
|
||||
<td><label for="notifications">Enable wake up
|
||||
notifications</label></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<div class="profile">
|
||||
<img title="Primary profile picture" src="profile.png" />
|
||||
|
@ -196,14 +188,11 @@
|
|||
</div>
|
||||
|
||||
<script>
|
||||
const url = "https://giller.dev/g/my-status";
|
||||
const notifications = [];
|
||||
let userOnPage = true;
|
||||
const url = "https://giller.dev/g/my-status";
|
||||
let previousStatus = undefined;
|
||||
let currentStatus = undefined;
|
||||
let updateRoutine = undefined;
|
||||
const updateInterval = 60 * 1000;
|
||||
const notificationSettingName = "wake-up-notifications";
|
||||
const updateInterval = 60 * 1000;
|
||||
|
||||
function setText(id, text) {
|
||||
document.getElementById(id).innerHTML = text;
|
||||
|
@ -251,78 +240,11 @@
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
function dismissNotifications() {
|
||||
notifications.forEach(notification => notification.close());
|
||||
notifications.length = 0;
|
||||
}
|
||||
|
||||
function hasWakenUp() {
|
||||
return previousStatus && previousStatus.title.toLowerCase() === "sleeping" && currentStatus.title.toLowerCase() !== "sleeping";
|
||||
}
|
||||
|
||||
function enableNotifications() {
|
||||
if (updateRoutine) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Request permission to show notifications
|
||||
Notification.requestPermission().then(function (result) {
|
||||
if (result === "granted") {
|
||||
// Save setting
|
||||
localStorage.setItem(notificationSettingName, "true");
|
||||
|
||||
// Enable notifications
|
||||
updateRoutine = setInterval(function () {
|
||||
updateStatus();
|
||||
if (hasWakenUp()) {
|
||||
showNotification("Max Status", "Max has woken up!");
|
||||
}
|
||||
}, updateInterval);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function disableNotifications() {
|
||||
if (!updateRoutine) {
|
||||
return;
|
||||
}
|
||||
|
||||
clearInterval(updateRoutine);
|
||||
updateRoutine = undefined;
|
||||
|
||||
dismissNotifications();
|
||||
|
||||
// Save setting
|
||||
localStorage.setItem(notificationSettingName, "false");
|
||||
}
|
||||
|
||||
function showNotification(title, body) {
|
||||
if (userOnPage) {
|
||||
return;
|
||||
}
|
||||
|
||||
const notification = new Notification(title, {
|
||||
body: body,
|
||||
icon: "https://giller.dev/favicon.ico"
|
||||
});
|
||||
|
||||
notification.onclick = function () {
|
||||
window.focus();
|
||||
};
|
||||
|
||||
notifications.push(notification);
|
||||
}
|
||||
|
||||
function loadNotificationSetting() {
|
||||
if (localStorage.getItem(notificationSettingName) === "true") {
|
||||
document.getElementById("notifications").checked = true;
|
||||
enableNotifications();
|
||||
} else {
|
||||
document.getElementById("notifications").checked = false;
|
||||
disableNotifications();
|
||||
}
|
||||
}
|
||||
|
||||
function updateSleepStreak(streakData) {
|
||||
if (streakData.length == 0) {
|
||||
|
@ -356,31 +278,6 @@
|
|||
}
|
||||
}
|
||||
|
||||
// On window focus, dismiss all notifications
|
||||
window.onfocus = function () {
|
||||
dismissNotifications();
|
||||
userOnPage = true;
|
||||
};
|
||||
|
||||
// On window blur, enable notifications
|
||||
window.onblur = function () {
|
||||
userOnPage = false;
|
||||
};
|
||||
|
||||
// On page unload, dismiss all notifications
|
||||
window.onbeforeunload = function () {
|
||||
dismissNotifications();
|
||||
};
|
||||
|
||||
// On checkbox change, enable/disable notifications
|
||||
document.getElementById("notifications").onchange = function () {
|
||||
if (this.checked) {
|
||||
enableNotifications();
|
||||
} else {
|
||||
disableNotifications();
|
||||
}
|
||||
};
|
||||
|
||||
// On scroll, hide settings notice
|
||||
window.onscroll = function () {
|
||||
const scrollPosition = window.scrollY;
|
||||
|
@ -391,8 +288,7 @@
|
|||
}
|
||||
};
|
||||
|
||||
updateStatus();
|
||||
loadNotificationSetting();
|
||||
updateStatus();
|
||||
</script>
|
||||
</body>
|
||||
|
||||
|
|
Loading…
Reference in a new issue