Created
July 9, 2026 06:30
-
-
Save jeznag/5be9b9be1aea486be7cf2361de988c18 to your computer and use it in GitHub Desktop.
Google Messages Focus Filter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name Google Messages Focus Filter | |
| // @namespace http://tampermonkey.net/ | |
| // @version 1.0 | |
| // @description Hides unread messages from anyone not on your allowed list. | |
| // @author You | |
| // @match https://messages.google.com/web/* | |
| // @grant none | |
| // ==/UserScript== | |
| (function() { | |
| 'use strict'; | |
| // 1. ADD YOUR ALLOWED CONTACTS HERE (Match the exact spelling in Google Messages) | |
| const ALLOWED_CONTACTS = [ | |
| "PARTNER NAME", | |
| "SOMEONE ELSE IMPORTANT" | |
| ]; | |
| // 2. TOGGLE FOCUS MODE (Change to 'false' to reveal all messages again) | |
| const FOCUS_MODE_ACTIVE = true; | |
| function applyFocusFilter() { | |
| if (!FOCUS_MODE_ACTIVE) return; | |
| // Grab all conversation blocks in the sidebar | |
| const conversations = document.querySelectorAll('mws-conversation-list-item'); | |
| [...conversations].forEach(chat => { | |
| // Check if this specific chat has the unread attribute | |
| const isUnread = chat.querySelector('a[data-e2e-is-unread="true"]') !== null; | |
| // Extract the exact contact name from the DOM | |
| const nameElement = chat.querySelector('span[data-e2e-conversation-name]'); | |
| const contactName = nameElement ? nameElement.textContent.trim() : ""; | |
| if (contactName) { | |
| // If it's unread AND the name isn't in your VIP list, hide the entire block | |
| if (!ALLOWED_CONTACTS.includes(contactName)) { | |
| chat.style.display = 'none'; | |
| console.log('hide', contactName, chat); | |
| } else { | |
| console.log('KEEP', contactName, chat); | |
| // Ensure your VIPs remain visible | |
| chat.style.display = ''; | |
| } | |
| } else { | |
| // If the message is already read, leave it visible | |
| chat.style.display = ''; | |
| } | |
| }); | |
| } | |
| // Google Messages is a Single Page Application, so we use setInterval | |
| // to run the filter every 1 second to catch new incoming texts instantly. | |
| setInterval(applyFocusFilter, 150); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment