mirror of
https://gitea.invidious.io/iv-org/invidious-copy-2023-06-08.git
synced 2024-08-15 00:53:38 +00:00
Only add notification event listener after onload
This commit is contained in:
parent
4e111c84f3
commit
e23bab0103
3 changed files with 29 additions and 29 deletions
|
@ -1,4 +1,4 @@
|
||||||
function get_playlist(plid, timeouts) {
|
function get_playlist(plid, timeouts = 0) {
|
||||||
if (timeouts > 10) {
|
if (timeouts > 10) {
|
||||||
console.log('Failed to pull playlist');
|
console.log('Failed to pull playlist');
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
var notifications, delivered;
|
var notifications, delivered;
|
||||||
|
|
||||||
function get_subscriptions(callback, failures) {
|
function get_subscriptions(callback, failures = 1) {
|
||||||
if (failures >= 10) {
|
if (failures >= 10) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,21 @@ function create_notification_stream(subscriptions) {
|
||||||
notifications.stream();
|
notifications.stream();
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener('storage', function (e) {
|
window.addEventListener('load', function (e) {
|
||||||
|
localStorage.setItem('notification_count', document.getElementById('notification_count') ? document.getElementById('notification_count').innerText : '0');
|
||||||
|
|
||||||
|
if (localStorage.getItem('stream')) {
|
||||||
|
localStorage.removeItem('stream');
|
||||||
|
} else {
|
||||||
|
setTimeout(function () {
|
||||||
|
if (!localStorage.getItem('stream')) {
|
||||||
|
get_subscriptions(create_notification_stream);
|
||||||
|
localStorage.setItem('stream', true);
|
||||||
|
}
|
||||||
|
}, Math.random() * 1000 + 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener('storage', function (e) {
|
||||||
if (e.key === 'stream' && !e.newValue) {
|
if (e.key === 'stream' && !e.newValue) {
|
||||||
if (notifications) {
|
if (notifications) {
|
||||||
localStorage.setItem('stream', true);
|
localStorage.setItem('stream', true);
|
||||||
|
@ -115,21 +129,7 @@ window.addEventListener('storage', function (e) {
|
||||||
'<i class="icon ion-ios-notifications-outline"></i>';
|
'<i class="icon ion-ios-notifications-outline"></i>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
window.addEventListener('load', function (e) {
|
|
||||||
localStorage.setItem('notification_count', document.getElementById('notification_count') ? document.getElementById('notification_count').innerText : '0');
|
|
||||||
|
|
||||||
if (localStorage.getItem('stream')) {
|
|
||||||
localStorage.removeItem('stream');
|
|
||||||
} else {
|
|
||||||
setTimeout(function () {
|
|
||||||
if (!localStorage.getItem('stream')) {
|
|
||||||
get_subscriptions(create_notification_stream);
|
|
||||||
localStorage.setItem('stream', true);
|
|
||||||
}
|
|
||||||
}, Math.random() * 1000 + 10);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
window.addEventListener('unload', function (e) {
|
window.addEventListener('unload', function (e) {
|
||||||
|
|
|
@ -7,7 +7,7 @@ if (subscribe_button.getAttribute('data-type') === 'subscribe') {
|
||||||
subscribe_button.onclick = unsubscribe;
|
subscribe_button.onclick = unsubscribe;
|
||||||
}
|
}
|
||||||
|
|
||||||
function subscribe(timeouts) {
|
function subscribe(timeouts = 0) {
|
||||||
if (timeouts >= 10) {
|
if (timeouts >= 10) {
|
||||||
console.log('Failed to subscribe.');
|
console.log('Failed to subscribe.');
|
||||||
return;
|
return;
|
||||||
|
@ -41,7 +41,7 @@ function subscribe(timeouts) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function unsubscribe(timeouts) {
|
function unsubscribe(timeouts = 0) {
|
||||||
if (timeouts >= 10) {
|
if (timeouts >= 10) {
|
||||||
console.log('Failed to subscribe');
|
console.log('Failed to subscribe');
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue