Created
December 8, 2023 16:18
-
-
Save rmnmjw/bbdd907cb4018a601f3bad4e5cb95803 to your computer and use it in GitHub Desktop.
This file contains 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 whatsapp - show number in title | |
// @namespace Violentmonkey Scripts | |
// @match https://web.whatsapp.com/ | |
// @grant none | |
// @version 1.0 | |
// @author - | |
// @description 8.12.2023, 17:17:41 | |
// ==/UserScript== | |
const debounce = (func, wait, immediate) => { | |
let timeout; | |
return function() { | |
const context = this, args = arguments; | |
const later = function() { | |
timeout = null; | |
if (!immediate) func.apply(context, args); | |
}; | |
const callNow = immediate && !timeout; | |
clearTimeout(timeout); | |
timeout = setTimeout(later, wait); | |
if (callNow) func.apply(context, args); | |
}; | |
}; | |
(() => { | |
setTimeout(() => { | |
const newTitle = document.createElement("title"); | |
const newContent = document.createTextNode("Telegram"); | |
newTitle.appendChild(newContent); | |
document.head.appendChild(newTitle); | |
}, 1000); | |
const action = debounce(() => { | |
const number = document.querySelectorAll('[role="gridcell"] span[aria-label="Ungelesen"]').length; | |
let title = 'WhatsApp Web' | |
if (number) { | |
title = `${title} (${number})` | |
} | |
document.querySelectorAll('title').forEach(el => el.innerHTML = title); | |
}, 100, true); | |
const mo = new MutationObserver(action) | |
mo.observe( document, { childList:true, subtree:true }) | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment