// ==UserScript== // @name 小六壬起卦助手 - 全局赛博圣杯版 // @namespace http://tampermonkey.net/ // @version 4.3.1 // @description 全局页面运行支持,极致逼真筊杯动画,历史记忆,快捷注册通道与暖心鼓励 // @author Gemini // @match *://*/* // @match file:///* // @include * // @require https://unpkg.com/lunar-javascript/lunar.js // @grant GM_xmlhttpRequest // @grant GM_setValue // @grant GM_getValue // @grant GM_registerMenuCommand // @grant GM_addStyle // @connect api.siliconflow.cn // ==/UserScript== (function() { 'use strict'; if (window.top !== window.self) { return; } const svgConvex = `data:image/svg+xml;utf8,`; const svgFlat = `data:image/svg+xml;utf8,`; // ========================================== // 1. 注入 CSS 样式 // ========================================== GM_addStyle(` #xlr-float-btn { position: fixed; bottom: 30px; right: 30px; width: 50px; height: 50px; background-color: #F5F5F3; border: 2px solid #8B1D1D; border-radius: 8px; color: #8B1D1D; font-size: 24px; font-family: "Kaiti SC", "STKaiti", "Kaiti", serif; display: flex; justify-content: center; align-items: center; cursor: pointer; z-index: 2147483647; box-shadow: 2px 2px 10px rgba(0,0,0,0.1); transition: all 0.3s ease; } #xlr-float-btn:hover { background-color: #8B1D1D; color: #F5F5F3; transform: scale(1.05); } #xlr-app-wrapper { display: none; position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(0, 0, 0, 0.4); backdrop-filter: blur(3px); z-index: 2147483647; justify-content: center; align-items: center; font-family: "Kaiti SC", "STKaiti", "Kaiti", "Songti SC", "SimSun", serif; } #xlr-container { background-color: #F5F5F3; background-image: radial-gradient(#e2e2e2 1px, transparent 1px); background-size: 20px 20px; width: 90%; max-width: 500px; max-height: 85vh; overflow-y: auto; overflow-x: hidden; padding: 30px; border-radius: 8px; border: 1px solid #D3D3D3; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2); position: relative; color: #333333; } .xlr-header-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 5px; position: relative; z-index: 10; border-bottom: 1px solid #D3D3D3; padding-bottom: 10px; } .xlr-tab { font-size: 15px; color: #888; cursor: pointer; margin-right: 15px; transition: all 0.3s; padding-bottom: 5px; } .xlr-tab:hover { color: #8B1D1D; } .xlr-tab.active { color: #8B1D1D; font-weight: bold; border-bottom: 2px solid #8B1D1D; } #xlr-close-btn { font-size: 28px; cursor: pointer; color: #888; line-height: 1; margin-top: -5px; margin-right: -10px;} #xlr-close-btn:hover { color: #8B1D1D; } #xlr-container h1 { text-align: center; font-size: 26px; font-weight: normal; letter-spacing: 4px; margin-top: 20px; margin-bottom: 25px; color: #333; position: relative; } #xlr-container h1::after { content: "印"; position: absolute; top: -10px; right: 25%; font-size: 12px; color: #8B1D1D; border: 1px solid #8B1D1D; padding: 2px; border-radius: 2px; opacity: 0.8; transform: rotate(-10deg); } .section { margin-bottom: 20px; } #xlr-container label { display: block; margin-bottom: 8px; font-size: 16px; color: #555; } #xlr-container input[type="text"], #xlr-container input[type="password"], #xlr-container select { width: 100%; padding: 12px; border: 1px solid #D3D3D3; background: rgba(255,255,255,0.7); border-radius: 4px; font-family: inherit; font-size: 15px; box-sizing: border-box; transition: all 0.3s; } #xlr-container input:focus, #xlr-container select:focus { outline: none; border-color: #8B1D1D; box-shadow: 0 0 5px rgba(139, 29, 29, 0.2); } .xlr-btn { width: 100%; padding: 14px; background-color: transparent; border: 1px solid #8B1D1D; color: #8B1D1D; font-size: 18px; font-family: inherit; cursor: pointer; border-radius: 4px; letter-spacing: 2px; transition: all 0.3s ease; margin-top: 10px; font-weight: bold; } .xlr-btn:hover { background-color: #8B1D1D; color: #fff; } /* 注册快捷按钮 */ .xlr-btn-outline { display: block; width: 100%; padding: 10px; border: 1px dashed #8B1D1D; color: #8B1D1D; text-align: center; text-decoration: none; border-radius: 4px; font-size: 14px; transition: all 0.3s; box-sizing: border-box; margin-top: 10px; background: rgba(139,29,29,0.02); } .xlr-btn-outline:hover { background-color: rgba(139,29,29,0.08); color: #8B1D1D; text-decoration: none;} /* 作者抖音按钮 */ .xlr-btn-douyin { display: block; width: 100%; padding: 12px; border: 1px dashed #333; color: #333; text-align: center; text-decoration: none; border-radius: 4px; font-size: 15px; font-weight: bold; transition: all 0.3s; box-sizing: border-box; margin-top: 25px; background: rgba(0,0,0,0.02); } .xlr-btn-douyin:hover { background-color: #111; color: #fff; text-decoration: none; border: 1px solid #111;} .xlr-view { display: none; } .xlr-view.active { display: block; } /* 结果与历史区 */ #xlr-resultArea { display: none; margin-top: 25px; padding-top: 20px; border-top: 1px dashed #D3D3D3; } .gua-badge { display: inline-block; padding: 5px 15px; border-radius: 20px; border: 1px solid #8B1D1D; color: #8B1D1D; margin: 0 5px; font-size: 18px; background: rgba(139,29,29,0.05); } .gua-title-wrap { text-align: center; margin-bottom: 15px; } .gua-time { text-align: center; font-size: 13px; color: #777; margin-bottom: 15px; } .ai-response { line-height: 1.8; font-size: 16px; text-align: justify; white-space: pre-wrap; color: #333; } /* 暖心寄语固定底部 */ .xlr-encouragement { margin-top: 25px; padding-top: 20px; border-top: 1px solid rgba(139,29,29,0.1); text-align: center; color: #A32626; font-size: 15px; letter-spacing: 2px; line-height: 1.6; } .xlr-history-item { background: rgba(255,255,255,0.5); border: 1px solid #eee; padding: 15px; margin-bottom: 15px; border-radius: 4px; border-left: 3px solid #8B1D1D; } .xlr-h-time { font-size: 12px; color: #888; margin-bottom: 5px; } .xlr-h-q { font-size: 15px; color: #333; font-weight: bold; margin-bottom: 10px; } .xlr-h-a { font-size: 14px; color: #555; white-space: pre-wrap; display: none; margin-top: 10px; padding-top: 10px; border-top: 1px dashed #ccc;} .xlr-h-toggle { font-size: 13px; color: #8B1D1D; cursor: pointer; user-select: none; } /* ================= 沉浸式动画遮罩 ================= */ #xlr-loadingOverlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(245, 245, 243, 0.95); display: flex; flex-direction: column; justify-content: center; align-items: center; z-index: 20; opacity: 0; pointer-events: none; transition: opacity 0.4s ease; border-radius: 8px; } #xlr-loadingOverlay.active { opacity: 1; pointer-events: all; } .xlr-loading-text { margin-top: 30px; font-size: 18px; letter-spacing: 2px; color: #555; } #xlr-anim-hand { width: 100px; height: 100px; background-image: url('https://cdn.jsdelivr.net/gh/jdecked/twemoji@15.1.0/assets/svg/1f90f-1f3fb.svg'); background-size: contain; background-repeat: no-repeat; background-position: center; filter: sepia(0.6) hue-rotate(-15deg) contrast(1.1); animation: xlrCalculateAnim 0.6s infinite alternate ease-in-out; } @keyframes xlrCalculateAnim { 0% { transform: translateY(0) rotate(0deg) scale(1); } 100% { transform: translateY(-10px) rotate(-10deg) scale(1.05); } } #xlr-anim-jiaobei { display: none; position: relative; width: 150px; height: 120px; } .jb-cup { position: absolute; width: 50px; height: 100px; background-size: contain; background-repeat: no-repeat; background-position: center; background-image: url('${svgConvex}'); top: -200px; } .jb-cup.is-flat { background-image: url('${svgFlat}'); } .jb-left { left: 15px; } .jb-right { right: 15px; transform: scaleX(-1); } .anim-drop-left { animation: dropBouncingLeft 1.5s forwards cubic-bezier(0.28, 0.84, 0.42, 1); } .anim-drop-right { animation: dropBouncingRight 1.5s forwards cubic-bezier(0.28, 0.84, 0.42, 1); } @keyframes dropBouncingLeft { 0% { top: -200px; transform: rotate(0deg) scale(1.5); filter: drop-shadow(15px 30px 10px rgba(0,0,0,0.3)); } 40% { top: 30px; transform: rotate(-180deg) scale(1); filter: drop-shadow(2px 4px 3px rgba(0,0,0,0.6)); } 60% { top: -20px; transform: rotate(-240deg) scale(1.1); filter: drop-shadow(8px 15px 6px rgba(0,0,0,0.4)); } 80% { top: 20px; transform: rotate(-320deg) scale(1); filter: drop-shadow(2px 4px 3px rgba(0,0,0,0.6)); } 90% { top: 10px; transform: rotate(-340deg) scale(1); filter: drop-shadow(4px 8px 4px rgba(0,0,0,0.5)); } 100% { top: 15px; transform: rotate(-350deg) scale(1); filter: drop-shadow(3px 5px 4px rgba(0,0,0,0.6)); } } @keyframes dropBouncingRight { 0% { top: -200px; transform: scaleX(-1) rotate(0deg) scale(1.5); filter: drop-shadow(-15px 30px 10px rgba(0,0,0,0.3)); } 45% { top: 35px; transform: scaleX(-1) rotate(190deg) scale(1); filter: drop-shadow(-2px 4px 3px rgba(0,0,0,0.6)); } 65% { top: -15px; transform: scaleX(-1) rotate(260deg) scale(1.1); filter: drop-shadow(-8px 15px 6px rgba(0,0,0,0.4)); } 85% { top: 25px; transform: scaleX(-1) rotate(340deg) scale(1); filter: drop-shadow(-2px 4px 3px rgba(0,0,0,0.6)); } 95% { top: 15px; transform: scaleX(-1) rotate(355deg) scale(1); filter: drop-shadow(-4px 8px 4px rgba(0,0,0,0.5)); } 100% { top: 20px; transform: scaleX(-1) rotate(365deg) scale(1); filter: drop-shadow(-3px 5px 4px rgba(0,0,0,0.6)); } } `); // ========================================== // 2. 构建 HTML DOM // ========================================== const floatBtn = document.createElement('div'); floatBtn.id = 'xlr-float-btn'; floatBtn.innerHTML = '卦'; document.body.appendChild(floatBtn); const appWrapper = document.createElement('div'); appWrapper.id = 'xlr-app-wrapper'; appWrapper.innerHTML = `
起卦 历史 配置
×

