mirror of
https://github.com/openvk/openvk
synced 2024-11-15 03:31:18 +03:00
Update notifications.js
This commit is contained in:
parent
28c66af133
commit
0657e1c00e
1 changed files with 8 additions and 27 deletions
|
@ -2,32 +2,12 @@ Function.noop = () => {};
|
||||||
|
|
||||||
var _n_counter = 0;
|
var _n_counter = 0;
|
||||||
|
|
||||||
var _activeWindow = true;
|
|
||||||
|
|
||||||
const _pageTitle = u("title").nodes[0].innerText;
|
|
||||||
|
|
||||||
var counter = 0;
|
var counter = 0;
|
||||||
|
|
||||||
/* this fucking dumb shit is broken :c
|
window.addEventListener("focus", () => {
|
||||||
|
document.title = document.title.replace(/^\([0-9]+\) /, ""); // remove notification counter xD
|
||||||
window.addEventListener('focus', () => {
|
|
||||||
_activeWindow = true;
|
|
||||||
closeAllNotifications();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
window.addEventListener('blur', () => {_activeWindow = false});
|
|
||||||
|
|
||||||
function closeAllNotifications() {
|
|
||||||
var notifications = u(".notifications_global_wrap").nodes[0].children;
|
|
||||||
for (var i = 0; i < notifications.length; i++) {
|
|
||||||
setTimeout(() => {
|
|
||||||
console.log(i);
|
|
||||||
notifications.item(i).classList.add('disappears');
|
|
||||||
setTimeout(() => {notifications.item(i).remove()}, 500).bind(this);
|
|
||||||
}, 5000).bind(this);
|
|
||||||
}
|
|
||||||
} */
|
|
||||||
|
|
||||||
function NewNotification(title, body, avatar = null, callback = () => {}, time = 5000, count = true) {
|
function NewNotification(title, body, avatar = null, callback = () => {}, time = 5000, count = true) {
|
||||||
if(avatar != null) {
|
if(avatar != null) {
|
||||||
avatar = '<avatar>' +
|
avatar = '<avatar>' +
|
||||||
|
@ -62,18 +42,19 @@ function NewNotification(title, body, avatar = null, callback = () => {}, time =
|
||||||
}
|
}
|
||||||
|
|
||||||
function __closeNotification() {
|
function __closeNotification() {
|
||||||
|
if(document.visibilityState != "visible")
|
||||||
|
return setTimeout(() => {__closeNotification()}, time); // delay notif deletion
|
||||||
|
|
||||||
getPrototype().addClass('disappears');
|
getPrototype().addClass('disappears');
|
||||||
setTimeout(() => {getPrototype().remove()}, 500);
|
return setTimeout(() => {getPrototype().remove()}, 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(count == true) {
|
if(count == true) {
|
||||||
counter++;
|
counter++;
|
||||||
document.title = `(${counter}) ${_pageTitle}`;
|
document.title = `(${counter}) ${document.title}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if(_activeWindow == true) { */
|
|
||||||
setTimeout(() => {__closeNotification()}, time);
|
setTimeout(() => {__closeNotification()}, time);
|
||||||
/* } */
|
|
||||||
|
|
||||||
notification.children('notification_title').children('a.close').on('click', function(e) {
|
notification.children('notification_title').children('a.close').on('click', function(e) {
|
||||||
__closeNotification();
|
__closeNotification();
|
||||||
|
|
Loading…
Reference in a new issue