VK Image Blur for Specific Users

Blurs images from specific users in VK conversations and removes blur on hover

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         VK Image Blur for Specific Users
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  Blurs images from specific users in VK conversations and removes blur on hover
// @author       antowkas
// @match        https://vk.com/im*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Задайте список имен пользователей, чьи изображения нужно размыть
    const targetNames = ["Дима Михайлов", "ミリフ 遺構"];

    function blurImagesForUsers() {
        // Находим все сообщения в истории беседы
        const messages = document.querySelectorAll('.ConvoHistory__dateStack section');

        messages.forEach(message => {
            // Находим имя отправителя сообщения
            const authorElement = message.querySelector('.ConvoMessageHeader__authorLink .PeerTitle__title');
            if (authorElement && targetNames.includes(authorElement.textContent.trim())) {
                // Находим все изображения в сообщении и применяем к ним blur
                const images = message.querySelectorAll('img.PhotoItem__img, img.ReImage__img');
                images.forEach(img => {
                    img.style.filter = 'blur(10px)'; // Применяем размытие

                    // Добавляем обработчики событий для наведения и ухода курсора
                    img.addEventListener('mouseenter', () => {
                        img.style.filter = 'none'; // Убираем размытие при наведении
                    });

                    img.addEventListener('mouseleave', () => {
                        img.style.filter = 'blur(10px)'; // Возвращаем размытие при уходе курсора
                    });
                });
            }
        });
    }

    // Выполняем функцию сразу после загрузки страницы
    window.addEventListener('load', blurImagesForUsers);

    // Также добавляем наблюдатель за изменениями в DOM, чтобы обрабатывать новые сообщения
    const observer = new MutationObserver(blurImagesForUsers);
    observer.observe(document.body, { childList: true, subtree: true });

})();