Skip to content

Instantly share code, notes, and snippets.

@WebReflection
Created June 18, 2020 14:04
Show Gist options
  • Save WebReflection/7a89d5216947f42ed58d052c9b922e55 to your computer and use it in GitHub Desktop.
Save WebReflection/7a89d5216947f42ed58d052c9b922e55 to your computer and use it in GitHub Desktop.
// 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