// ==UserScript== // @name 明日方舟界园 - 掷出通宝成功概率计算器 // @namespace http://tampermonkey.net/ // @version 0.2 // @iconURL https://torappu.prts.wiki/assets/roguelike_topic_itempic/rogue_5_copper_B_01.png // @description 计算从花、衡、厉三种通宝中掷出n个时,某种特定通宝至少有m个的概率 // @author 幺幺幺幺吆 // @license MIT // @match *://*/* // @grant none // @downloadURL none // ==/UserScript== (function() { 'use strict'; // 创建浮动按钮 const floatBtn = document.createElement('button'); floatBtn.title = '投钱'; // 保留文字提示作为鼠标悬停tooltip // 使用网络图片作为按钮背景 floatBtn.style.cssText = ` position: fixed; bottom: 20px; right: 20px; z-index: 9999; width: 80px; height: 80px; padding: 0; background: url('https://torappu.prts.wiki/assets/roguelike_topic_itempic/rogue_5_copper_B_01.png') no-repeat center/100%; background-color: none; border: none; border-radius: 50%; cursor: pointer; filter: drop-shadow(0 2px 3px rgba(0,0,0,0.3)); `; // 图片加载失败的回退方案 floatBtn.innerHTML = `
`; // 图片加载失败时显示文字 floatBtn.onerror = function() { this.style.background = '#60928B'; this.innerHTML = '投钱'; this.style.fontWeight = 'bold'; this.style.color = 'white'; this.style.padding = '10px'; this.style.borderRadius = '50px'; }; // 创建计算器界面 const calculator = document.createElement('div'); calculator.style.cssText = ` transition: all 0.3s ease; opacity: 0; transform: translateY(20px); display: none; position: fixed; bottom: 70px; right: 20px; z-index: 9998; width: 300px; padding: 15px; background-color: white; border: 1px solid #ddd; border-radius: 5px; box-shadow: 0 0 10px rgba(0,0,0,0.1); `; calculator.innerHTML = `错误:通宝总数量不能超过20
"; return; } if (n > total) { document.getElementById('tm-result').innerHTML = "错误:掷出通宝数量不能超过通宝总数量
"; return; } let K; let targetName; switch(target) { case 'a': K = a; targetName = "花"; break; case 'b': K = b; targetName = "衡"; break; case 'c': K = c; targetName = "厉"; break; default: K = 0; targetName = ""; } let prob = 0; for (let k = m; k <= Math.min(K, n); k++) { prob += hypergeometric(total, K, n, k); } const percentage = (prob * 100).toFixed(2); document.getElementById('tm-result').innerHTML = `结果: 从现有的 ${total} 个通宝中掷出 ${n} 个通宝,其中至少有 ${m} 个 ${targetName} 通宝的概率为 ${percentage}%
`; }); })();