// ==UserScript== // @name 【微信文件传输登陆保存】— 登录助手 (WeUI 优化版) // @namespace https://greasyfork.org/zh-CN/users/927947-witchery // @version 2.0.1 // @description 界面全面重构:采用微信原生 WeUI 风格,仅保留登录保存与恢复功能,仅在 szfilehelper 生效。 // @author witcher (Modified by AI) // @match https://szfilehelper.weixin.qq.com/* // @grant GM_setValue // @grant GM_getValue // @grant GM_addStyle // @require https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/js/all.min.js // ==/UserScript== (function () { // 严格限制运行域名 if (!location.href.startsWith("https://szfilehelper.weixin.qq.com/")) { return; } const ver = '2.0.0-weui'; const WECHAT_GREEN = '#07C160'; const WECHAT_RED = '#FA5151'; const WECHAT_BLUE = '#10AEFF'; const BG_COLOR = '#F7F7F7'; // 注入样式 const style = document.createElement('style'); style.textContent = ` @import url('https://fonts.googleapis.com/css2?family=PingFang+SC:wght@400;500;600&display=swap'); :root { --wx-green: ${WECHAT_GREEN}; --wx-red: ${WECHAT_RED}; --wx-blue: ${WECHAT_BLUE}; --wx-bg: ${BG_COLOR}; } /* 侧边面板 */ .login-tool-panel { background: #ffffff; width: 0px; height: 70%; position: fixed; z-index: 99999; top: 15%; left: 0; overflow: hidden; transition: width 0.4s cubic-bezier(0.25, 0.8, 0.25, 1); box-shadow: 4px 0px 20px rgba(0,0,0,0.08); border-radius: 0 12px 12px 0; font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", Arial, sans-serif; display: flex; flex-direction: column; } /* 面板头部 */ .panel-header { padding: 20px 25px; border-bottom: 1px solid #f0f0f0; background: #fff; min-width: 280px; } .panel-title { font-size: 18px; font-weight: 600; color: #333; margin: 0; display: flex; align-items: center; gap: 8px; } .panel-title i { color: var(--wx-green); } .panel-subtitle { font-size: 12px; color: #999; margin-top: 5px; } /* 内容区域 */ .panel-body { padding: 20px 25px; flex: 1; overflow-y: auto; min-width: 280px; background: #fafafa; } /* 按钮组 */ .action-group { display: flex; flex-direction: column; gap: 15px; } .tool-btn { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; padding: 12px 0; border: none; border-radius: 8px; font-size: 15px; font-weight: 500; cursor: pointer; transition: all 0.2s ease; position: relative; overflow: hidden; color: white; box-shadow: 0 2px 6px rgba(0,0,0,0.1); } .tool-btn:active { transform: scale(0.98); } .tool-btn:hover { opacity: 0.9; box-shadow: 0 4px 12px rgba(0,0,0,0.15); } .btn-save { background: linear-gradient(135deg, #07C160 0%, #06AD56 100%); } .btn-restore { background: linear-gradient(135deg, #10AEFF 0%, #0099E0 100%); } .btn-clear { background: linear-gradient(135deg, #FA5151 0%, #E04545 100%); } /* 悬浮开关 */ .tool-toggle-btn { position: fixed; left: 0; top: 75%; z-index: 99998; background: var(--wx-green); color: white; padding: 10px 14px; border-radius: 0 8px 8px 0; cursor: pointer; box-shadow: 2px 2px 10px rgba(0,0,0,0.15); font-size: 13px; font-weight: 600; transition: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1); display: flex; align-items: center; gap: 6px; user-select: none; } .tool-toggle-btn:hover { background: #06AD56; } /* Toast 提示 */ .toast-container { position: fixed; top: 20px; left: 50%; transform: translateX(-50%) translateY(-100px); background: rgba(0,0,0,0.75); color: white; padding: 10px 20px; border-radius: 50px; font-size: 14px; z-index: 100000; transition: transform 0.3s ease; backdrop-filter: blur(4px); display: flex; align-items: center; gap: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.2); } .toast-show { transform: translateX(-50%) translateY(0); } /* 版本信息 */ .version-info { text-align: center; font-size: 11px; color: #ccc; margin-top: auto; padding-bottom: 10px; min-width: 280px; } `; document.head.appendChild(style); // 构建 HTML const panelHTML = `

登录管理

安全保存您的会话状态
v.${ver} | SZ FileHelper
登录助手
操作成功
`; const container = document.createElement('div'); container.innerHTML = panelHTML; document.body.appendChild(container); // 元素引用 const panel = document.getElementById('loginPanel'); const toggleBtn = document.getElementById('toggleBtn'); const toast = document.getElementById('toast'); const btnSave = document.getElementById('btnSave'); const btnRestore = document.getElementById('btnRestore'); const btnClear = document.getElementById('btnClear'); let isOpen = false; // 切换面板 function togglePanel() { isOpen = !isOpen; if (isOpen) { panel.style.width = '300px'; toggleBtn.innerHTML = ' 收起'; toggleBtn.style.marginLeft = '270px'; toggleBtn.style.background = '#fff'; toggleBtn.style.color = '#333'; } else { panel.style.width = '0px'; toggleBtn.innerHTML = ' 登录助手'; toggleBtn.style.marginLeft = '0px'; toggleBtn.style.background = WECHAT_GREEN; toggleBtn.style.color = '#fff'; } } // Toast 提示函数 function showToast(msg, type = 'success') { const icon = type === 'success' ? 'fa-check-circle' : (type === 'error' ? 'fa-exclamation-circle' : 'fa-info-circle'); const color = type === 'success' ? '#07C160' : (type === 'error' ? '#FA5151' : '#10AEFF'); toast.innerHTML = ` ${msg}`; toast.classList.add('toast-show'); setTimeout(() => { toast.classList.remove('toast-show'); }, 2500); } // 辅助:设置 Cookie function setCookie(name, value, days) { let expires = ""; if (days) { const date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); expires = "; expires=" + date.toUTCString(); } document.cookie = name + "=" + encodeURIComponent(value) + expires + "; path=/"; } // 事件监听 toggleBtn.addEventListener('click', togglePanel); // 1. 保存登录 btnSave.addEventListener('click', () => { const currentCookie = document.cookie; if (!currentCookie || currentCookie.length < 10) { showToast('未检测到有效登录,请先扫码', 'error'); return; } GM_setValue('wx_ck_backup_sz', currentCookie); showToast('登录信息已安全保存', 'success'); // 简单的按钮动画反馈 const originalText = btnSave.innerHTML; btnSave.innerHTML = ' 已保存'; setTimeout(() => btnSave.innerHTML = originalText, 1500); }); // 2. 恢复登录 btnRestore.addEventListener('click', () => { const savedCookie = GM_getValue('wx_ck_backup_sz'); if (!savedCookie) { showToast('暂无保存的登录记录', 'error'); return; } const cookiePairs = savedCookie.split(";"); let count = 0; for (let i = 0; i < cookiePairs.length; i++) { const pair = cookiePairs[i].split("="); if (pair[0] && pair[1]) { setCookie(pair[0].trim(), pair[1], 399999); count++; } } if (count > 0) { showToast('正在恢复登录,页面将刷新...', 'success'); setTimeout(() => location.reload(), 1200); } else { showToast('恢复失败,记录可能已损坏', 'error'); } }); // 3. 清空数据 btnClear.addEventListener('click', () => { if(!confirm('确定要清空所有登录备份吗?\n此操作不可恢复,您将需要重新扫码登录。')) return; // 清除 Cookie const cookies = document.cookie.split(";"); for (let i = 0; i < cookies.length; i++) { const cookie = cookies[i]; const eqPos = cookie.indexOf("="); const name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie; document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/"; } GM_setValue('wx_ck_backup_sz', ''); showToast('已清空所有数据', 'success'); setTimeout(() => location.reload(), 1000); }); // 初始化:首次加载自动微展开提示用户(可选,1秒后自动收起) setTimeout(() => { if (!GM_getValue('wx_ck_backup_sz')) { // 如果没有保存过,稍微展开提示一下 panel.style.width = '60px'; setTimeout(() => { if(!isOpen) panel.style.width = '0px'; }, 2000); } }, 1000); })();