-
Notifications
You must be signed in to change notification settings - Fork 0
/
Notifications.js
31 lines (27 loc) · 1.09 KB
/
Notifications.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function Notify(text){
let notify = document.querySelector('#notification');
notify.innerHTML = text;
notify.className = "visible";
notify.addEventListener("click", function(){
let notify = document.querySelector('#notification');
notify.className = "hidden";
});
}
function NotifyOnload(){
let notify = document.querySelector('#notification');
//callback for the mutation observer
const callback = function(mutationsList, observer) {
mutationsList.forEach(mu => {
if (mu.type !== "attributes" && mu.attributeName !== "class") return;
//The class was changed. Make sure to set it back to hidden after 5 seconds
window.setTimeout(() =>{
let notify = document.querySelector('#notification');
notify.className = "hidden";
}, 5000);
});
};
// Options for the observer (which mutations to observe)
const config = { attributes: true, childList: true, subtree: true };
const observer = new MutationObserver(callback);
observer.observe(notify, config);
}