// ==UserScript== // @name 彩票助手 - 福彩体彩开奖查询与智能选号 // @namespace lottery-assistant // @version 1.0.0 // @description 支持双色球、大乐透等主流彩种的开奖查询、历史分析和智能选号功能 // @author Lottery Assistant // @match *://*.cwl.gov.cn/* // @match *://*.lottery.gov.cn/* // @match *://*.caipiao*.com/* // @grant GM_xmlhttpRequest // @grant GM_setValue // @grant GM_getValue // @grant GM_addStyle // @grant GM_registerMenuCommand // @connect cwl.gov.cn // @connect lottery.gov.cn // @connect *caipiao* // @run-at document-idle // @license MIT // ==/UserScript== (function() { 'use strict'; // ==================== 配置 ==================== const CONFIG = { version: '1.0.0', default_red_ball_range: { min: 1, max: 33 }, default_blue_ball_range: { min: 1, max: 16 }, dlt_red_ball_range: { min: 1, max: 35 }, dlt_blue_ball_range: { min: 1, max: 12 }, refresh_interval: 30000, // 30秒刷新间隔 max_history: 100, // 最多保存历史记录数 }; // ==================== 彩票类型定义 ==================== const LOTTERY_TYPES = { SSQ: { id: 'ssq', name: '双色球', redCount: 6, redRange: { min: 1, max: 33 }, blueCount: 1, blueRange: { min: 1, max: 16 }, color: { red: '#E74C3C', blue: '#3498DB' } }, DLT: { id: 'dlt', name: '大乐透', redCount: 5, redRange: { min: 1, max: 35 }, blueCount: 2, blueRange: { min: 1, max: 12 }, color: { red: '#E74C3C', blue: '#3498DB' } }, FC3D: { id: 'fc3d', name: '福彩3D', redCount: 3, redRange: { min: 0, max: 9 }, color: { red: '#E74C3C', blue: '#3498DB' } }, PL3: { id: 'pl3', name: '排列三', redCount: 3, redRange: { min: 0, max: 9 }, color: { red: '#E74C3C', blue: '#3498DB' } }, PL5: { id: 'pl5', name: '排列五', redCount: 5, redRange: { min: 0, max: 9 }, color: { red: '#E74C3C', blue: '#3498DB' } }, QXC: { id: 'qxc', name: '七星彩', redCount: 7, redRange: { min: 0, max: 9 }, color: { red: '#E74C3C', blue: '#3498DB' } } }; // ==================== 样式 ==================== const STYLES = ` .lottery-assistant-btn { position: fixed; right: 20px; bottom: 20px; width: 56px; height: 56px; border-radius: 50%; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; border: none; cursor: pointer; box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4); z-index: 2147483647; font-size: 24px; display: flex; align-items: center; justify-content: center; transition: all 0.3s ease; } .lottery-assistant-btn:hover { transform: scale(1.1); box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6); } .lottery-assistant-modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.6); z-index: 2147483646; display: none; justify-content: center; align-items: center; backdrop-filter: blur(4px); } .lottery-assistant-modal.active { display: flex; } .lottery-assistant-panel { width: 95%; max-width: 900px; max-height: 90vh; background: linear-gradient(180deg, #1a1a2e 0%, #16213e 100%); border-radius: 20px; overflow: hidden; box-shadow: 0 25px 80px rgba(0, 0, 0, 0.5); display: flex; flex-direction: column; animation: slideUp 0.3s ease; } @keyframes slideUp { from { transform: translateY(50px); opacity: 0; } to { transform: translateY(0); opacity: 1; } } .lottery-header { background: linear-gradient(90deg, #667eea 0%, #764ba2 100%); padding: 20px; color: white; display: flex; justify-content: space-between; align-items: center; } .lottery-header h2 { margin: 0; font-size: 20px; display: flex; align-items: center; gap: 10px; } .lottery-close { background: rgba(255,255,255,0.2); border: none; color: white; width: 36px; height: 36px; border-radius: 50%; cursor: pointer; font-size: 20px; transition: all 0.2s; } .lottery-close:hover { background: rgba(255,255,255,0.3); transform: rotate(90deg); } .lottery-tabs { display: flex; background: rgba(0,0,0,0.2); padding: 0 20px; } .lottery-tab { padding: 15px 25px; color: rgba(255,255,255,0.7); cursor: pointer; border: none; background: none; font-size: 14px; transition: all 0.2s; border-bottom: 3px solid transparent; } .lottery-tab:hover { color: white; } .lottery-tab.active { color: white; border-bottom-color: #667eea; background: rgba(102, 126, 234, 0.2); } .lottery-content { padding: 25px; overflow-y: auto; flex: 1; } .lottery-section { display: none; } .lottery-section.active { display: block; } .lottery-select-group { display: flex; gap: 15px; margin-bottom: 20px; flex-wrap: wrap; } .lottery-select { background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.2); border-radius: 10px; padding: 12px 20px; color: white; font-size: 14px; cursor: pointer; transition: all 0.2s; } .lottery-select:hover { border-color: #667eea; } .lottery-select option { background: #1a1a2e; } .lottery-btn { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); border: none; color: white; padding: 12px 25px; border-radius: 10px; cursor: pointer; font-size: 14px; transition: all 0.2s; } .lottery-btn:hover { transform: translateY(-2px); box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4); } .lottery-btn.secondary { background: rgba(255,255,255,0.1); } .lottery-btn.success { background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%); } .lottery-btn.danger { background: linear-gradient(135deg, #eb3349 0%, #f45c43 100%); } .lottery-result { background: rgba(255,255,255,0.05); border-radius: 15px; padding: 20px; margin-top: 20px; } .lottery-result-title { color: #667eea; font-size: 14px; margin-bottom: 15px; display: flex; justify-content: space-between; align-items: center; } .lottery-balls { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; } .lottery-ball { width: 45px; height: 45px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: bold; font-size: 18px; color: white; box-shadow: 0 4px 10px rgba(0,0,0,0.3); } .lottery-ball.red { background: linear-gradient(135deg, #E74C3C 0%, #c0392b 100%); } .lottery-ball.blue { background: linear-gradient(135deg, #3498DB 0%, #2980b9 100%); } .lottery-ball.orange { background: linear-gradient(135deg, #f39c12 0%, #e67e22 100%); } .lottery-number { background: rgba(255,255,255,0.1); padding: 10px 15px; border-radius: 8px; display: inline-block; } .lottery-history { margin-top: 20px; } .lottery-history-item { display: flex; justify-content: space-between; align-items: center; padding: 12px; border-bottom: 1px solid rgba(255,255,255,0.1); } .lottery-history-item:hover { background: rgba(255,255,255,0.05); } .lottery-history-date { color: rgba(255,255,255,0.6); font-size: 13px; } .lottery-stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 15px; margin-top: 20px; } .lottery-stat-card { background: rgba(255,255,255,0.05); border-radius: 12px; padding: 15px; text-align: center; } .lottery-stat-value { font-size: 28px; font-weight: bold; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); -webkit-background-clip: text; -webkit-text-fill-color: transparent; } .lottery-stat-label { color: rgba(255,255,255,0.6); font-size: 12px; margin-top: 5px; } .lottery-frequency { display: grid; grid-template-columns: repeat(10, 1fr); gap: 8px; margin-top: 15px; } .lottery-frequency-item { background: rgba(255,255,255,0.05); border-radius: 8px; padding: 10px 5px; text-align: center; } .lottery-frequency-num { font-size: 16px; font-weight: bold; color: white; } .lottery-frequency-count { font-size: 11px; color: rgba(255,255,255,0.6); margin-top: 3px; } .lottery-generator { display: flex; flex-direction: column; gap: 20px; } .lottery-generator-row { display: flex; gap: 15px; align-items: center; flex-wrap: wrap; } .lottery-generator-label { color: rgba(255,255,255,0.8); min-width: 80px; } .lottery-generator-input { width: 80px; background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.2); border-radius: 8px; padding: 10px; color: white; text-align: center; font-size: 16px; } .lottery-generator-input:focus { outline: none; border-color: #667eea; } .lottery-generator-balls { display: flex; gap: 5px; flex-wrap: wrap; padding: 15px; background: rgba(0,0,0,0.2); border-radius: 10px; min-height: 60px; } .lottery-generator-ball { width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: bold; cursor: pointer; transition: all 0.2s; color: white; font-size: 14px; } .lottery-generator-ball:hover { transform: scale(1.15); } .lottery-generator-ball.selected { box-shadow: 0 0 0 3px #fff, 0 0 15px rgba(102, 126, 234, 0.6); } .lottery-generator-ball.red { background: linear-gradient(135deg, #E74C3C 0%, #c0392b 100%); } .lottery-generator-ball.blue { background: linear-gradient(135deg, #3498DB 0%, #2980b9 100%); } .lottery-generator-ball.orange { background: linear-gradient(135deg, #f39c12 0%, #e67e22 100%); } .lottery-generated-numbers { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; } .lottery-generated-item { display: flex; justify-content: space-between; align-items: center; padding: 15px; background: rgba(255,255,255,0.05); border-radius: 10px; } .lottery-generated-balls { display: flex; gap: 8px; } .lottery-generated-ball { width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: bold; font-size: 15px; color: white; } .lottery-generated-ball.red { background: linear-gradient(135deg, #E74C3C 0%, #c0392b 100%); } .lottery-generated-ball.blue { background: linear-gradient(135deg, #3498DB 0%, #2980b9 100%); } .lottery-tips { background: rgba(255,255,255,0.05); border-left: 3px solid #667eea; padding: 15px; border-radius: 0 10px 10px 0; margin-top: 20px; } .lottery-tips-title { color: #667eea; font-size: 13px; margin-bottom: 8px; } .lottery-tips-content { color: rgba(255,255,255,0.7); font-size: 13px; line-height: 1.6; } .lottery-loading { text-align: center; padding: 40px; color: rgba(255,255,255,0.6); } .lottery-spinner { width: 40px; height: 40px; border: 3px solid rgba(255,255,255,0.1); border-top-color: #667eea; border-radius: 50%; animation: spin 1s linear infinite; margin: 0 auto 15px; } @keyframes spin { to { transform: rotate(360deg); } } .lottery-no-data { text-align: center; padding: 40px; color: rgba(255,255,255,0.5); } .lottery-modal-actions { display: flex; gap: 10px; margin-top: 10px; } .lottery-copy-btn { background: rgba(255,255,255,0.1); border: none; color: rgba(255,255,255,0.7); padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 12px; transition: all 0.2s; } .lottery-copy-btn:hover { background: rgba(255,255,255,0.2); color: white; } /* 遗漏分析样式 */ .lottery-miss-grid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 6px; margin-top: 15px; } .lottery-miss-item { background: rgba(255,255,255,0.05); border-radius: 6px; padding: 8px 4px; text-align: center; } .lottery-miss-num { font-size: 14px; font-weight: bold; color: white; } .lottery-miss-value { font-size: 10px; color: rgba(255,255,255,0.6); margin-top: 2px; } .lottery-miss-item.hot { background: rgba(231, 76, 60, 0.3); } .lottery-miss-item.cold { background: rgba(52, 152, 219, 0.3); } `; // ==================== 工具函数 ==================== const Utils = { // 生成随机数 random: (min, max) => Math.floor(Math.random() * (max - min + 1)) + min, // 生成不重复的随机数数组 randomArray: (count, min, max) => { const arr = []; while (arr.length < count) { const num = Utils.random(min, max); if (!arr.includes(num)) arr.push(num); } return arr.sort((a, b) => a - b); }, // 格式化日期 formatDate: (date) => { const d = new Date(date); return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`; }, // 深拷贝 deepClone: (obj) => JSON.parse(JSON.stringify(obj)), // 本地存储 storage: { get: (key, defaultValue = null) => { try { const value = GM_getValue(key); return value !== undefined ? value : defaultValue; } catch { return defaultValue; } }, set: (key, value) => { try { GM_setValue(key, value); } catch (e) { console.error('Storage error:', e); } } }, // HTTP请求 request: (url, options = {}) => { return new Promise((resolve, reject) => { GM_xmlhttpRequest({ method: options.method || 'GET', url: url, headers: options.headers || {}, data: options.body, timeout: 10000, onload: (response) => { try { resolve({ status: response.status, data: JSON.parse(response.responseText), text: response.responseText }); } catch { resolve({ status: response.status, data: null, text: response.responseText }); } }, onerror: (error) => reject(error), ontimeout: () => reject(new Error('Request timeout')) }); }); } }; // ==================== 号码生成器 ==================== class NumberGenerator { constructor(type) { this.type = type; } // 机选 random(count = 1) { const results = []; const type = this.type; for (let i = 0; i < count; i++) { const redBalls = Utils.randomArray(type.redCount, type.redRange.min, type.redRange.max); const result = { red: redBalls }; if (type.blueCount) { result.blue = Utils.randomArray(type.blueCount, type.blueRange.min, type.blueRange.max); } results.push(result); } return results; } // 胆拖选号 generateWithDantuo(redDan, redTuo, blueDan = [], blueTuo = []) { const type = this.type; const result = { red: [...redDan] }; // 剩余红球从拖区选取 const needRed = type.redCount - redDan.length; const availableRed = redTuo.filter(n => !redDan.includes(n)); result.red.push(...Utils.randomArray(needRed, Math.min(...availableRed), Math.max(...availableRed))); if (type.blueCount) { result.blue = [...blueDan]; const needBlue = type.blueCount - blueDan.length; const availableBlue = blueTuo.filter(n => !blueDan.includes(n)); if (availableBlue.length >= needBlue) { result.blue.push(...Utils.randomArray(needBlue, Math.min(...availableBlue), Math.max(...availableBlue))); } } result.red.sort((a, b) => a - b); if (result.blue) result.blue.sort((a, b) => a - b); return result; } } // ==================== 数据分析器 ==================== class DataAnalyzer { constructor(history) { this.history = history; } // 计算出现频率 getFrequency() { const freq = {}; this.history.forEach(item => { item.red.forEach(n => { freq[n] = (freq[n] || 0) + 1; }); if (item.blue) { item.blue.forEach(n => { freq[n] = (freq[n] || 0) + 1; }); } }); return freq; } // 计算遗漏值 getMissCount() { const miss = {}; const latest = this.history[0]; if (!latest) return miss; this.history.forEach(item => { const allNumbers = [...item.red, ...(item.blue || [])]; allNumbers.forEach(n => { if (!miss[n]) miss[n] = 0; miss[n]++; }); }); // 计算当前遗漏 const allNumbers = [...latest.red, ...(latest.blue || [])]; for (let i = 1; i <= 35; i++) { if (!allNumbers.includes(i)) { miss[i] = (miss[i] || 0) + 1; } } return miss; } // 获取冷热号 getHotCold(threshold = 0.3) { const freq = this.getFrequency(); const avg = Object.values(freq).reduce((a, b) => a + b, 0) / Object.keys(freq).length || 0; const hot = []; const cold = []; Object.entries(freq).forEach(([num, count]) => { if (count > avg * (1 + threshold)) { hot.push(parseInt(num)); } else if (count < avg * (1 - threshold)) { cold.push(parseInt(num)); } }); return { hot, cold, average: avg }; } // 和值分析 getSumAnalysis() { return this.history.map(item => { const sum = [...item.red, ...(item.blue || [])].reduce((a, b) => a + b, 0); return sum; }); } // 奇偶比例 getOddEvenRatio() { return this.history.map(item => { const all = [...item.red, ...(item.blue || [])]; const odd = all.filter(n => n % 2 === 1).length; return { odd, even: all.length - odd }; }); } } // ==================== 彩票助手主类 ==================== class LotteryAssistant { constructor() { this.currentType = LOTTERY_TYPES.SSQ; this.history = []; this.analysisData = null; this.selectedNumbers = { red: [], blue: [] }; this.generatedNumbers = []; } // 初始化 init() { this.injectStyles(); this.createUI(); this.bindEvents(); this.loadLocalData(); this.fetchLatestResults(); } // 注入样式 injectStyles() { GM_addStyle(STYLES); } // 创建UI createUI() { // 创建悬浮按钮 const btn = document.createElement('button'); btn.className = 'lottery-assistant-btn'; btn.innerHTML = '🎯'; btn.title = '彩票助手'; btn.id = 'lottery-assistant-trigger'; document.body.appendChild(btn); // 创建主面板 const modal = document.createElement('div'); modal.className = 'lottery-assistant-modal'; modal.id = 'lottery-assistant-modal'; modal.innerHTML = `

