mirror of
https://github.com/NeteaseCloudMusicApiEnhanced/api-enhanced.git
synced 2026-08-12 08:50:38 +00:00
583 lines
16 KiB
HTML
583 lines
16 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh">
|
|
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<meta name="referrer" content="no-referrer" />
|
|
<link rel="icon" href="docs/netease.png" />
|
|
<title>云小编每日抽奖 - 网易云音乐 API Enhanced</title>
|
|
<style>
|
|
:root {
|
|
--gold: #fdcb6e;
|
|
--text-light: #636e72;
|
|
--fg: #333;
|
|
--muted: #666;
|
|
--border: #ddd;
|
|
--bg: #f5f5f5;
|
|
--panel: #ffffff;
|
|
}
|
|
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
body {
|
|
font-family: 'Segoe UI', system-ui, -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif;
|
|
background: linear-gradient(135deg, var(--bg-start) 0%, var(--bg-end) 50%, #fce4ec 100%);
|
|
min-height: 100vh;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
padding: 1.5rem;
|
|
color: var(--text);
|
|
line-height: 1.5;
|
|
}
|
|
|
|
.container {
|
|
max-width: 520px;
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 1.5rem;
|
|
}
|
|
|
|
/* 标题编辑卡片 */
|
|
.card {
|
|
background: var(--card-bg);
|
|
border-radius: var(--radius);
|
|
padding: 1.8rem 2rem;
|
|
box-shadow: var(--shadow);
|
|
border: 1px solid var(--border);
|
|
transition: var(--transition);
|
|
}
|
|
|
|
.title-section {
|
|
text-align: center;
|
|
}
|
|
|
|
.title-input {
|
|
width: 100%;
|
|
border: 2px solid transparent;
|
|
border-radius: var(--radius-sm);
|
|
font-size: 1.6rem;
|
|
font-weight: 700;
|
|
text-align: center;
|
|
padding: 0.6rem 1rem;
|
|
color: var(--text);
|
|
background: #fafafa;
|
|
transition: var(--transition);
|
|
outline: none;
|
|
font-family: inherit;
|
|
}
|
|
|
|
.title-input:hover {
|
|
background: #f5f3ff;
|
|
}
|
|
|
|
.title-input:focus {
|
|
border-color: var(--primary-light);
|
|
background: #fff;
|
|
box-shadow: 0 0 0 4px rgba(124, 108, 240, 0.06);
|
|
}
|
|
|
|
.title-hint {
|
|
font-size: 0.8rem;
|
|
color: #b2bec3;
|
|
margin-top: 0.4rem;
|
|
}
|
|
|
|
/* 抽奖主卡片 */
|
|
.lottery-card {
|
|
background: var(--card-bg);
|
|
border-radius: var(--radius);
|
|
padding: 2rem 2rem 2.2rem;
|
|
box-shadow: var(--shadow);
|
|
border: 1px solid var(--border);
|
|
text-align: center;
|
|
}
|
|
|
|
.rolling-display {
|
|
font-size: 2.4rem;
|
|
font-weight: 800;
|
|
color: var(--primary);
|
|
min-height: 4rem;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
letter-spacing: 1px;
|
|
word-break: break-all;
|
|
}
|
|
|
|
.rolling-display.idle {
|
|
color: #c4b5fd;
|
|
font-size: 1.3rem;
|
|
font-weight: 500;
|
|
}
|
|
|
|
/* ---- Winner Result ---- */
|
|
.winner-display {
|
|
background: linear-gradient(135deg, #fff9e6, #fff3cd);
|
|
border: 2px solid var(--gold);
|
|
border-radius: var(--radius);
|
|
padding: 1.5rem;
|
|
margin: 1rem 0 1.5rem;
|
|
animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
|
|
}
|
|
|
|
.winner-label {
|
|
font-size: 14px;
|
|
font-weight: 600;
|
|
color: #065f46;
|
|
margin-bottom: 8px;
|
|
}
|
|
|
|
.winner-name {
|
|
font-size: 2rem;
|
|
font-weight: 800;
|
|
color: #dc2626;
|
|
letter-spacing: 1px;
|
|
word-break: break-all;
|
|
}
|
|
|
|
.winner-img {
|
|
width: 200px;
|
|
height: 200px;
|
|
margin: -20px;
|
|
}
|
|
|
|
.confetti-row {
|
|
margin-top: 8px;
|
|
display: flex;
|
|
justify-content: center;
|
|
gap: 0.5rem;
|
|
}
|
|
|
|
.confetti-emoji {
|
|
font-size: 1.6rem;
|
|
animation: bounce 0.6s ease infinite alternate;
|
|
}
|
|
|
|
.confetti-emoji:nth-child(2) {
|
|
animation-delay: 0.15s;
|
|
}
|
|
|
|
.confetti-emoji:nth-child(3) {
|
|
animation-delay: 0.3s;
|
|
}
|
|
|
|
@keyframes bounce {
|
|
from { transform: translateY(0); }
|
|
to { transform: translateY(-8px); }
|
|
}
|
|
|
|
/* 按钮 */
|
|
.btn {
|
|
padding: 0.9rem 2.5rem;
|
|
border: none;
|
|
border-radius: 50px;
|
|
font-weight: 700;
|
|
font-size: 1.05rem;
|
|
cursor: pointer;
|
|
transition: var(--transition);
|
|
letter-spacing: 0.5px;
|
|
width: 100%;
|
|
display: inline-flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
gap: 0.5rem;
|
|
}
|
|
|
|
.btn-lottery {
|
|
background: linear-gradient(135deg, #fd79a8, #e84393);
|
|
color: #fff;
|
|
box-shadow: 0 6px 20px rgba(253, 121, 168, 0.35);
|
|
}
|
|
|
|
.btn-lottery:hover:not(:disabled) {
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 10px 28px rgba(253, 121, 168, 0.45);
|
|
}
|
|
|
|
.btn-lottery:active:not(:disabled) {
|
|
transform: translateY(0);
|
|
}
|
|
|
|
.btn-lottery:disabled {
|
|
background: #b2bec3;
|
|
box-shadow: none;
|
|
cursor: not-allowed;
|
|
transform: none;
|
|
}
|
|
|
|
.btn-reset {
|
|
background: transparent;
|
|
border: 2px solid var(--border);
|
|
color: var(--text-light);
|
|
margin-top: 0.8rem;
|
|
font-weight: 600;
|
|
}
|
|
|
|
.btn-reset:hover {
|
|
border-color: var(--primary-light);
|
|
color: var(--primary);
|
|
background: #f8f7ff;
|
|
}
|
|
|
|
/* 状态提示 */
|
|
.status-bar {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
padding: 10px 14px;
|
|
background: #f9fafb;
|
|
border-radius: 6px;
|
|
margin-top: 16px;
|
|
font-size: 13px;
|
|
color: #666;
|
|
}
|
|
|
|
.status-dot {
|
|
width: 8px;
|
|
height: 8px;
|
|
border-radius: 50%;
|
|
background: #059669;
|
|
flex-shrink: 0;
|
|
animation: pulse 1.5s ease infinite;
|
|
}
|
|
|
|
.status-dot.error {
|
|
background: #dc2626;
|
|
}
|
|
|
|
.status-dot.idle {
|
|
background: #9ca3af;
|
|
animation: none;
|
|
}
|
|
|
|
@keyframes pulse {
|
|
0%, 100% { opacity: 1; }
|
|
50% { opacity: 0.4; }
|
|
}
|
|
|
|
.status-text {
|
|
flex: 1;
|
|
}
|
|
|
|
/* ---- Footer ---- */
|
|
.footer-link {
|
|
text-align: center;
|
|
margin-top: 24px;
|
|
padding-top: 16px;
|
|
border-top: 1px solid #eee;
|
|
font-size: 13px;
|
|
}
|
|
|
|
.footer-link a {
|
|
color: #666;
|
|
text-decoration: none;
|
|
}
|
|
|
|
.footer-link a:hover {
|
|
text-decoration: underline;
|
|
}
|
|
|
|
/* ---- Responsive ---- */
|
|
@media (max-width: 500px) {
|
|
|
|
.card,
|
|
.lottery-card {
|
|
padding: 1.4rem 1.2rem;
|
|
}
|
|
|
|
.title-input {
|
|
font-size: 1.3rem;
|
|
}
|
|
|
|
.rolling-display {
|
|
font-size: 1.8rem;
|
|
min-height: 3rem;
|
|
}
|
|
|
|
.winner-name {
|
|
font-size: 1.5rem;
|
|
}
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<div class="container">
|
|
<!-- 标题编辑区 -->
|
|
<div class="card title-section">
|
|
<input type="text" class="title-input" id="titleInput" value="🎉 云小编每日抽奖 🎉" autocomplete="off" disabled>
|
|
<div class="title-hint">每次抽奖消耗 <b>200 个曲库编辑部积分</b>,每日最多可抽奖 3 次</div>
|
|
</div>
|
|
|
|
<!-- 抽奖主区域 -->
|
|
<div class="lottery-card">
|
|
<div class="rolling-display idle" id="rollingDisplay">等待抽奖</div>
|
|
<div id="resultContainer"></div>
|
|
<button class="btn btn-lottery" id="lotteryBtn">
|
|
<span>🎲</span> 开始抽奖
|
|
</button>
|
|
<button class="btn btn-reset" id="resetBtn">
|
|
<span>🔄</span> 编辑令牌
|
|
</button>
|
|
<div class="status-bar" id="statusBar">
|
|
<span class="status-dot idle" id="statusDot"></span>
|
|
<span class="status-text" id="statusText">就绪,点击按钮开始抽奖</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
(function () {
|
|
// ============ DOM 元素 ============
|
|
const titleInput = document.getElementById('titleInput');
|
|
const rollingDisplay = document.getElementById('rollingDisplay');
|
|
const resultContainer = document.getElementById('resultContainer');
|
|
const lotteryBtn = document.getElementById('lotteryBtn');
|
|
const statusDot = document.getElementById('statusDot');
|
|
const statusText = document.getElementById('statusText');
|
|
|
|
// ============ 状态 ============
|
|
let isDrawing = false;
|
|
let rollingTimer = null;
|
|
|
|
// ============ 状态栏更新 ============
|
|
function setStatus(type, message) {
|
|
statusText.textContent = message;
|
|
statusDot.className = 'status-dot';
|
|
if (type === 'error') {
|
|
statusDot.classList.add('error');
|
|
} else if (type === 'info') {
|
|
statusDot.style.background = '#059669';
|
|
} else {
|
|
statusDot.classList.add('idle');
|
|
}
|
|
}
|
|
|
|
// ============ 重置结果 ============
|
|
function resetResult() {
|
|
resultContainer.innerHTML = '';
|
|
rollingDisplay.textContent = '等待抽奖';
|
|
rollingDisplay.className = 'rolling-display idle';
|
|
setStatus('idle', '就绪,点击按钮开始抽奖');
|
|
}
|
|
|
|
// ============ 本地令牌管理 ============
|
|
const cookieKey = 'ncm_cookie';
|
|
let cookie = localStorage.getItem(cookieKey) || '';
|
|
if (cookie) {
|
|
cookieInput.value = cookie;
|
|
}
|
|
|
|
window.readLocalCookie = function () {
|
|
const local = localStorage.getItem(cookieKey);
|
|
if (local) {
|
|
cookie = local;
|
|
cookieInput.value = local;
|
|
setStatus('info', '已读取本地令牌');
|
|
} else {
|
|
setStatus('error', '未在本地发现令牌,请手动输入');
|
|
}
|
|
};
|
|
|
|
window.clearCookie = function () {
|
|
cookie = '';
|
|
cookieInput.value = '';
|
|
localStorage.removeItem(cookieKey);
|
|
setStatus('info', '已清除本地令牌');
|
|
};
|
|
|
|
window.saveCookie = function () {
|
|
const ck = cookieInput.value.trim();
|
|
if (ck) {
|
|
cookie = ck;
|
|
localStorage.setItem(cookieKey, ck);
|
|
setStatus('info', '已保存本地令牌');
|
|
} else {
|
|
setStatus('error', '令牌内容为空,未保存');
|
|
}
|
|
};
|
|
|
|
function getCookie() {
|
|
const ck = cookieInput.value.trim();
|
|
if (ck) cookie = ck;
|
|
return ck || cookie || '';
|
|
}
|
|
|
|
// ============ 调用后端接口 ============
|
|
async function request(url, params) {
|
|
try {
|
|
url += '?timestamp=' + Date.now() + params;
|
|
const ck = getCookie();
|
|
if (ck) url += '&cookie=' + encodeURIComponent(ck);
|
|
|
|
const response = await fetch(url);
|
|
|
|
let res;
|
|
try {
|
|
res = await response.json();
|
|
} catch (error) {
|
|
console.error('数据解析错误:', error);
|
|
throw new Error('接口请求错误: ' + response.status + ': ' + response.statusText);
|
|
}
|
|
|
|
if (res.code !== 200) {
|
|
throw new Error('接口返回错误: ' + res.code + ': ' + (res.message || '未知错误'));
|
|
}
|
|
|
|
return res;
|
|
} catch (error) {
|
|
console.error('接口请求失败:', error);
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
async function fetchLotteryResult() {
|
|
const user = await request('rep/ugc/user/get', '');
|
|
|
|
if ((user.data?.availablePoints ?? 0) < 200) {
|
|
throw new Error('用户剩余积分不足,请先完成任务获取积分');
|
|
}
|
|
|
|
const chance = await request('middle/play/lottery/remain/chance', '&activityId=6501202');
|
|
|
|
if (chance.data === 0) {
|
|
throw new Error('今日机会已用完,明天再来吧');
|
|
}
|
|
|
|
const res = await request('middle/play/do/lottery', '&activityId=6501202&drawCount=1');
|
|
|
|
// 根据你的后端返回格式提取中奖者名称
|
|
const winner = res.data?.prizeDetailInfoMap?.['8186002']?.prizeName;
|
|
if (!winner) {
|
|
throw new Error('无法解析响应数据');
|
|
}
|
|
|
|
// [抽奖结果, 剩余机会]
|
|
return [winner, res.data.restChance];
|
|
}
|
|
|
|
// ============ 滚动动画 ============
|
|
function startRollingAnimation(finalWinner, img) {
|
|
const placeholderNames = ['🎰', '🎲', '🎯', '✨', '💫', '🌟', '🎪', '🎭'];
|
|
const totalDuration = 2000;
|
|
const startInterval = 50;
|
|
const endInterval = 280;
|
|
const startTime = Date.now();
|
|
|
|
rollingDisplay.className = 'rolling-display';
|
|
resultContainer.innerHTML = '';
|
|
|
|
function roll() {
|
|
const elapsed = Date.now() - startTime;
|
|
const progress = Math.min(elapsed / totalDuration, 1.0);
|
|
const easeOutProgress = 1 - Math.pow(1 - progress, 3);
|
|
const currentInterval = startInterval + (endInterval - startInterval) * easeOutProgress;
|
|
|
|
const randomPlaceholder = placeholderNames[Math.floor(Math.random() * placeholderNames.length)];
|
|
rollingDisplay.textContent = randomPlaceholder;
|
|
|
|
if (progress >= 1.0) {
|
|
clearTimeout(rollingTimer);
|
|
rollingDisplay.textContent = finalWinner;
|
|
rollingDisplay.style.display = 'none';
|
|
showWinnerResult(finalWinner, img);
|
|
finishDrawing();
|
|
return;
|
|
}
|
|
|
|
rollingTimer = setTimeout(roll, currentInterval);
|
|
}
|
|
|
|
roll();
|
|
}
|
|
|
|
function showWinnerResult(winner) {
|
|
resultContainer.innerHTML = `
|
|
<div class="winner-display">
|
|
<div class="winner-label">🏆 恭喜中奖</div>
|
|
<div class="winner-name">${escapeHTML(winner)}</div>
|
|
<div class="confetti-row">
|
|
<span class="confetti-emoji">🎉</span>
|
|
<span class="confetti-emoji">🎊</span>
|
|
<span class="confetti-emoji">✨</span>
|
|
</div>
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
function escapeHTML(str) {
|
|
const div = document.createElement('div');
|
|
div.appendChild(document.createTextNode(str));
|
|
return div.innerHTML;
|
|
}
|
|
|
|
function finishDrawing() {
|
|
isDrawing = false;
|
|
lotteryBtn.disabled = false;
|
|
}
|
|
|
|
// ============ 主抽奖流程 ============
|
|
async function startLottery() {
|
|
if (isDrawing) return;
|
|
|
|
isDrawing = true;
|
|
lotteryBtn.disabled = true;
|
|
resultContainer.innerHTML = '';
|
|
rollingDisplay.className = 'rolling-display';
|
|
rollingDisplay.textContent = '🎰';
|
|
rollingDisplay.style.display = 'flex';
|
|
setStatus('info', '正在获取抽奖结果...');
|
|
|
|
try {
|
|
const res = await fetchLotteryResult();
|
|
setStatus('info', '抽奖成功,剩余次数 ' + res[1]);
|
|
// 启动滚动动画,最终定格在中奖者
|
|
startRollingAnimation(res[0]);
|
|
} catch (error) {
|
|
rollingDisplay.textContent = '抽奖失败';
|
|
rollingDisplay.className = 'rolling-display idle';
|
|
setStatus('error', '抽奖失败: ' + error.message);
|
|
isDrawing = false;
|
|
lotteryBtn.disabled = false;
|
|
}
|
|
}
|
|
|
|
// ============ 事件绑定 ============
|
|
lotteryBtn.addEventListener('click', startLottery);
|
|
|
|
// 空格键快捷抽奖
|
|
document.addEventListener('keydown', (e) => {
|
|
if (e.key === ' ' && document.activeElement !== titleInput) {
|
|
e.preventDefault();
|
|
if (!isDrawing && !lotteryBtn.disabled) {
|
|
startLottery();
|
|
}
|
|
}
|
|
});
|
|
|
|
// 回车键在输入框中触发保存
|
|
cookieInput.addEventListener('keypress', function (e) {
|
|
if (e.key === 'Enter') {
|
|
saveCookie();
|
|
}
|
|
});
|
|
|
|
// ============ 初始化 ============
|
|
resetResult();
|
|
|
|
window.demo = function (name, chance, img) {
|
|
rollingDisplay.style.display = 'flex';
|
|
setStatus('info', '抽奖成功,剩余次数 ' + (chance || '0'));
|
|
startRollingAnimation(name || '演示', img || 'https://p5.music.126.net/obj/worDmcOCw6HCnzzCmsKx/61891591760/8d1c/528a/e977/10cbaa3fb39e8057be5d2560182cc5c7.png');
|
|
};
|
|
})();
|
|
</script>
|
|
</body>
|
|
|
|
</html> |