Skip to content

Instantly share code, notes, and snippets.

@hadongsoo
Last active May 24, 2019 16:35
Show Gist options
  • Save hadongsoo/aef2790d8fd8921535078ef013d607bc to your computer and use it in GitHub Desktop.
Save hadongsoo/aef2790d8fd8921535078ef013d607bc to your computer and use it in GitHub Desktop.
twichCategory_notification
// ==UserScript==
// @name twitch-category-alarm
// @version 1
// @grant none
// @match *://www.twitch.tv/*
// @run-at document-idle
// ==/UserScript==
window.setTimeout(function () {
console.log('alarm start');
let target = document.querySelector('.channel-info-bar__content-right .tw-interactive.tw-link');
let originalFavicon = document.querySelector('link[rel="icon"]').href;
let newFavicon = 'https://d4fodtu7cqfym.cloudfront.net/favicon/favicon.ico';
let originalTitle = document.title;
let alramMessage = 'IRL';
let timing = 5;
let interval;
let worker = () => {
// console.log('working');
if (target.textContent === "Just Chatting") {
document.title = `${alramMessage} ${originalTitle}`;
document.querySelector('link[rel="icon"]').href = originalFavicon;
} else {
document.title = originalTitle;
document.querySelector('link[rel="icon"]').href = newFavicon;
}
}
worker();
window.addEventListener('blur', ()=> {
// console.log('blur');
interval = setInterval(worker, 1000*60*timing);
});
window.addEventListener('focus', () => {
// console.log('focus');
clearInterval(interval);
let observer = new MutationObserver(function(mutations) {
worker();
});
let config = { attributes: false, childList: true, characterData: false };
observer.observe(target, config);
});
}, 3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment