Notion 高亮挖空

Blurs highlighted text in Notion notes, reveals on hover with improved reliability

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Notion 高亮挖空
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Blurs highlighted text in Notion notes, reveals on hover with improved reliability
// @author       tianzhongs
// @match        https://*.notion.so/*
// @grant        GM_addStyle
// @license      CC BY-NC-ND 4.0
// ==/UserScript==

(function() {
    'use strict';

    // Inject CSS with higher specificity and pointer-events
    GM_addStyle(`
        /* Target Notion highlight classes or elements with background colors */
        .notion-page-content span[style*="background"],
        .notion-page-content [class*="color"],
        .notion-page-content span[style*="background-color"] {
            filter: blur(4px) !important;
            transition: filter 0.3s ease !important;
            pointer-events: auto !important;
            position: relative !important;
            z-index: 1 !important;
        }

        /* Remove blur on hover with higher specificity */
        .notion-page-content span[style*="background"]:hover,
        .notion-page-content [class*="color"]:hover,
        .notion-page-content span[style*="background-color"]:hover {
            filter: none !important;
        }
    `);

    // JavaScript fallback for hover handling
    function applyHoverEffect() {
        const highlights = document.querySelectorAll(
            '.notion-page-content span[style*="background"], .notion-page-content [class*="color"], .notion-page-content span[style*="background-color"]'
        );
        highlights.forEach(el => {
            // Ensure initial blur
            el.style.filter = 'blur(4px)';
            el.style.transition = 'filter 0.3s ease';
            el.style.pointerEvents = 'auto';

            // Add hover event listeners
            el.addEventListener('mouseenter', () => {
                el.style.filter = 'none';
            });
            el.addEventListener('mouseleave', () => {
                el.style.filter = 'blur(4px)';
            });
        });
    }

    // Run initial application of hover effect
    applyHoverEffect();

    // MutationObserver to handle dynamically loaded content
    const observer = new MutationObserver((mutations) => {
        mutations.forEach((mutation) => {
            if (mutation.addedNodes.length) {
                applyHoverEffect();
            }
        });
    });

    // Observe changes in the Notion page content
    const targetNode = document.querySelector('body');
    if (targetNode) {
        observer.observe(targetNode, { childList: true, subtree: true });
    }
})();