DEV Community

Ibrahim Ezzy
Ibrahim Ezzy

Posted on • Edited on

3

Mark All WhatsApp messages as Read

A popular person in our community receives a lot of WhatsApp messages — in thousands — especially during events and he obviously cannot reply or even read all of them. He asked me if there was a way to Mark as Read all messages so I came up with this quick and dirty solution that works in WhatsApp Web.

Just copy and paste the following script in the browser console and wait for it to finish. It marks a message as read every 2 seconds.

const triggerMouseEvent = (node, eventType) => {
        var clickEvent = document.createEvent("MouseEvents");
        clickEvent.initEvent(eventType, true, true);
        node.dispatchEvent(clickEvent);
    },
    timer = (ms) => {
        return new Promise((res) => setTimeout(res, ms));
    },
    selector = '[aria-label*="unread message"]',
    messages = (async () => {
        for (const message of document.querySelectorAll(selector)) {
            ["mouseover", "mousedown", "mouseup", "click"]
                .map((event) => triggerMouseEvent(message, event));
            await timer(2000);
        }
    })();
Enter fullscreen mode Exit fullscreen mode

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs