Notify Destiny Message

Plays a sound or notifies when a div with data-username="destiny" is created

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Notify Destiny Message
// @namespace   Violentmonkey Scripts
// @description  Plays a sound or notifies when a div with data-username="destiny" is created
// @match       https://www.destiny.gg/*
// @grant       none
// @icon        https://cdn.destiny.gg/2.49.0/emotes/6296cf7e8ccd0.png
// @version     1.0
// @author      Walamo15
// @description 1/24/2025, 12:12:39 AM
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // List of usernames to monitor
    const usernamesToMonitor = ['destiny', 'EXAMPLEUSERNAME2','EXAMPLEUSERNAME']; // Add more usernames as needed

      // Function to handle new matching divs
    function handleNewDiv(div, username) {
        const messageText = div.querySelector(".text")?.textContent.trim() || "No message content";

        // console.log(`New message from ${username}: ${messageText}`);

        // Show browser notification
        if (Notification.permission === "granted") {
            new Notification(`New message from ${username}!`, {
                body: messageText,
                icon: "https://cdn.destiny.gg/emotes/649f7adb5746a.png" // Replace with a relevant icon URL
            });
        } else if (Notification.permission !== "denied") {
            Notification.requestPermission().then(permission => {
                if (permission === "granted") {
                    new Notification(`New message from ${username}!`, {
                        body: messageText,
                        icon: "https://via.placeholder.com/150"
                    });
                }
            });
        }
    }

    // MutationObserver to detect new divs
    const observer = new MutationObserver(mutations => {
        mutations.forEach(mutation => {
            if (mutation.type === "childList" && mutation.addedNodes.length > 0) {
                mutation.addedNodes.forEach(node => {
                    if (node.nodeType === Node.ELEMENT_NODE) {
                      //  console.log("Node detected:", node); // Log the added node

                        // Check if the node has the expected classes
                        if (
                            node.classList.contains('msg-chat') &&
                            node.classList.contains('msg-user')
                        ) {
                            const username = node.getAttribute('data-username');
                            //console.log("Checking username:", username); // Log the username detected

                            // Convert username to lowercase for case-insensitive comparison
                            if (usernamesToMonitor.includes(username.toLowerCase())) {
                                handleNewDiv(node, username);
                            }
                        }

                        // Check if the node contains a .text element inside it
                        const textElement = node.querySelector('.text');
                        if (textElement) {
                          //  console.log("Found message text:", textElement.textContent); // Log message text content
                            const username = node.getAttribute('data-username');

                            // Convert username to lowercase for case-insensitive comparison
                            if (usernamesToMonitor.includes(username.toLowerCase())) {
                                handleNewDiv(node, username);
                            }
                        }
                    }
                });
            }
        });
    });

    // Start observing the document body or a specific container for added nodes
    const chatContainer = document.querySelector('#chat-output-frame'); // Update to the correct container ID
    if (chatContainer) {
   //     console.log("Chat container found, starting observer.");
        observer.observe(chatContainer, { childList: true, subtree: true });
    } else {
     //   console.log("Chat container not found. Make sure the selector is correct.");
    }
})();