// ==UserScript== // @name 123网盘口令助手 // @namespace https://greasyfork.org/zh-CN/users/1135389-chumor // @version 0.1.0 // @description 提取并复制123网盘口令,支持手动扫描与复制解锁开关,提供底部Toast提示。 // @author Chumor // @license MIT // @match https://www.123pan.com/* // @match https://www.123pan.cn/* // @grant GM_setClipboard // @grant GM_registerMenuCommand // @grant GM_getValue // @grant GM_setValue // ==/UserScript== (function () { "use strict"; /** * 显示底部 Toast 提示 * @param {string} msg - 要显示的提示文本 */ function notify(msg) { const div = document.createElement("div"); div.textContent = msg; div.style.cssText = ` position: fixed; bottom: 12%; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,0.75); color: #fff; padding: 8px 14px; border-radius: 20px; font-size: 14px; max-width: 80%; text-align: center; z-index: 99999; `; document.body.appendChild(div); setTimeout(() => { div.style.transition = "opacity 0.4s"; div.style.opacity = "0"; setTimeout(() => div.remove(), 400); }, 1800); } /** * 复制文本到剪贴板 * @param {string} text - 要复制的内容 */ function copy(text) { try { GM_setClipboard(text); notify("口令已复制"); } catch { notify("复制失败"); } } /** * 扫描页面中的123网盘口令并复制 * 口令格式示例: ##Xa23QfOeoNreoBa## */ function scanCode() { const regex = /##[A-Za-z0-9]+##/; const match = document.body.innerText.match(regex); if (match) { copy(match[0]); return true; } notify("未发现口令"); return false; } /** * 复制解锁功能(允许网页中的复制与右键) */ const KEY = "unlock_copy"; let unlock = GM_getValue(KEY, false); function toggleUnlock() { unlock = !unlock; GM_setValue(KEY, unlock); if (unlock) { document.addEventListener("copy", stop, true); document.addEventListener("contextmenu", stop, true); notify("复制解锁已开启"); } else { document.removeEventListener("copy", stop, true); document.removeEventListener("contextmenu", stop, true); notify("复制解锁已关闭"); } } function stop(e) { e.stopPropagation(); } if (unlock) toggleUnlock(); // 注册菜单功能 GM_registerMenuCommand("重新扫描口令", scanCode); GM_registerMenuCommand(unlock ? "关闭复制解锁" : "开启复制解锁", toggleUnlock); })();