// ==UserScript== // @name HTML Source Dot // @namespace http://tampermonkey.net/ // @version 1.0 // @description Minimal HTML source viewer with draggable red dot // @author YourName // @match *://*/* // @grant GM_setClipboard // @run-at document-start // ==/UserScript== (function() { 'use strict'; // 创建小红点元素 const dot = document.createElement('div'); dot.id = 'source-dot'; dot.style.cssText = ` position: fixed; top: 20px; left: 20px; width: 16px; height: 16px; background: #ff4444; border-radius: 50%; cursor: move; z-index: 99999; box-shadow: 0 0 4px rgba(0,0,0,0.3); transition: all 0.2s ease; `; // 创建隐藏的源码容器 const sourceContainer = document.createElement('div'); sourceContainer.id = 'source-container'; sourceContainer.style.cssText = ` display: none; position: fixed; z-index: 99998; background: white; border: 1px solid #ddd; border-radius: 4px; padding: 8px; max-width: 80vw; max-height: 80vh; overflow: auto; font-family: monospace; font-size: 12px; `; // 添加到文档 document.documentElement.appendChild(dot); document.documentElement.appendChild(sourceContainer); // 拖拽功能 let isDragging = false; let offsetX, offsetY; dot.addEventListener('mousedown', function(e) { if (e.button !== 0) return; // 只响应左键 isDragging = true; offsetX = e.clientX - dot.getBoundingClientRect().left; offsetY = e.clientY - dot.getBoundingClientRect().top; dot.style.cursor = 'grabbing'; }); document.addEventListener('mousemove', function(e) { if (!isDragging) return; dot.style.left = (e.clientX - offsetX) + 'px'; dot.style.top = (e.clientY - offsetY) + 'px'; }); document.addEventListener('mouseup', function() { isDragging = false; dot.style.cursor = 'move'; }); // 悬停效果 dot.addEventListener('mouseenter', function() { dot.style.transform = 'scale(1.5)'; dot.style.background = '#4CAF50'; dot.title = 'Click to copy HTML'; }); dot.addEventListener('mouseleave', function() { dot.style.transform = ''; dot.style.background = '#ff4444'; dot.title = ''; }); // 点击复制功能 dot.addEventListener('click', function() { const html = document.documentElement.outerHTML; GM_setClipboard(html, 'text'); // 显示临时提示 sourceContainer.textContent = 'HTML copied to clipboard!'; sourceContainer.style.display = 'block'; sourceContainer.style.left = (parseInt(dot.style.left) + 20) + 'px'; sourceContainer.style.top = dot.style.top; setTimeout(() => { sourceContainer.style.display = 'none'; }, 1500); }); // 立即显示小红点 dot.style.display = 'block'; // 持续更新源码(即使在加载过程中) const updateSource = () => { sourceContainer.textContent = document.documentElement.outerHTML; }; // 初始获取 updateSource(); // 定时更新 const interval = setInterval(updateSource, 300); window.addEventListener('DOMContentLoaded', () => { clearInterval(interval); updateSource(); }); window.addEventListener('load', updateSource); })();