670 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>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
min-height: 100vh;
background: #f5f5f5;
padding: 20px;
}
.container {
max-width: 520px;
margin: 40px auto;
background: white;
border-radius: 12px;
padding: 32px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
h1 {
font-size: 24px;
font-weight: 600;
color: #333;
margin-bottom: 8px;
text-align: center;
}
.subtitle {
font-size: 14px;
color: #666;
margin-bottom: 24px;
text-align: center;
}
.subtitle b {
color: #d63031;
}
/* ---- Section ---- */
.section {
margin-bottom: 24px;
padding-bottom: 20px;
border-bottom: 1px solid #eee;
}
.section:last-of-type {
border-bottom: none;
margin-bottom: 0;
padding-bottom: 0;
}
.section-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
}
.section-title {
font-size: 16px;
font-weight: 600;
color: #333;
}
/* ---- Form Elements ---- */
.form-group {
margin-bottom: 16px;
text-align: left;
}
label {
display: block;
font-size: 13px;
font-weight: 500;
color: #555;
margin-bottom: 6px;
}
label .tag {
display: inline-block;
font-size: 11px;
font-weight: 400;
padding: 1px 6px;
border-radius: 3px;
margin-left: 6px;
}
label .tag.o {
background: #fef3c7;
color: #92400e;
}
input[type="text"],
input[type="number"],
textarea {
width: 100%;
padding: 10px 14px;
border: 1px solid #ddd;
border-radius: 6px;
font-size: 14px;
outline: none;
font-family: inherit;
transition: border-color 0.2s;
}
input[type="text"]:focus,
input[type="number"]:focus,
textarea:focus {
border-color: #333;
}
textarea {
resize: vertical;
}
.btn {
display: block;
width: 100%;
padding: 12px;
background: #333;
color: white;
font-size: 15px;
font-weight: 500;
border-radius: 6px;
cursor: pointer;
transition: background 0.2s ease;
border: none;
text-align: center;
margin-top: 16px;
}
.btn:hover {
background: #555;
}
.btn:disabled {
background: #ccc;
cursor: not-allowed;
}
.btn-sm {
display: inline-block;
width: auto;
padding: 6px 16px;
background: #333;
color: white;
font-size: 13px;
font-weight: 500;
border-radius: 6px;
cursor: pointer;
transition: background 0.2s ease;
border: none;
text-align: center;
margin-top: 0;
}
.btn-sm:hover {
background: #555;
}
.btn-sm:disabled {
background: #ccc;
cursor: not-allowed;
}
.btn-sm.gray {
background: #6b7280;
}
.btn-sm.gray:hover {
background: #4b5563;
}
.btn-sm.gray:disabled {
background: #d1d5db;
}
.btn-sm.green {
background: #059669;
}
.btn-sm.green:hover {
background: #047857;
}
.btn-sm.green:disabled {
background: #a7f3d0;
}
.quick-fill {
margin-top: 5px;
font-size: 12px;
color: #666;
}
.quick-fill span {
color: #0066cc;
cursor: pointer;
margin-right: 8px;
}
.quick-fill span:hover {
text-decoration: underline;
}
/* ---- Lottery Display ---- */
.lottery-display {
text-align: center;
padding: 24px 16px;
background: #f9fafb;
border-radius: 8px;
border: 1px solid #eee;
margin-bottom: 16px;
}
.rolling-display {
font-size: 2.4rem;
font-weight: 800;
color: #333;
min-height: 4rem;
display: flex;
align-items: center;
justify-content: center;
letter-spacing: 1px;
word-break: break-all;
}
.rolling-display.idle {
color: #999;
font-size: 1.2rem;
font-weight: 500;
}
/* ---- Winner Result ---- */
.winner-display {
background: #f0fdf4;
border: 1px solid #86efac;
border-radius: 8px;
padding: 20px 16px;
margin-top: 16px;
text-align: center;
}
.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;
}
.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);
}
}
/* ---- Status ---- */
.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) {
.container {
padding: 20px 16px;
margin: 20px auto;
}
h1 {
font-size: 20px;
}
.rolling-display {
font-size: 1.8rem;
min-height: 3rem;
}
.winner-name {
font-size: 1.5rem;
}
}
</style>
</head>
<body>
<div class="container">
<h1>云小编每日抽奖</h1>
<p class="subtitle">每次抽奖消耗 <b>200 个曲库编辑部积分</b>,每日最多可抽奖 3 次</p>
<!-- Cookie 管理 -->
<div class="form-group">
<label for="cookieInput">令牌 <span class="tag o">可选</span></label>
<input type="text" id="cookieInput" placeholder="留空则默认读取本地存储的令牌" autocomplete="off" />
<div class="quick-fill">
<span onclick="readLocalCookie()">读取本地令牌</span>
<span onclick="clearCookie()">清除令牌</span>
<span onclick="saveCookie()">保存令牌</span>
</div>
</div>
<!-- 抽奖区域 -->
<div class="section">
<div class="section-header">
<span class="section-title">每日抽奖</span>
</div>
<div class="lottery-display">
<div class="rolling-display idle" id="rollingDisplay">等待抽奖</div>
<div id="resultContainer"></div>
</div>
<button class="btn" id="lotteryBtn">
🎲 开始抽奖
</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 class="footer-link">
<a href="/">← 返回首页</a>
<span style="margin: 0 8px; color: #ddd;">·</span>
<a href="/ugc.html">云小编任务中心</a>
</div>
</div>
<script>
(function () {
// ============ DOM 元素 ============
const cookieInput = document.getElementById('cookieInput');
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) {
const placeholderNames = ['🎰', '🎲', '🎯', '✨', '💫', '🌟', '🎪', '🎭'];
const totalDuration = 2800;
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;
showWinnerResult(finalWinner);
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 = '🎰';
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', function (e) {
if (e.key === ' ' && document.activeElement !== cookieInput) {
e.preventDefault();
if (!isDrawing && !lotteryBtn.disabled) {
startLottery();
}
}
});
// 回车键在输入框中触发保存
cookieInput.addEventListener('keypress', function (e) {
if (e.key === 'Enter') {
saveCookie();
}
});
// ============ 初始化 ============
resetResult();
})();
</script>
</body>
</html>