From 4cd4c675a4eabd3a26a74c150983d2197d5ae349 Mon Sep 17 00:00:00 2001 From: manchuwork Date: Tue, 5 Aug 2025 13:40:56 +0800 Subject: [PATCH] init --- script2.js | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 script2.js diff --git a/script2.js b/script2.js new file mode 100644 index 0000000..efa478a --- /dev/null +++ b/script2.js @@ -0,0 +1,105 @@ +// ==UserScript== +// @name 页面工具按钮 +// @namespace http://tampermonkey.net/ +// @version 0.1 +// @description 在页面右下角添加工具按钮,支持复制源码和解析公司信息 +// @author You +// @match *://*/* +// @grant none +// ==/UserScript== + +(function() { + 'use strict'; + + // 创建按钮容器 + function createButtonContainer() { + const container = document.createElement('div'); + container.id = 'tool-container'; + Object.assign(container.style, { + position: 'fixed', + right: '20px', + bottom: '20px', + zIndex: '9999', + display: 'flex', + flexDirection: 'column', + gap: '10px', + width: '40px', + height: '40px', + backgroundColor: '#4CAF50', + borderRadius: '50%', + transition: 'all 0.3s ease', + overflow: 'hidden', + cursor: 'pointer' + }); + + // +号指示器 + const plusSign = document.createElement('div'); + plusSign.textContent = '+'; + Object.assign(plusSign.style, { + color: 'white', + fontSize: '24px', + textAlign: 'center', + lineHeight: '40px', + width: '100%' + }); + container.appendChild(plusSign); + + // 悬停展开效果 + container.addEventListener('mouseenter', () => { + container.style.width = '150px'; + container.style.height = 'auto'; + container.style.borderRadius = '8px'; + }); + + container.addEventListener('mouseleave', () => { + container.style.width = '40px'; + container.style.height = '40px'; + container.style.borderRadius = '50%'; + }); + + // 创建功能按钮 + function createButton(text, onClick) { + const button = document.createElement('button'); + button.textContent = text; + Object.assign(button.style, { + padding: '8px 12px', + border: 'none', + borderRadius: '4px', + backgroundColor: 'white', + color: '#333', + cursor: 'pointer', + width: '100%', + transition: 'backgroundColor 0.2s' + }); + button.addEventListener('mouseenter', () => button.style.backgroundColor = '#f0f0f0'); + button.addEventListener('mouseleave', () => button.style.backgroundColor = 'white'); + button.addEventListener('click', onClick); + return button; + } + + // 复制源码按钮 + const copySourceButton = createButton('复制源码', () => { + const html = document.documentElement.outerHTML; + navigator.clipboard.writeText(html).then(() => { + alert('源码已复制到剪贴板'); + }).catch(err => { + console.error('复制失败:', err); + }); + }); + + // 解析公司信息按钮 + const parseInfoButton = createButton('解析公司信息', () => { + // 这里添加解析公司信息的逻辑 + alert('解析公司信息功能待实现'); + }); + + // 添加按钮到容器 + container.appendChild(copySourceButton); + container.appendChild(parseInfoButton); + + document.body.appendChild(container); + } + + // 页面加载完成后创建按钮 + window.addEventListener('load', createButtonContainer); +})();