Last active
March 5, 2025 16:17
-
-
Save DanClarke-io/09ea0f363c3e16587de1e0c29366af43 to your computer and use it in GitHub Desktop.
Unread archive number for WhatsApp Web
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 Archive number for WhatsApp Web | |
| // @namespace http://tampermonkey.net/ | |
| // @version 2025-03-05 | |
| // @description Adds the number of unread archive messages to the tab title | |
| // @author You | |
| // @match https://web.whatsapp.com/ | |
| // @icon https://www.google.com/s2/favicons?sz=64&domain=whatsapp.com | |
| // @grant none | |
| // ==/UserScript== | |
| (function() { | |
| 'use strict'; | |
| // Function to extract numbers from text | |
| function extractNumbers(text) { | |
| return (text.match(/\d+/g) || []).map(Number); | |
| } | |
| // Function to update the title | |
| function updateTitle() { | |
| const archivedElements = document.querySelectorAll('[aria-label="Archived "]'); | |
| let total = 0; | |
| // Sum numbers found in archived elements | |
| archivedElements.forEach(element => { | |
| const numbers = extractNumbers(element.innerText); | |
| total += numbers.reduce((sum, num) => sum + num, 0); | |
| }); | |
| // Extract the existing count from the title (supports both (8) and (8/X) formats) | |
| const titleMatch = document.title.match(/^\((\d+)(?:\/\d+)?\)\s*(.*)$/); | |
| if (titleMatch) { | |
| const existingCount = titleMatch[1]; | |
| const baseTitle = titleMatch[2]; | |
| if (total > 0) { | |
| document.title = `(${existingCount}/${total}) ${baseTitle}`; // Show (8/X) WhatsApp | |
| } else { | |
| document.title = `(${existingCount}) ${baseTitle}`; // Revert to (8) WhatsApp if no numbers found | |
| } | |
| } | |
| } | |
| // Initial title update | |
| updateTitle(); | |
| // Update the title every 10 seconds | |
| setInterval(updateTitle, 10000); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment