add and hide button
This commit is contained in:
parent
7ad67a80f5
commit
e84441e7f1
@ -59,10 +59,25 @@
|
||||
const isLoggedIn = document.getElementById('is-logged-in').value === 'true';
|
||||
navigator.serviceWorker.register('{{ url_for("static", filename="service-worker.js") }}').then(function(registration) {
|
||||
console.log('ServiceWorker registration successful with scope: ', registration.scope);
|
||||
// Check for the 'loggedin' query parameter to trigger the prompt
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
if (isLoggedIn && urlParams.has('loggedin')) {
|
||||
const enableNotificationsBtn = document.getElementById('enable-notifications-btn');
|
||||
|
||||
function setupNotificationButton() {
|
||||
registration.pushManager.getSubscription().then(function(subscription) {
|
||||
if (enableNotificationsBtn) {
|
||||
if (subscription) {
|
||||
enableNotificationsBtn.style.display = 'none';
|
||||
} else {
|
||||
enableNotificationsBtn.style.display = 'block';
|
||||
enableNotificationsBtn.addEventListener('click', function() {
|
||||
askPermission(registration);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (enableNotificationsBtn) {
|
||||
setupNotificationButton();
|
||||
}
|
||||
}, function(err) {
|
||||
console.log('ServiceWorker registration failed: ', err);
|
||||
@ -143,6 +158,10 @@
|
||||
.then(response => {
|
||||
if (response.ok) {
|
||||
console.log('Subscription saved successfully.');
|
||||
const enableNotificationsBtn = document.getElementById('enable-notifications-btn');
|
||||
if (enableNotificationsBtn) {
|
||||
enableNotificationsBtn.style.display = 'none';
|
||||
}
|
||||
return response.json();
|
||||
} else {
|
||||
console.error('Failed to save subscription. Status:', response.status);
|
||||
|
@ -5,6 +5,9 @@
|
||||
{% block content %}
|
||||
<h1>Welcome {{ username }}!</h1>
|
||||
<br>
|
||||
<button id="enable-notifications-btn" class="btn btn-primary">Enable Notifications</button>
|
||||
<br>
|
||||
<br>
|
||||
<h2>You have {{ accounts }} active accounts</h2>
|
||||
<br>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user