// ==UserScript== // @name Notion Floating Heads Toggle // @namespace http://tampermonkey.net/ // @version 1.3 // @description Toggle visibility of floating head icons in Notion with a movable, color-changing icon button // @match https://www.notion.so/* // @grant GM_setValue // @grant GM_getValue // @license MIT // @downloadURL none // ==/UserScript== (function() { 'use strict'; let isVisible = true; let isDragging = false; let startX, startY, startLeft, startTop; function toggleFloatingHeads() { const containers = document.querySelectorAll('.notion-presence-container'); containers.forEach(container => { container.style.display = isVisible ? 'none' : ''; }); isVisible = !isVisible; updateButtonAppearance(); } function updateButtonAppearance() { const button = document.getElementById('toggleFloatingHeadsBtn'); if (button) { const iconColor = isVisible ? '#2eaadc' : '#ff4d4d'; button.querySelector('svg').style.fill = iconColor; button.title = isVisible ? 'Hide Floating Heads' : 'Show Floating Heads'; } } function createFloatingButton() { const button = document.createElement('button'); button.id = 'toggleFloatingHeadsBtn'; button.innerHTML = ` `; button.style.cssText = ` position: fixed; bottom: 20px; right: 70px; z-index: 9999; background-color: white; border: none; cursor: move; padding: 0; width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; border-radius: 50%; box-shadow: 0 2px 5px rgba(0,0,0,0.2); `; button.addEventListener('click', toggleFloatingHeads); button.addEventListener('mousedown', startDragging); document.addEventListener('mousemove', drag); document.addEventListener('mouseup', stopDragging); document.body.appendChild(button); updateButtonAppearance(); restorePosition(button); } function startDragging(e) { isDragging = true; startX = e.clientX; startY = e.clientY; startLeft = parseInt(window.getComputedStyle(this).left); startTop = parseInt(window.getComputedStyle(this).top); e.preventDefault(); // Prevent text selection } function drag(e) { if (!isDragging) return; const button = document.getElementById('toggleFloatingHeadsBtn'); const newLeft = startLeft + e.clientX - startX; const newTop = startTop + e.clientY - startY; button.style.left = `${newLeft}px`; button.style.top = `${newTop}px`; button.style.right = 'auto'; button.style.bottom = 'auto'; } function stopDragging() { if (!isDragging) return; isDragging = false; const button = document.getElementById('toggleFloatingHeadsBtn'); savePosition(button); } function savePosition(button) { const position = { left: button.style.left, top: button.style.top }; GM_setValue('buttonPosition', JSON.stringify(position)); } function restorePosition(button) { const savedPosition = GM_getValue('buttonPosition'); if (savedPosition) { const position = JSON.parse(savedPosition); button.style.left = position.left; button.style.top = position.top; button.style.right = 'auto'; button.style.bottom = 'auto'; } } function init() { console.log('Notion Floating Heads Toggle: Script started'); createFloatingButton(); console.log('Notion Floating Heads Toggle: Floating button created'); } // Run the script after a short delay to ensure Notion's UI is loaded setTimeout(init, 2000); })();