🎰 彩票助手

${this.createResultSection()} ${this.createHistorySection()} ${this.createAnalysisSection()} ${this.createGeneratorSection()}
`; document.body.appendChild(modal); } // 开奖结果区域 createResultSection() { return `
正在加载开奖信息...
`; } // 历史数据区域 createHistorySection() { return `
历史记录 共 0 条
暂无历史数据
`; } // 数据分析区域 createAnalysisSection() { return `
请先加载历史数据
`; } // 智能选号区域 createGeneratorSection() { const type = this.currentType; const redBalls = []; for (let i = type.redRange.min; i <= type.redRange.max; i++) { redBalls.push(i); } const blueBalls = type.blueCount ? Array.from({length: type.blueRange.max}, (_, i) => i + type.blueRange.min) : []; return `

🔴 红球区(选择胆码)

${redBalls.map(n => `
${n}
`).join('')}
${type.blueCount ? `

🔵 蓝球区(选择胆码)

${blueBalls.map(n => `
${n}
`).join('')}
` : ''}
生成组数:
生成结果
点击"机选生成"开始选号
💡 选号技巧
• 点击上方球号可选为胆码,胆码会出现在所有生成的号码中
• 建议选择1-2个胆码,可提高中奖概率
• 机选是完全随机的,中奖概率相同,请理性购彩
`; } // 绑定事件 bindEvents() { // 打开/关闭面板 document.getElementById('lottery-assistant-trigger').addEventListener('click', () => { document.getElementById('lottery-assistant-modal').classList.add('active'); }); document.getElementById('lottery-close').addEventListener('click', () => { document.getElementById('lottery-assistant-modal').classList.remove('active'); }); document.getElementById('lottery-assistant-modal').addEventListener('click', (e) => { if (e.target.id === 'lottery-assistant-modal') { e.target.classList.remove('active'); } }); // 标签切换 document.querySelectorAll('.lottery-tab').forEach(tab => { tab.addEventListener('click', () => { document.querySelectorAll('.lottery-tab').forEach(t => t.classList.remove('active')); document.querySelectorAll('.lottery-section').forEach(s => s.classList.remove('active')); tab.classList.add('active'); document.getElementById(`section-${tab.dataset.tab}`).classList.add('active'); }); }); // 彩种选择 document.getElementById('lottery-type-select').addEventListener('change', (e) => { this.currentType = LOTTERY_TYPES[e.target.value]; this.fetchLatestResults(); }); document.getElementById('history-type-select').addEventListener('change', (e) => { this.currentType = LOTTERY_TYPES[e.target.value]; }); document.getElementById('analysis-type-select').addEventListener('change', (e) => { this.currentType = LOTTERY_TYPES[e.target.value]; }); // 刷新开奖 document.getElementById('refresh-result').addEventListener('click', () => { this.fetchLatestResults(); }); // 加载历史 document.getElementById('load-history').addEventListener('click', () => { this.fetchHistory(); }); // 清空历史 document.getElementById('clear-history').addEventListener('click', () => { if (confirm('确定要清空所有历史记录吗?')) { Utils.storage.set('lottery_history', {}); this.renderHistory(); } }); // 开始分析 document.getElementById('run-analysis').addEventListener('click', () => { this.runAnalysis(); }); // 机选生成 document.getElementById('generate-btn').addEventListener('click', () => { this.generateNumbers(); }); // 清空重选 document.getElementById('generate-clear').addEventListener('click', () => { this.clearSelections(); }); // 复制全部 document.getElementById('copy-all')?.addEventListener('click', () => { this.copyAllNumbers(); }); // 选号球点击 document.addEventListener('click', (e) => { if (e.target.classList.contains('lottery-generator-ball')) { e.target.classList.toggle('selected'); const num = parseInt(e.target.dataset.number); const isRed = e.target.classList.contains('red'); if (isRed) { const idx = this.selectedNumbers.red.indexOf(num); if (idx > -1) { this.selectedNumbers.red.splice(idx, 1); } else { this.selectedNumbers.red.push(num); } } else { const idx = this.selectedNumbers.blue.indexOf(num); if (idx > -1) { this.selectedNumbers.blue.splice(idx, 1); } else { this.selectedNumbers.blue.push(num); } } } }); } // 加载本地数据 loadLocalData() { const history = Utils.storage.get('lottery_history', {}); this.history = history[this.currentType.id] || []; this.renderHistory(); } // 获取最新开奖 async fetchLatestResults() { const content = document.getElementById('result-content'); content.innerHTML = `
正在获取开奖信息...
`; try { const results = await this.fetchLotteryData(this.currentType.id); this.renderResult(results); } catch (error) { content.innerHTML = `

