// ==UserScript== // @name 网页工具箱 - 多功能网页增强工具 // @namespace http://tampermonkey.net/ // @version 1.0 // @description 集合多种实用网页工具的增强插件,包括广告屏蔽、阅读模式、网页截图、链接提取等功能 // @author shenfangda // @match *://*/* // @grant GM_addStyle // @grant GM_setClipboard // @grant GM_download // @grant GM_xmlhttpRequest // @grant GM_info // @connect * // @license MIT // @downloadURL https://update.greasyfork.icu/scripts/549897/%E7%BD%91%E9%A1%B5%E5%B7%A5%E5%85%B7%E7%AE%B1%20-%20%E5%A4%9A%E5%8A%9F%E8%83%BD%E7%BD%91%E9%A1%B5%E5%A2%9E%E5%BC%BA%E5%B7%A5%E5%85%B7.user.js // @updateURL https://update.greasyfork.icu/scripts/549897/%E7%BD%91%E9%A1%B5%E5%B7%A5%E5%85%B7%E7%AE%B1%20-%20%E5%A4%9A%E5%8A%9F%E8%83%BD%E7%BD%91%E9%A1%B5%E5%A2%9E%E5%BC%BA%E5%B7%A5%E5%85%B7.meta.js // ==/UserScript== (function() { 'use strict'; // 配置 const config = { // 工具列表 tools: [ { id: 'adblock', name: '广告屏蔽', icon: '🚫' }, { id: 'reader', name: '阅读模式', icon: '📖' }, { id: 'screenshot', name: '网页截图', icon: '📸' }, { id: 'links', name: '链接提取', icon: '🔗' }, { id: 'text', name: '文本提取', icon: '📝' }, { id: 'password', name: '密码生成', icon: '🔑' }, { id: 'qrcode', name: '二维码生成', icon: '🔲' }, { id: 'translate', name: '快速翻译', icon: '🌐' } ], // 默认设置 defaultSettings: { adblockSelectors: [ '广告', '.ad', '.ads', '.advertisement', '[class*="ad-"]', '[id*="ad-"]', '.google-ads', '.banner-ad', '.sidebar-ad' ], readerMode: { maxWidth: 800, lineHeight: 1.6, fontSize: 16, fontFamily: 'Arial, sans-serif' } } }; // 主要功能类 class WebToolkit { constructor() { this.settings = {...config.defaultSettings}; this.init(); } init() { console.log('网页工具箱已启动'); this.createUI(); this.bindEvents(); } // 创建用户界面 createUI() { GM_addStyle(` #web-toolkit-panel { position: fixed; top: 20px; right: 20px; width: 300px; max-height: 80vh; background: #fff; border: 1px solid #ccc; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.15); z-index: 10000; font-family: Arial, sans-serif; font-size: 14px; overflow: hidden; display: none; } #web-toolkit-panel-header { background: #2c3e50; color: white; padding: 12px 15px; cursor: move; display: flex; justify-content: space-between; align-items: center; } #web-toolkit-panel-title { font-weight: bold; font-size: 16px; } #web-toolkit-panel-close { background: none; border: none; color: white; font-size: 20px; cursor: pointer; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; border-radius: 50%; } #web-toolkit-panel-close:hover { background: rgba(255,255,255,0.2); } #web-toolkit-panel-content { padding: 15px; overflow-y: auto; max-height: calc(80vh - 50px); } .web-toolkit-section { margin-bottom: 20px; } .web-toolkit-section-title { font-weight: bold; margin-bottom: 12px; color: #2c3e50; border-bottom: 1px solid #eee; padding-bottom: 6px; display: flex; align-items: center; } .web-toolkit-section-title i { margin-right: 8px; font-size: 16px; } .web-toolkit-tools-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; } .web-toolkit-tool-item { padding: 12px; background: #f8f9fa; border: 1px solid #e9ecef; border-radius: 6px; cursor: pointer; transition: all 0.2s; display: flex; flex-direction: column; align-items: center; text-align: center; } .web-toolkit-tool-item:hover { background: #e9ecef; transform: translateY(-2px); box-shadow: 0 2px 5px rgba(0,0,0,0.1); } .web-toolkit-tool-icon { font-size: 24px; margin-bottom: 8px; } .web-toolkit-tool-name { font-size: 13px; color: #495057; } .web-toolkit-btn { padding: 10px 15px; background: #3498db; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 14px; width: 100%; margin-top: 5px; transition: background 0.2s; } .web-toolkit-btn:hover { background: #2980b9; } .web-toolkit-btn.secondary { background: #95a5a6; } .web-toolkit-btn.secondary:hover { background: #7f8c8d; } .web-toolkit-btn.success { background: #27ae60; } .web-toolkit-btn.success:hover { background: #229954; } .web-toolkit-btn.danger { background: #e74c3c; } .web-toolkit-btn.danger:hover { background: #c0392b; } .web-toolkit-input-group { margin-bottom: 15px; } .web-toolkit-input-group label { display: block; margin-bottom: 5px; font-weight: 500; color: #495057; } .web-toolkit-input { width: 100%; padding: 8px 12px; border: 1px solid #ddd; border-radius: 4px; font-size: 14px; box-sizing: border-box; } .web-toolkit-textarea { width: 100%; padding: 8px 12px; border: 1px solid #ddd; border-radius: 4px; font-size: 14px; box-sizing: border-box; min-height: 100px; resize: vertical; } .web-toolkit-result { background: #f8f9fa; border: 1px solid #e9ecef; border-radius: 4px; padding: 12px; margin-top: 10px; max-height: 200px; overflow-y: auto; } .web-toolkit-notification { position: fixed; top: 20px; right: 20px; background: #27ae60; color: white; padding: 12px 20px; border-radius: 4px; box-shadow: 0 2px 10px rgba(0,0,0,0.2); z-index: 10001; display: none; } #web-toolkit-toggle-btn { position: fixed; top: 20px; right: 20px; width: 45px; height: 45px; background: #2c3e50; color: white; border: none; border-radius: 50%; box-shadow: 0 2px 10px rgba(0,0,0,0.2); cursor: pointer; z-index: 9999; font-size: 20px; display: flex; align-items: center; justify-content: center; } #web-toolkit-toggle-btn:hover { background: #34495e; transform: scale(1.05); } .web-toolkit-password-container { display: flex; gap: 10px; } .web-toolkit-password-container .web-toolkit-input { flex: 1; } .web-toolkit-qrcode-container { text-align: center; } .web-toolkit-qrcode-container canvas { max-width: 100%; border: 1px solid #ddd; border-radius: 4px; } `); // 创建主面板 const panel = document.createElement('div'); panel.id = 'web-toolkit-panel'; panel.innerHTML = `
工具 "${tool.name}" 尚未实现
`; } // 添加返回按钮 const backButton = document.createElement('button'); backButton.className = 'web-toolkit-btn secondary'; backButton.textContent = '← 返回工具列表'; backButton.onclick = () => { toolDetails.style.display = 'none'; this.initToolsGrid(); }; toolDetails.appendChild(backButton); } // 渲染广告屏蔽工具 renderAdblockTool(container) { container.innerHTML = `点击下方按钮屏蔽页面中的广告元素
`; document.getElementById('web-toolkit-adblock-btn').addEventListener('click', () => { this.blockAds(); }); } // 渲染阅读模式工具 renderReaderTool(container) { container.innerHTML = `点击下方按钮进入阅读模式,专注于文章内容
`; document.getElementById('web-toolkit-reader-btn').addEventListener('click', () => { this.enterReaderMode(); }); } // 渲染网页截图工具 renderScreenshotTool(container) { container.innerHTML = `点击下方按钮截取当前网页
`; document.getElementById('web-toolkit-screenshot-btn').addEventListener('click', () => { this.takeScreenshot(); }); } // 渲染链接提取工具 renderLinksTool(container) { container.innerHTML = `点击下方按钮提取页面中的所有链接
`; document.getElementById('web-toolkit-links-btn').addEventListener('click', () => { this.extractLinks(); }); } // 渲染文本提取工具 renderTextTool(container) { container.innerHTML = `点击下方按钮提取页面中的所有文本内容
`; document.getElementById('web-toolkit-text-btn').addEventListener('click', () => { this.extractText(); }); } // 渲染密码生成工具 renderPasswordTool(container) { container.innerHTML = `截图功能说明:
完整截图功能需要使用 html2canvas 或类似库,此版本为演示。
您可以手动使用浏览器的截图功能:
未找到链接
'; return; } let html = `找到 ${links.length} 个链接:
未找到文本内容
'; return; } // 截取前1000个字符作为预览 const preview = text.substring(0, 1000); const fullText = text; result.innerHTML = `文本长度: ${fullText.length} 字符
`; document.getElementById('web-toolkit-text-copy').addEventListener('click', () => { GM_setClipboard(fullText); this.showNotification('文本已复制到剪贴板'); }); this.showNotification(`提取到 ${fullText.length} 字符的文本`); } // 生成密码 generatePassword() { const length = parseInt(document.getElementById('web-toolkit-password-length').value) || 12; const includeUppercase = document.getElementById('web-toolkit-password-uppercase').checked; const includeNumbers = document.getElementById('web-toolkit-password-numbers').checked; const includeSymbols = document.getElementById('web-toolkit-password-symbols').checked; let charset = 'abcdefghijklmnopqrstuvwxyz'; if (includeUppercase) charset += 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; if (includeNumbers) charset += '0123456789'; if (includeSymbols) charset += '!@#$%^&*()_+-=[]{}|;:,.<>?'; let password = ''; for (let i = 0; i < length; i++) { const randomIndex = Math.floor(Math.random() * charset.length); password += charset[randomIndex]; } document.getElementById('web-toolkit-password-result').value = password; this.showNotification('密码已生成'); } // 复制密码 copyPassword() { const password = document.getElementById('web-toolkit-password-result').value; if (password) { GM_setClipboard(password); this.showNotification('密码已复制到剪贴板'); } } // 生成二维码 generateQRCode() { const text = document.getElementById('web-toolkit-qrcode-text').value; if (!text) { this.showNotification('请输入文本内容'); return; } const result = document.getElementById('web-toolkit-qrcode-result'); result.innerHTML = `二维码内容: ${text}
由于版权原因,完整二维码生成功能需要引入第三方库。
您可以使用在线二维码生成器或安装专门的二维码插件。
`; this.showNotification('二维码生成功能需要第三方库支持'); } // 翻译文本 translateText() { const text = document.getElementById('web-toolkit-translate-input').value; const targetLang = document.getElementById('web-toolkit-translate-target').value; if (!text) { this.showNotification('请输入要翻译的文本'); return; } const result = document.getElementById('web-toolkit-translate-result'); result.style.display = 'block'; // 模拟翻译结果 const translations = { 'zh': '这是翻译后的中文文本', 'en': 'This is the translated English text', 'ja': 'これは翻訳された日本語テキストです', 'ko': '이것은 번역된 한국어 텍스트입니다', 'fr': 'Ceci est le texte traduit en français', 'de': 'Dies ist der übersetzte deutsche Text', 'es': 'Este es el texto traducido al español' }; result.innerHTML = `翻译结果 (${targetLang}):
${translations[targetLang] || translations['en']}
注意:实际翻译功能需要调用翻译API
`; this.showNotification('翻译功能为演示版本'); } // 显示通知 showNotification(message) { const notification = document.getElementById('web-toolkit-notification'); notification.textContent = message; notification.style.display = 'block'; setTimeout(() => { notification.style.display = 'none'; }, 3000); } } // 初始化插件 new WebToolkit(); })();