Created
June 18, 2020 14:04
-
-
Save WebReflection/7a89d5216947f42ed58d052c9b922e55 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// it notifies about the highest peak, and it logs it in console | |
// it also saves it to the window.participants property | |
(function () { | |
var max = 0; | |
var timer = 0; | |
var target = document.querySelector('[type="participants"]'); | |
var Notification = self.Notification || {permission: 'denied'}; | |
(new MutationObserver(() => { | |
var now = Math.max(parseInt(target.innerText.trim()), max); | |
if (max < now) { | |
console.log('%cparticipants:', 'font-weight:bold', max = now); | |
if (Notification.permission === 'granted') | |
notify(); | |
else if (Notification.permission !== 'denied') { | |
Notification.requestPermission().then(function (permission) { | |
if (permission === "granted") | |
notify(); | |
}); | |
} | |
window.participants = max; | |
} | |
})).observe(target, {characterData: true, subtree: true}); | |
function notify() { | |
clearTimeout(timer); | |
timer = setTimeout( | |
function () { | |
new Notification('new participants peek: ' + max); | |
}, | |
5000 | |
); | |
} | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment