// ==UserScript== // @name 123网盘口令助手 // @namespace https://scriptcat.org/zh-CN/users/156019 // @version 0.2.0 // @description 自动扫描并复制 123 网盘口令,支持开关控制,带底部 Toast 提示 // @author Chumor // @match *://www.123pan.com/* // @match *://www.123pan.cn/* // @grant GM_addStyle // @grant GM_setClipboard // @grant GM_registerMenuCommand // @grant GM_getValue // @grant GM_setValue // @license MIT // ==/UserScript== (function() { 'use strict'; /*********************** * 样式:底部 Toast 提示 ***********************/ GM_addStyle(` .toast { visibility: hidden; min-width: 120px; margin-left: -60px; background-color: rgba(0,0,0,0.75); color: #fff; text-align: center; border-radius: 8px; padding: 12px; position: fixed; z-index: 9999; left: 50%; bottom: 30px; font-size: 14px; transition: visibility 0s, opacity 0.3s linear; opacity: 0; } .toast.show { visibility: visible; opacity: 1; } `); /** * 显示底部提示 * @param {string} msg - 提示文字 */ function showToast(msg) { let toast = document.createElement("div"); toast.className = "toast"; toast.innerText = msg; document.body.appendChild(toast); setTimeout(() => { toast.classList.add("show"); }, 100); setTimeout(() => { toast.classList.remove("show"); setTimeout(() => document.body.removeChild(toast), 300); }, 2000); } /** * 扫描页面中的口令并复制 */ function scanAndCopyCode() { let regex = /\b\d{3}\b/g; // 匹配3位数字口令 let match = document.body.innerText.match(regex); if (match) { GM_setClipboard(match[0]); showToast("口令已复制: " + match[0]); } else { showToast("未找到口令"); } } /** * 自动复制逻辑 */ let autoCopy = GM_getValue("autoCopy", false); // 默认关闭 if (autoCopy) { scanAndCopyCode(); } /** * 注册菜单命令 */ GM_registerMenuCommand("🔍 扫描并复制口令", scanAndCopyCode); GM_registerMenuCommand((autoCopy ? "❌ 关闭自动复制" : "✅ 启用自动复制"), () => { GM_setValue("autoCopy", !autoCopy); showToast("自动复制已" + (autoCopy ? "关闭" : "启用")); }); })();