小六壬 · 掷筊

「 万物皆有定数,亦有变数。
心存善念,所遇皆是上上签。 」

* 配置自动保存在本地,无需每次输入。

🎵 喜欢这个脚本?在抖音找到作者
掐指排盘中...
`; document.body.appendChild(appWrapper); // ========================================== // 3. 基础事件与历史记录逻辑 // ========================================== const dom = { wrapper: document.getElementById('xlr-app-wrapper'), questionInput: document.getElementById('xlr-question'), startBtn: document.getElementById('xlr-startBtn'), apiKeyInput: document.getElementById('xlr-apiKey'), modelNameInput: document.getElementById('xlr-modelName'), overlay: document.getElementById('xlr-loadingOverlay'), animHand: document.getElementById('xlr-anim-hand'), animJiaobei: document.getElementById('xlr-anim-jiaobei'), jbLeft: document.getElementById('jb-left-cup'), jbRight: document.getElementById('jb-right-cup'), loadingText: document.getElementById('xlr-loading-text') }; dom.apiKeyInput.value = GM_getValue('xlr_apikey', ''); let savedModel = GM_getValue('xlr_model', 'deepseek-ai/DeepSeek-V3'); dom.modelNameInput.value = savedModel; document.getElementById('xlr-float-btn').addEventListener('click', () => { dom.wrapper.style.display = 'flex'; }); document.getElementById('xlr-close-btn').addEventListener('click', () => dom.wrapper.style.display = 'none'); document.querySelectorAll('.xlr-tab').forEach(tab => { tab.addEventListener('click', function() { document.querySelectorAll('.xlr-tab').forEach(t => t.classList.remove('active')); this.classList.add('active'); document.querySelectorAll('.xlr-view').forEach(v => v.classList.remove('active')); document.getElementById(this.dataset.target).classList.add('active'); if(this.dataset.target === 'view-history') renderHistory(); }); }); dom.apiKeyInput.addEventListener('input', (e) => GM_setValue('xlr_apikey', e.target.value.trim())); dom.modelNameInput.addEventListener('input', (e) => { savedModel = e.target.value.trim(); GM_setValue('xlr_model', savedModel); }); document.getElementById('xlr-fetchModelsBtn').addEventListener('click', () => { const apiKey = dom.apiKeyInput.value.trim(); if (!apiKey) return alert("请先输入您的 API Key"); document.getElementById('xlr-fetchModelsBtn').innerText = "[获取中...]"; GM_xmlhttpRequest({ method: "GET", url: "https://api.siliconflow.cn/v1/models", headers: { "Authorization": `Bearer ${apiKey}` }, onload: function(res) { document.getElementById('xlr-fetchModelsBtn').innerText = "[一键获取可用模型]"; if (res.status === 200) { try { const data = JSON.parse(res.responseText); const models = data.data .filter(m => m.id.includes('chat') || m.id.includes('DeepSeek') || m.id.includes('Qwen') || m.id.includes('GLM')) .map(m => m.id); if (models.length === 0) return; let selectHTML = ``; document.getElementById('xlr-modelContainer').innerHTML = selectHTML; document.getElementById('xlr-modelSelect').addEventListener('change', (e) => { savedModel = e.target.value; GM_setValue('xlr_model', savedModel); }); alert("获取成功,已自动加载为下拉菜单!"); } catch(e) { } } else { alert("获取失败,请检查 API Key"); } }, onerror: () => { document.getElementById('xlr-fetchModelsBtn').innerText = "[一键获取可用模型]"; alert("网络请求失败"); } }); }); function renderHistory() { const history = JSON.parse(GM_getValue('xlr_history_data', '[]')); if (history.length === 0) return document.getElementById('xlr-historyArea').innerHTML = '
暂无记录。
'; let html = ''; history.forEach(item => { html += `
${item.time}
天时: ${item.gua}变数: ${item.jb}
问:${item.question}
[查看解卦]
${item.answer}
`; }); document.getElementById('xlr-historyArea').innerHTML = html; } function saveHistory(timeDetail, guaName, jbName, question, aiText) { let history = JSON.parse(GM_getValue('xlr_history_data', '[]')); history.unshift({ time: timeDetail, gua: guaName, jb: jbName, question: question, answer: aiText }); if (history.length > 30) history = history.slice(0, 30); GM_setValue('xlr_history_data', JSON.stringify(history)); } // ========================================== // 4. 核心起卦逻辑 // ========================================== function generateJiaobei() { const r = Math.random(); if (r < 0.5) { const isLeftFlat = Math.random() > 0.5; return { name: "圣杯", attr: "一阴一阳", mean: "神明允诺,大吉。", leftFlat: isLeftFlat, rightFlat: !isLeftFlat }; } if (r < 0.75) return { name: "笑杯", attr: "双阳面", mean: "神明笑而不答,不明朗。", leftFlat: true, rightFlat: true }; return { name: "阴杯", attr: "双阴面", mean: "神明不许,有隐患。", leftFlat: false, rightFlat: false }; } dom.startBtn.addEventListener('click', () => { const question = dom.questionInput.value.trim(); const apiKey = dom.apiKeyInput.value.trim(); if (!question || !apiKey) return alert("请输入问题并配置API Key"); document.getElementById('xlr-resultArea').style.display = 'none'; dom.overlay.classList.add('active'); dom.animHand.style.display = 'block'; dom.animJiaobei.style.display = 'none'; dom.loadingText.innerText = "掐指算天时中..."; const now = new Date(); const lunar = window.Lunar.fromDate(now); const zhiList = ["子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"]; const timeStr = lunar.getTimeZhi(); const calcValue = (lunar.getMonth() + lunar.getDay() + zhiList.indexOf(timeStr) + 1 - 2) % 6; const guaName = ["空亡", "大安", "留连", "速喜", "赤口", "小吉"][calcValue]; const timeDetail = `${now.toLocaleDateString()} (农历${lunar.getMonthInChinese()}月${lunar.getDayInChinese()} ${timeStr}时)`; const jb = generateJiaobei(); setTimeout(() => { dom.animHand.style.display = 'none'; dom.animJiaobei.style.display = 'block'; dom.loadingText.innerText = "掷筊请示神明中..."; dom.jbLeft.classList.remove('anim-drop-left'); dom.jbRight.classList.remove('anim-drop-right'); void dom.jbLeft.offsetWidth; dom.jbLeft.classList.add('anim-drop-left'); dom.jbRight.classList.add('anim-drop-right'); let flipInterval = setInterval(() => { dom.jbLeft.classList.toggle('is-flat'); dom.jbRight.classList.toggle('is-flat'); }, 100); setTimeout(() => { clearInterval(flipInterval); if (jb.leftFlat) dom.jbLeft.classList.add('is-flat'); else dom.jbLeft.classList.remove('is-flat'); if (jb.rightFlat) dom.jbRight.classList.add('is-flat'); else dom.jbRight.classList.remove('is-flat'); }, 1450); const prompt = `用户求算了一卦。 小六壬天时:【${guaName}】 掷筊结果:掷出了【${jb.name}】(${jb.attr}:${jb.mean}) 问题:${question} 要求: 1. 【古意解析】:分析天时与掷筊的结合。 2. 【白话直解】:单独一段,用最通俗大白话告知吉凶与建议。 3. 【温暖寄语】:无论卦象吉凶,请务必在最后单独写一段充满正能量、温暖人心的话语来鼓励用户,给他们信心和力量。`; GM_xmlhttpRequest({ method: "POST", url: "https://api.siliconflow.cn/v1/chat/completions", headers: { "Authorization": `Bearer ${apiKey}`, "Content-Type": "application/json" }, data: JSON.stringify({ model: savedModel, messages: [{ role: 'user', content: prompt }], temperature: 0.7, max_tokens: 800 }), onload: function(response) { setTimeout(() => { dom.overlay.classList.remove('active'); if (response.status === 200) { try { const data = JSON.parse(response.responseText); document.getElementById('xlr-guaTime').innerText = `起卦时间:${timeDetail}`; document.getElementById('xlr-guaTitleWrap').innerHTML = `天时:${guaName}神意:${jb.name}`; document.getElementById('xlr-aiResponse').innerText = data.choices[0].message.content; document.getElementById('xlr-resultArea').style.display = 'block'; document.getElementById('xlr-resultArea').scrollIntoView({ behavior: 'smooth' }); saveHistory(timeDetail, guaName, jb.name, question, data.choices[0].message.content); } catch(e) {} } else alert("API请求失败"); }, 2500); } }); }, 2500); }); GM_registerMenuCommand("🔮 开启起卦面板", () => { dom.wrapper.style.display = 'flex'; }); })();