// ==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 = `
获取开奖信息失败
${error.message}