|
|
发表于 2026-2-12 14:33:56
|
显示全部楼层
让deepseek搞了一个,感觉应该能满足需求?

🎲 3d100 : 74 + 100 + 59 = 233 (74, 100, 59)
附上提示词
帮我写一个油猴脚本插件。它的基本功能是投骰子,可以自定义投掷的骰子面数和骰子数量,每个骰子的结果单独显示,同时显示所有骰子结果的总和。还要可以快捷复制骰子结果 和
- // ==UserScript==
- // @name 万能骰子投手 · 可拖拽面板
- // @namespace https://greasyfork.org/users/your-namespace
- // @version 1.5
- // @description 任意骰子面数/数量,单独显示每个点数与总和,支持一键复制。面板可拖拽,位置自由定义。
- // @author YourName
- // @match *://*/*
- // @exclude *://*.taobao.com/*
- // @exclude *://*.tmall.com/*
- // @grant GM_setClipboard
- // @grant GM_addStyle
- // @run-at document-end
- // @license MIT
- // ==/UserScript==
- (function() {
- 'use strict';
- // ---------- 1. 样式注入(含拖拽光标与全局拖拽态)----------
- GM_addStyle(`
- #dice-roller-panel {
- all: initial;
- position: fixed;
- bottom: 20px;
- right: 20px;
- width: 280px;
- background: #2d2d2d;
- color: #f0f0f0;
- border-radius: 12px;
- box-shadow: 0 8px 20px rgba(0,0,0,0.5);
- font-family: 'Segoe UI', Roboto, system-ui, sans-serif;
- z-index: 2147483647;
- border: 1px solid #555;
- backdrop-filter: blur(5px);
- padding: 16px 18px;
- transition: none; /* 拖拽时禁止动画,避免卡顿 */
- user-select: none;
- }
- #dice-roller-panel * {
- box-sizing: border-box;
- margin: 0;
- padding: 0;
- line-height: 1.4;
- }
- #dice-roller-header {
- font-size: 18px;
- font-weight: 600;
- margin-bottom: 16px;
- color: #ffd966;
- display: flex;
- align-items: center;
- gap: 8px;
- border-bottom: 1px solid #555;
- padding-bottom: 8px;
- cursor: move; /* 拖拽提示 */
- }
- /* 全局拖拽态:禁止选中,手型变抓取 */
- body.dice-dragging {
- user-select: none !important;
- cursor: grabbing !important;
- }
- .dice-input-row {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 12px;
- gap: 10px;
- }
- .dice-input-row label {
- display: flex;
- align-items: center;
- gap: 6px;
- font-size: 14px;
- color: #ccc;
- background: #3a3a3a;
- padding: 5px 10px;
- border-radius: 20px;
- flex: 1;
- }
- .dice-input-row input {
- width: 70px;
- padding: 6px 8px;
- border-radius: 20px;
- border: 1px solid #666;
- background: #1e1e1e;
- color: #fff;
- font-weight: 500;
- text-align: center;
- outline: none;
- transition: 0.15s;
- }
- .dice-input-row input:focus {
- border-color: #ffb86b;
- background: #2a2a2a;
- }
- #roll-button {
- width: 100%;
- background: #e67e22;
- border: none;
- color: white;
- font-weight: bold;
- padding: 10px 0;
- border-radius: 40px;
- font-size: 18px;
- display: flex;
- align-items: center;
- justify-content: center;
- gap: 8px;
- cursor: pointer;
- border-bottom: 3px solid #b85e0a;
- transition: all 0.08s;
- margin: 12px 0 16px 0;
- letter-spacing: 2px;
- }
- #roll-button:hover {
- background: #f39c12;
- border-bottom-width: 2px;
- transform: translateY(1px);
- }
- #roll-button:active {
- transform: translateY(4px);
- border-bottom-width: 1px;
- }
- .results-area {
- background: #252525;
- border-radius: 16px;
- padding: 14px;
- margin-bottom: 14px;
- border: 1px solid #484848;
- }
- .dice-list {
- display: flex;
- flex-wrap: wrap;
- gap: 8px;
- margin-bottom: 10px;
- max-height: 160px;
- overflow-y: auto;
- padding: 4px 2px;
- }
- .die-item {
- background: #4a4a4a;
- padding: 6px 12px;
- border-radius: 24px;
- font-size: 16px;
- font-weight: 600;
- color: #ffe083;
- box-shadow: inset 0 -2px 0 #2a2a2a;
- border: 1px solid #6a6a6a;
- min-width: 46px;
- text-align: center;
- }
- .sum-line {
- display: flex;
- justify-content: space-between;
- align-items: baseline;
- font-size: 17px;
- background: #333;
- padding: 8px 14px;
- border-radius: 30px;
- color: #ddd;
- margin-top: 6px;
- }
- .sum-number {
- font-size: 26px;
- font-weight: 800;
- color: #ffd966;
- margin-left: 8px;
- }
- .copy-section {
- display: flex;
- align-items: center;
- gap: 10px;
- margin-top: 8px;
- }
- #copy-result-btn {
- background: #3a6ea5;
- border: none;
- color: white;
- padding: 10px 18px;
- border-radius: 40px;
- font-size: 15px;
- font-weight: 600;
- display: flex;
- align-items: center;
- gap: 8px;
- cursor: pointer;
- border-bottom: 3px solid #1f3f66;
- transition: 0.1s;
- flex: 2;
- justify-content: center;
- }
- #copy-result-btn:hover {
- background: #4d8cd4;
- border-bottom-width: 2px;
- transform: translateY(1px);
- }
- #copy-result-btn:active {
- transform: translateY(3px);
- border-bottom-width: 1px;
- }
- #copy-status {
- font-size: 13px;
- color: #a5d6a5;
- flex: 1;
- white-space: nowrap;
- }
- /* 滚动条美化 */
- .dice-list::-webkit-scrollbar {
- width: 6px;
- }
- .dice-list::-webkit-scrollbar-track {
- background: #2a2a2a;
- border-radius: 10px;
- }
- .dice-list::-webkit-scrollbar-thumb {
- background: #777;
- border-radius: 10px;
- }
- `);
- // ---------- 2. 防止重复注入 ----------
- if (document.getElementById('dice-roller-panel')) return;
- // ---------- 3. 创建面板DOM ----------
- const panel = document.createElement('div');
- panel.id = 'dice-roller-panel';
- panel.innerHTML = `
- <div id="dice-roller-header">
- <span>🎲</span> 极简骰子
- </div>
- <div class="dice-input-row">
- <label>📦 数量 <input type="number" id="dice-count" min="1" max="99" value="1" step="1"></label>
- <label>🎯 面数 <input type="number" id="dice-sides" min="2" max="999" value="6" step="1"></label>
- </div>
- <button id="roll-button">⚡ 投掷</button>
- <div class="results-area">
- <div id="dice-results-container">
- <div id="individual-results" class="dice-list">
- <!-- 动态填充骰子结果 -->
- </div>
- <div id="sum-result" class="sum-line">
- <span>🔢 总和</span>
- <span class="sum-number" id="sum-value">0</span>
- </div>
- </div>
- </div>
- <div class="copy-section">
- <button id="copy-result-btn">📋 复制结果</button>
- <span id="copy-status"></span>
- </div>
- `;
- document.body.appendChild(panel);
- // ---------- 4. 获取常用元素引用 ----------
- const countInput = document.getElementById('dice-count');
- const sidesInput = document.getElementById('dice-sides');
- const rollBtn = document.getElementById('roll-button');
- const individualDiv = document.getElementById('individual-results');
- const sumSpan = document.getElementById('sum-value');
- const copyBtn = document.getElementById('copy-result-btn');
- const copyStatus = document.getElementById('copy-status');
- // 存储当前骰子结果数据
- let currentRoll = {
- count: 1,
- sides: 6,
- results: [],
- sum: 0
- };
- // ---------- 5. 核心:投骰子函数 ----------
- function rollDice() {
- let count = parseInt(countInput.value, 10);
- let sides = parseInt(sidesInput.value, 10);
- if (isNaN(count) || count < 1) {
- count = 1;
- countInput.value = 1;
- }
- if (isNaN(sides) || sides < 2) {
- sides = 6;
- sidesInput.value = 6;
- }
- if (count > 99) {
- count = 99;
- countInput.value = 99;
- }
- if (sides > 999) {
- sides = 999;
- sidesInput.value = 999;
- }
- const results = [];
- for (let i = 0; i < count; i++) {
- results.push(Math.floor(Math.random() * sides) + 1);
- }
- const sum = results.reduce((acc, val) => acc + val, 0);
- currentRoll = { count, sides, results, sum };
- // 渲染骰子
- individualDiv.innerHTML = '';
- results.forEach(val => {
- const dieSpan = document.createElement('span');
- dieSpan.className = 'die-item';
- dieSpan.textContent = val;
- individualDiv.appendChild(dieSpan);
- });
- sumSpan.textContent = sum;
- copyStatus.textContent = '';
- }
- // ---------- 6. 复制结果 ----------
- function copyRollResult() {
- const { count, sides, results, sum } = currentRoll;
- if (!results || results.length === 0) {
- copyStatus.textContent = '⚠️ 没有可复制的结果';
- return;
- }
- const diceExpr = `${count}d${sides}`;
- const resultsStr = results.join(' + ');
- const copyText = `🎲 ${diceExpr} : ${resultsStr} = ${sum} (${results.join(', ')})`;
- GM_setClipboard(copyText, 'text/plain');
- copyStatus.textContent = '✅ 已复制!';
- setTimeout(() => {
- copyStatus.textContent = '';
- }, 2000);
- }
- // ---------- 7. 绑定基础事件 ----------
- rollBtn.addEventListener('click', (e) => {
- e.preventDefault();
- rollDice();
- });
- copyBtn.addEventListener('click', (e) => {
- e.preventDefault();
- copyRollResult();
- });
- countInput.addEventListener('change', function() {
- let v = parseInt(this.value, 10);
- if (isNaN(v) || v < 1) this.value = 1;
- if (v > 99) this.value = 99;
- });
- sidesInput.addEventListener('change', function() {
- let v = parseInt(this.value, 10);
- if (isNaN(v) || v < 2) this.value = 6;
- if (v > 999) this.value = 999;
- });
- // ---------- 8. 拖拽功能(面板可移动)----------
- function makeDraggable() {
- const header = document.getElementById('dice-roller-header');
- let isDragging = false;
- let startX, startY, startLeft, startTop;
- function onMouseDown(e) {
- // 仅当点击在header或子元素时才启动拖拽
- if (!e.target.closest('#dice-roller-header')) return;
- e.preventDefault(); // 防止拖拽时选中文本或触发默认拖拽行为
- // 获取面板当前相对于视口的位置
- const rect = panel.getBoundingClientRect();
- const style = window.getComputedStyle(panel);
- // 若面板仍使用bottom/right定位,则切换为top/left以支持自由移动
- if (style.bottom !== 'auto' && style.bottom !== '0px' && style.right !== 'auto') {
- panel.style.top = rect.top + 'px';
- panel.style.left = rect.left + 'px';
- panel.style.bottom = 'auto';
- panel.style.right = 'auto';
- } else {
- // 如果已经是top/left定位,确保数值与当前渲染一致(防止某些情况不同步)
- panel.style.top = rect.top + 'px';
- panel.style.left = rect.left + 'px';
- }
- startX = e.clientX;
- startY = e.clientY;
- startLeft = parseFloat(panel.style.left) || rect.left;
- startTop = parseFloat(panel.style.top) || rect.top;
- isDragging = true;
- document.body.classList.add('dice-dragging'); // 全局拖拽态,禁用选中
- window.addEventListener('mousemove', onMouseMove);
- window.addEventListener('mouseup', onMouseUp);
- }
- function onMouseMove(e) {
- if (!isDragging) return;
- e.preventDefault();
- const dx = e.clientX - startX;
- const dy = e.clientY - startY;
- let newLeft = startLeft + dx;
- let newTop = startTop + dy;
- // 边界限制,避免面板完全移出可视区
- const winW = window.innerWidth;
- const winH = window.innerHeight;
- const panelW = panel.offsetWidth;
- const panelH = panel.offsetHeight;
- newLeft = Math.max(0, Math.min(winW - panelW, newLeft));
- newTop = Math.max(0, Math.min(winH - panelH, newTop));
- panel.style.left = newLeft + 'px';
- panel.style.top = newTop + 'px';
- }
- function onMouseUp(e) {
- if (isDragging) {
- isDragging = false;
- document.body.classList.remove('dice-dragging');
- window.removeEventListener('mousemove', onMouseMove);
- window.removeEventListener('mouseup', onMouseUp);
- }
- }
- header.addEventListener('mousedown', onMouseDown);
- }
- // 初始化拖拽
- makeDraggable();
- // ---------- 9. 初始化投掷一次(默认1d6)----------
- rollDice();
- })();
复制代码
|
板凳
2026-2-12 14:33:56
回复(4)
收起回复
steve回复凯凯凯凯凯酱
2026-2-12 17:04
回复
举报
只要需求写的足够清晰就行,不然他可能会瞎理解。让他做升级改版,甚至可能出现原本正常的功能失效的情况
 原来如此——
我靠,制作网页脚本居然如此简单? 
饿啊,紫苑,为什么 
|