WhatsApp Deleted Messages Viewer

Alert when a message is deleted in WhatsApp Web.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         WhatsApp Deleted Messages Viewer
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Alert when a message is deleted in WhatsApp Web.
// @author       Yusuf Sameh
// @match        https://web.whatsapp.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Function to handle incoming messages
    function handleNewMessages(mutationsList) {
        mutationsList.forEach(mutation => {
            if (mutation.type === 'childList') {
                mutation.addedNodes.forEach(node => {
                    if (node.nodeType === Node.ELEMENT_NODE && node.classList.contains('message-in')) {
                        const message = node.querySelector('.message-in .selectable-text');
                        if (message && message.textContent === 'This message was deleted') {
                            alert('A message was deleted.');
                        }
                    }
                });
            }
        });
    }

    // Select the target node
    const targetNode = document.querySelector('#pane-side');

    // Options for the observer (which mutations to observe)
    const config = { childList: true, subtree: true };

    // Check if targetNode exists before observing mutations
    if (targetNode) {
        // Create an observer instance linked to the callback function
        const observer = new MutationObserver(handleNewMessages);

        // Start observing the target node for configured mutations
        observer.observe(targetNode, config);
    } else {
        console.error('Target node not found.');
    }
})();