// ==UserScript== // @name 通用自动填充助手(按需版3.0) // @namespace http://tampermonkey.net/ // @version 3.0 // @description 智能填充各种网站的邮箱和密码字段,按需在特定网站激活,持久化保存激活状态 // @author yaya // @match *://*/* // @grant GM_setValue // @grant GM_getValue // @grant GM_registerMenuCommand // @icon https://cdn-icons-png.flaticon.com/512/2977/2977425.png // @downloadURL https://update.greasyfork.icu/scripts/549740/%E9%80%9A%E7%94%A8%E8%87%AA%E5%8A%A8%E5%A1%AB%E5%85%85%E5%8A%A9%E6%89%8B%28%E6%8C%89%E9%9C%80%E7%89%8830%29.user.js // @updateURL https://update.greasyfork.icu/scripts/549740/%E9%80%9A%E7%94%A8%E8%87%AA%E5%8A%A8%E5%A1%AB%E5%85%85%E5%8A%A9%E6%89%8B%28%E6%8C%89%E9%9C%80%E7%89%8830%29.meta.js // ==/UserScript== (function() { 'use strict'; // ============================== // 配置中心 - 在这里添加新网站配置 // ============================== const siteConfigs = [ // 港英云配置 { name: '港英云', urlPattern: /港英云/, fields: { email: { selector: 'input[placeholder="邮箱"]', events: ['input', 'change', 'blur', 'keydown', 'keyup'] }, password: { selector: 'input[placeholder="密码"][type="password"]', events: ['input', 'change', 'blur', 'keydown', 'keyup'] } }, loginButton: 'button.n-button--primary-type' }, // 通用配置 (作为后备) { name: '通用配置', urlPattern: /.*/, fields: { email: { selector: 'input[type="email"], input[id*="email"], input[name*="email"], input[placeholder*="邮箱"]', events: ['input', 'change'] }, password: { selector: 'input[type="password"], input[id*="password"], input[name*="password"], input[placeholder*="密码"]', events: ['input', 'change'] } }, loginButton: 'button[type="submit"], #login-btn, .login-button' } ]; // ============================== // 用户信息 // ============================== const USER_EMAIL = GM_getValue('user_email', 'xxx@example.com'); const USER_PASSWORD = GM_getValue('user_password', 'xxx'); // ============================== // 持久化激活的网站列表 // ============================== let activatedSites = GM_getValue('activatedSites', []); // **检查当前网站是否已激活** function isSiteActivated() { const currentDomain = location.hostname; return activatedSites.includes(currentDomain); } // **添加当前网站到激活列表** function activateSite() { const currentDomain = location.hostname; if (!activatedSites.includes(currentDomain)) { activatedSites.push(currentDomain); GM_setValue('activatedSites', activatedSites); console.log(`已激活网站: ${currentDomain}`); } } // ============================== // 核心功能 // ============================== // **增强填充函数** - 填充输入框并触发事件 function enhancedFillInput(selector, value, events = ['input', 'change']) { let filled = false; try { const inputs = document.querySelectorAll(selector); if (inputs.length > 0) { inputs.forEach(input => { input.value = value; events.forEach(eventType => { const event = new Event(eventType, { bubbles: true, cancelable: true }); input.dispatchEvent(event); }); console.log(`填充成功: ${selector}`, value); filled = true; }); } } catch (e) { console.error(`填充错误: ${selector}`, e); } return filled; } // **获取当前网站配置** - 优先匹配特定配置,否则使用通用配置 function getCurrentSiteConfig() { const specificConfig = siteConfigs.find(config => config.urlPattern.test(document.title) || config.urlPattern.test(location.href) ); if (specificConfig && specificConfig.name !== '通用配置') { return specificConfig; } return siteConfigs.find(config => config.name === '通用配置'); } // **自动填充主函数** - 执行填充并尝试登录 function autoFill() { const config = getCurrentSiteConfig(); if (!config) return {success: false, message: '未找到匹配的网站配置'}; let results = { email: false, password: false, configName: config.name }; if (config.fields.email) { results.email = enhancedFillInput( config.fields.email.selector, USER_EMAIL, config.fields.email.events ); } if (config.fields.password) { results.password = enhancedFillInput( config.fields.password.selector, USER_PASSWORD, config.fields.password.events ); } if (config.loginButton && results.email && results.password) { setTimeout(() => { const loginBtn = document.querySelector(config.loginButton); if (loginBtn) { loginBtn.click(); console.log('已尝试点击登录按钮'); } }, 800); } return results; } // **创建控制面板** function createControlPanel() { const panel = document.createElement('div'); panel.id = 'universal-fill-panel'; panel.style = ` position: fixed; bottom: 20px; right: 20px; background: white; border: 1px solid #e1e1e1; border-radius: 8px; padding: 10px 15px; box-shadow: 0 4px 10px rgba(0,0,0,0.1); z-index: 99999; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; min-width: 120px; max-width: 180px; transition: all 0.3s; `; panel.innerHTML = `