Zendesk Notification Sound & Highlight Updated

Play sound and change button style when a new notification arrives in Zendesk.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Zendesk Notification Sound & Highlight Updated
// @namespace    https://yourdomain.com
// @version      3.0
// @description  Play sound and change button style when a new notification arrives in Zendesk.
// @author       KoKa_UA
// @match        *://*.zendesk.com/*
// @grant        GM_addStyle
// @license MIT
// ==/UserScript==

(function() {
    'use strict';


    const notificationSound = new Audio("https://zvukitop.com/wp-content/uploads/2021/03/zvuki-opovesheniya.mp3");




    function checkForNewMessages(mutationsList) {

        const unreadCountElement = document.querySelector('[data-test-id="awm-unread-count"]');
        const notificationButton = document.querySelector('button[aria-label="Notifications"]');

        if (unreadCountElement && notificationButton) {
            if (unreadCountElement.innerText.trim() !== "0" && unreadCountElement.innerText.trim() !== "") {
                notificationSound.play();
                notificationButton.classList.add("has-new-messages");
            } else {
                notificationButton.classList.remove("has-new-messages");
            }
        }
    }


    function startObserver() {
        const targetNode = document.body;
        const config = { childList: true, subtree: true };

        const observer = new MutationObserver(checkForNewMessages);
        observer.observe(targetNode, config);

    }

    window.addEventListener('load', function() {
        setTimeout(startObserver, 5000);
    });

})();