Outlook Web App Unread Count Favicon

Adds an unread count favicon

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

You will need to install an extension such as Tampermonkey to install this script.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         Outlook Web App Unread Count Favicon
// @namespace    http://mattstow.com
// @version      0.1
// @description  Adds an unread count favicon
// @author       Matt Stow
// @match        https://outlook.office365.com/mail/*
// @match        https://outlook.live.com/mail/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    if (window.top !== window.self) {
        return;
    }

    var faviconEl = document.querySelector('[rel="shortcut icon"]');

    function setUnreadIconOnLoad (el) {
        var unreadEl = el.querySelector('.screenReaderOnly');
        var count = unreadEl ? unreadEl.parentElement.textContent.replace('unread', '') : 'O';

        faviconEl.href = 'https://dummyimage.com/32x32/0072c6/fff.png&text=' + count;
    }

    function setUreadIconOnChange (el) {
        var replacedUnread = el.textContent.replace('unread', '');
        var count = replacedUnread ? replacedUnread : 'O';

        faviconEl.href = 'https://dummyimage.com/32x32/0072c6/fff.png&text=' + count;
    }

    setTimeout(function () {
        var inboxEl = document.querySelector('[title="Inbox"]');
        var unreadConfig = { characterData: true, childList: true, subtree: true };
        var faviconConfig = { attributeFilter: ['href'] };

        var unreadObserver = new MutationObserver(function (mutations) {
            setUreadIconOnChange(mutations[0].target);
        });

        var faviconObserver = new MutationObserver(function (mutations) {
            mutations.forEach(function (mutation) {
                if (!mutation.target.href.includes('dummyimage.com')) {
                    setUnreadIconOnLoad(inboxEl);
                }
            });
        });

        setUnreadIconOnLoad(inboxEl);
        unreadObserver.observe(inboxEl, unreadConfig);
        faviconObserver.observe(faviconEl, faviconConfig);
    }, 2000);
})();