获取开奖信息失败

${error.message}

`; } } // 获取彩票数据 async fetchLotteryData(type) { // 尝试多个数据源 const sources = [ // 模拟数据(实际使用时可替换为真实API) () => this.getMockData(type) ]; for (const source of sources) { try { const data = source(); if (data) return data; } catch { continue; } } throw new Error('暂无可用数据源'); } // 获取模拟数据 getMockData(type) { const now = new Date(); const dateStr = Utils.formatDate(now); const mockData = { ssq: { period: `${now.getFullYear()}${String(now.getMonth() + 1).padStart(2, '0')}01`, date: dateStr, red: Utils.randomArray(6, 1, 33), blue: [Utils.random(1, 16)] }, dlt: { period: `${now.getFullYear()}${String(now.getMonth() + 1).padStart(2, '0')}01`, date: dateStr, red: Utils.randomArray(5, 1, 35), blue: Utils.randomArray(2, 1, 12) }, fc3d: { period: `${Utils.formatDate(now).replace(/-/g, '')}`, date: dateStr, red: Utils.randomArray(3, 0, 9) }, pl3: { period: `${Utils.formatDate(now).replace(/-/g, '')}`, date: dateStr, red: Utils.randomArray(3, 0, 9) }, pl5: { period: `${Utils.formatDate(now).replace(/-/g, '')}`, date: dateStr, red: Utils.randomArray(5, 0, 9) }, qxc: { period: `${Utils.formatDate(now).replace(/-/g, '')}`, date: dateStr, red: Utils.randomArray(7, 0, 9) } }; return mockData[type]; } // 渲染开奖结果 renderResult(result) { const content = document.getElementById('result-content'); const type = this.currentType; let ballsHtml = result.red.map(n => `
${String(n).padStart(2, '0')}
` ).join(''); if (result.blue) { ballsHtml += '+'; ballsHtml += result.blue.map(n => `
${String(n).padStart(2, '0')}
` ).join(''); } content.innerHTML = `
第 ${result.period} 期 ${result.date}
${ballsHtml}
📌 温馨提示
以上数据为演示数据,实际开奖请以官方公告为准。
`; } // 获取历史数据 async fetchHistory() { const list = document.getElementById('history-list'); list.innerHTML = `
正在加载历史数据...
`; // 生成一些模拟历史数据 const history = []; const now = new Date(); for (let i = 0; i < 20; i++) { const date = new Date(now); date.setDate(date.getDate() - i); const type = this.currentType; const record = { period: `${date.getFullYear()}${String(date.getMonth() + 1).padStart(2, '0')}${String(date.getDate()).padStart(2, '0')}`, date: Utils.formatDate(date), red: Utils.randomArray(type.redCount, type.redRange.min, type.redRange.max) }; if (type.blueCount) { record.blue = Utils.randomArray(type.blueCount, type.blueRange.min, type.blueRange.max); } history.push(record); } // 保存到本地 const allHistory = Utils.storage.get('lottery_history', {}); allHistory[this.currentType.id] = history; Utils.storage.set('lottery_history', allHistory); this.history = history; this.renderHistory(); } // 渲染历史记录 renderHistory() { const list = document.getElementById('history-list'); const count = document.getElementById('history-count'); if (this.history.length === 0) { list.innerHTML = '
暂无历史数据,请点击"加载历史"
'; count.textContent = '共 0 条'; return; } count.textContent = `共 ${this.history.length} 条`; list.innerHTML = this.history.map(item => { const redBalls = item.red.map(n => `${String(n).padStart(2, '0')}` ).join(''); const blueBalls = item.blue ? item.blue.map(n => `${String(n).padStart(2, '0')}` ).join('') : ''; return `
第 ${item.period} 期
${redBalls}${blueBalls ? ' + ' + blueBalls : ''}
${item.date}
`; }).join(''); } // 运行分析 runAnalysis() { const content = document.getElementById('analysis-content'); if (this.history.length < 5) { content.innerHTML = '
历史数据不足,请先加载至少5期数据
'; return; } const analyzer = new DataAnalyzer(this.history); // 频率分析 const freq = analyzer.getFrequency(); const type = this.currentType; // 红球频率 let redFreqHtml = ''; for (let i = type.redRange.min; i <= type.redRange.max; i++) { const count = freq[i] || 0; const pct = ((count / this.history.length) * 100).toFixed(0); redFreqHtml += `
${i}
${count}次
${pct}%
`; } // 蓝球频率(如果有) let blueFreqHtml = ''; if (type.blueRange) { blueFreqHtml = '

🔵 蓝球出现频率

'; for (let i = type.blueRange.min; i <= type.blueRange.max; i++) { const count = freq[i] || 0; const pct = this.history.length > 0 ? ((count / this.history.length) * 100).toFixed(0) : 0; blueFreqHtml += `
${i}
${count}次
${pct}%
`; } blueFreqHtml += '
'; } // 统计卡片 const hotCold = analyzer.getHotCold(); const sumAvg = analyzer.getSumAnalysis().reduce((a, b) => a + b, 0) / this.history.length; content.innerHTML = `
${this.history.length}
分析期数
${sumAvg.toFixed(1)}
平均和值
${hotCold.hot.length}
热号数量
${hotCold.cold.length}
冷号数量
🔴 红球出现频率
${redFreqHtml}
${blueFreqHtml}
📊 分析说明
热号:出现频率高于平均值的号码
冷号:出现频率低于平均值的号码
• 遗漏值:表示该号码距上次出现的期数
• 理性购彩,概率游戏请勿沉迷
`; } // 生成号码 generateNumbers() { const count = parseInt(document.getElementById('generate-count').value) || 5; const generator = new NumberGenerator(this.currentType); this.generatedNumbers = generator.random(Math.min(count, 20)); // 应用胆码 if (this.selectedNumbers.red.length > 0 || this.selectedNumbers.blue.length > 0) { this.generatedNumbers = this.generatedNumbers.map(n => { const result = { ...n }; result.red = [...this.selectedNumbers.red, ...result.red.slice(0, this.currentType.redCount - this.selectedNumbers.red.length)]; result.red.sort((a, b) => a - b); if (result.blue && this.selectedNumbers.blue.length > 0) { result.blue = [...this.selectedNumbers.blue, ...result.blue.slice(0, this.currentType.blueCount - this.selectedNumbers.blue.length)]; result.blue.sort((a, b) => a - b); } return result; }); } this.renderGeneratedNumbers(); } // 渲染生成的号码 renderGeneratedNumbers() { const list = document.getElementById('generated-list'); if (this.generatedNumbers.length === 0) { list.innerHTML = '
点击"机选生成"开始选号
'; return; } list.innerHTML = this.generatedNumbers.map((item, idx) => { const type = this.currentType; const redBalls = item.red.map(n => `
${String(n).padStart(2, '0')}
` ).join(''); const blueBalls = item.blue ? item.blue.map(n => `
${String(n).padStart(2, '0')}
` ).join('') : ''; const numbersStr = `${item.red.map(n => String(n).padStart(2, '0')).join(', ')}${item.blue ? ' + ' + item.blue.map(n => String(n).padStart(2, '0')).join(', ') : ''}`; return `
${redBalls}${blueBalls ? '+' + blueBalls : ''}
`; }).join(''); } // 复制单组号码 copyNumber(str) { navigator.clipboard.writeText(str).then(() => { this.showToast('号码已复制'); }); } // 复制全部号码 copyAllNumbers() { if (this.generatedNumbers.length === 0) return; const text = this.generatedNumbers.map(item => { const red = item.red.map(n => String(n).padStart(2, '0')).join(', '); const blue = item.blue ? ` + ${item.blue.map(n => String(n).padStart(2, '0')).join(', ')}` : ''; return red + blue; }).join('\n'); navigator.clipboard.writeText(text).then(() => { this.showToast('全部号码已复制'); }); } // 清空选择 clearSelections() { this.selectedNumbers = { red: [], blue: [] }; document.querySelectorAll('.lottery-generator-ball.selected').forEach(ball => { ball.classList.remove('selected'); }); this.generatedNumbers = []; this.renderGeneratedNumbers(); } // 显示提示 showToast(message) { const toast = document.createElement('div'); toast.style.cssText = ` position: fixed; top: 20px; left: 50%; transform: translateX(-50%); background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 12px 25px; border-radius: 25px; font-size: 14px; z-index: 2147483647; animation: fadeIn 0.3s ease; `; toast.textContent = message; document.body.appendChild(toast); setTimeout(() => { toast.style.animation = 'fadeOut 0.3s ease'; setTimeout(() => toast.remove(), 300); }, 2000); } } // ==================== 启动 ==================== let lotteryAssistant; function init() { lotteryAssistant = new LotteryAssistant(); lotteryAssistant.init(); // 注册菜单 GM_registerMenuCommand('🎯 打开彩票助手', () => { document.getElementById('lottery-assistant-modal').classList.add('active'); }); GM_registerMenuCommand('🔄 刷新开奖结果', () => { lotteryAssistant.fetchLatestResults(); }); // 添加动画样式 GM_addStyle(` @keyframes fadeIn { from { opacity: 0; transform: translateX(-50%) translateY(-20px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } } @keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } } `); } // 确保DOM加载完成 if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init); } else { init(); } // 暴露到全局 window.lotteryAssistant = lotteryAssistant; })();