Skip to content

Instantly share code, notes, and snippets.

@junmakii
Created May 19, 2018 14:44
Show Gist options
  • Select an option

  • Save junmakii/63790a5c924bb3736f1be72a9c1a144d to your computer and use it in GitHub Desktop.

Select an option

Save junmakii/63790a5c924bb3736f1be72a9c1a144d to your computer and use it in GitHub Desktop.
var messageHistory = []; var els = document.body.querySelectorAll('yt-live-chat-text-message-renderer'); Array.from(els).filter(el => Array.from(messageHistory).filter(message => message.getAttribute('id') === el.getAttribute('id')).length === 0).map(el => { messageHistory.push(el); return el.querySelector('#message').textContent });
var messageHistory = [];
var src = 'http://static.junmakii.umu.us/bell.ogg';
var audioEl = document.createElement('audio');
audioEl.setAttribute('src', src);
let play = function () {
let el = audioEl.cloneNode(true);
el.play();
};
let interval = function () {
try {
var els = document.body.querySelectorAll('yt-live-chat-text-message-renderer');
els = Array.prototype.slice.call(els, els.length - 10, els.length);
var doPlay = !!messageHistory.length
Array.from(els)
.filter(el => Array.from(messageHistory).filter(message => message.getAttribute('id') === el.getAttribute('id')).length === 0)
.map(el => {
if (messageHistory.length > 10) { messageHistory.shift(); }
messageHistory.push(el);
if (doPlay) { play()
new Notification(
'YouTube Live',
{"body": el.querySelector('#author-name').textContent + ' : ' + el.querySelector('#message').textContent })
};
});
} catch (err) {
console.error(err);
}
};
let main = function () {
// el.addEventListener('loadeddata', () => el.play())
if (Notification.permission !== 'granted') { Notification.requestPermission(permission => permission) }
window.setTimeout(() => { window.setInterval(interval, 5000, false) }, 1000);
};
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment