WhatsApp Web Blur & Quick Message

Blurs inactive WhatsApp chats/messages, unblurs on hover, and enables messaging without saving numbers.

À partir de 2025-06-01. Voir la dernière version.

// ==UserScript==
// @name         WhatsApp Web Blur & Quick Message
// @namespace    http://tampermonkey.net/
// @version      1.0.0
// @description  Blurs inactive WhatsApp chats/messages, unblurs on hover, and enables messaging without saving numbers.
// @author       Noushad Bhuiyan
// @match        https://web.whatsapp.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=whatsapp.com
// @grant        none
// @license      MIT
// ==/UserScript==
(() => {
  const applyBlur = el => !el.hasAttribute('is-blurred') && !el.hasAttribute('aria-selected') && (el.style.filter = 'blur(8px)', el.style.transition = 'filter 0.3s ease-in-out', el.setAttribute('is-blurred', 'true'), el.addEventListener('mouseenter', () => el.style.filter = 'none'), el.addEventListener('mouseleave', () => el.style.filter = 'blur(8px)'));

  const clearBlurFromActiveChat = () => document.querySelectorAll('[aria-label="Chat list"] [aria-selected="true"]').forEach(el => el.hasAttribute('is-blurred') && (el.style.filter = 'none', el.style.transition = 'none', el.removeAttribute('is-blurred'), el.removeEventListener('mouseenter', () => {}), el.removeEventListener('mouseleave', () => {})));

  const blurElements = () => (document.querySelectorAll('[aria-label="Chat list"] [role="listitem"], [role="application"] [data-testid="conversation-panel-messages"]').forEach(applyBlur), clearBlurFromActiveChat());

  const addMessageButton = () => {
    const h1 = document.querySelector('h1');
    if (h1 && !document.getElementById('quick-message-btn')) {
      const btn = Object.assign(document.createElement('button'), { id: 'quick-message-btn', title: 'Send message to a number without saving', style: 'margin-left:10px;cursor:pointer;background:none;border:none;vertical-align:middle' });
      btn.innerHTML = '<img src="data:image/jpeg;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAAsgAAALIBa5Ro4AAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAdASURBVFiFrZd5bFXHFYe/uct79z3veD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VJXV8sf9uyyQyHzaZFXUHRMVeRdl3VdEmGHImLL8RLfqbFCrFhdPEd1aVWLFi+Jqa6uMq2IXXii1FeqhUxW/Dg/iNc1es33nTYi9W1KDjBmgONlvnOP5xcsqf7wg0OWaW89UeorhaFUvCg7wohRcIsqP3VZ9W133GPvWRWH36sBptxq0wD2HPNabk1SsCBkTkl3nIgpeKPc4wqbwx8uF1rVkbPQfUoTyGdP1LnGARytMf52rMTXNG/es3pSVtdWxxGu239wdO0fXyXA/wCAZxgqAMQESgAAAABJRU5ErkJggg==" alt="Message Icon" style="width:20px;height:20px">';
      btn.onclick = showModal;
      h1.parentElement.parentElement.insertBefore(btn, h1.parentElement.nextSibling);
    }
  };

  const showModal = () => {
    document.getElementById('quick-message-modal')?.remove();
    const isDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
    const modal = Object.assign(document.createElement('div'), { id: 'quick-message-modal', style: 'position:fixed;top:0;left:0;width:100%;height:100%;background:' + (isDark ? 'rgba(0,0,0,0.7)' : 'rgba(0,0,0,0.5)') + ';backdrop-filter:blur(5px);display:flex;align-items:center;justify-content:center;z-index:1000' });
    const content = Object.assign(document.createElement('div'), { style: 'background:' + (isDark ? '#1a1a1a' : '#fff') + ';color:' + (isDark ? '#fff' : '#000') + ';padding:20px;border-radius:8px;max-width:400px;width:100%;box-shadow:0 4px 8px rgba(0,0,0,0.2)' });
    content.onclick = e => e.stopPropagation();
    const input = Object.assign(document.createElement('input'), { type: 'text', placeholder: 'Enter phone number', style: 'width:-webkit-fill-available;padding:10px;margin:10px 0;border-radius:4px;background:rgb(51,51,51);color:rgb(255,255,255)', autofocus: true });
    const note = Object.assign(document.createElement('div'), { style: 'font-size:12px;color:' + (isDark ? '#bbb' : '#555') + ';margin-bottom:10px', innerHTML: 'Please include the country code (e.g., +1234567890)' });
    const btnRow = Object.assign(document.createElement('div'), { style: 'display:flex;gap:10px' });
    const checkBtn = Object.assign(document.createElement('button'), { textContent: 'Check Number', style: 'background:#25D366;color:#fff;padding:10px;border:none;border-radius:4px;cursor:pointer;flex:1' });
    checkBtn.onclick = () => { const num = input.value.trim().replace(/[\s-+]/g, ''); num && (window.location.href = `https://web.whatsapp.com/send/?phone=${num}`); modal.remove(); };
    const closeBtn = Object.assign(document.createElement('button'), { textContent: 'Close', style: 'background:' + (isDark ? '#444' : '#ccc') + ';color:' + (isDark ? '#fff' : '#000') + ';padding:10px;border:none;border-radius:4px;cursor:pointer;flex:1' });
    closeBtn.onclick = () => modal.remove();
    modal.onclick = e => e.target === modal && modal.remove();
    btnRow.append(checkBtn, closeBtn);
    content.append(input, note, btnRow);
    modal.appendChild(content);
    document.body.appendChild(modal);
  };

  blurElements();
  addMessageButton();

  const observer = new MutationObserver(mutations => mutations.forEach(m => m.addedNodes.length && (blurElements(), addMessageButton())));
  const target = document.querySelector('body');
  target && observer.observe(target, { childList: true, subtree: true });
  window.addEventListener('unload', () => observer.disconnect());
})
长期地址
遇到问题?请前往 GitHub 提 Issues。