mirror of
https://github.com/NeteaseCloudMusicApiEnhanced/api-clawer.git
synced 2026-03-21 09:53:10 +00:00
619 lines
15 KiB
HTML
619 lines
15 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
<title>网易云音乐抓包工具</title>
|
|
<style>
|
|
:root {
|
|
--fg: #333;
|
|
--muted: #666;
|
|
--border: #ddd;
|
|
--bg: #f5f5f5;
|
|
--panel: #ffffff;
|
|
--accent: #C20C0C;
|
|
}
|
|
* { box-sizing: border-box; }
|
|
html, body { height: 100%; }
|
|
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; color: var(--fg); background: var(--bg); line-height: 1.6; }
|
|
|
|
.main-container {
|
|
display: flex;
|
|
height: 100vh;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.left-panel {
|
|
width: 33%;
|
|
min-width: 300px;
|
|
max-width: 450px;
|
|
border-right: 1px solid var(--border);
|
|
background: var(--panel);
|
|
display: flex;
|
|
flex-direction: column;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.right-panel {
|
|
flex: 1;
|
|
background: var(--bg);
|
|
overflow-y: auto;
|
|
padding: 20px;
|
|
}
|
|
|
|
.left-content {
|
|
flex: 1;
|
|
overflow-y: auto;
|
|
padding: 16px;
|
|
}
|
|
|
|
.header {
|
|
padding: 16px 20px;
|
|
border-bottom: 1px solid var(--border);
|
|
background: #fafafa;
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.header h1 {
|
|
font-size: 20px;
|
|
font-weight: 600;
|
|
margin: 0 0 8px 0;
|
|
color: var(--accent);
|
|
}
|
|
|
|
.badge {
|
|
display: inline-block;
|
|
margin-left: 8px;
|
|
padding: 2px 8px;
|
|
border: 1px solid var(--border);
|
|
border-radius: 10px;
|
|
font-size: 11px;
|
|
color: var(--muted);
|
|
}
|
|
|
|
.sub {
|
|
font-size: 13px;
|
|
color: var(--muted);
|
|
margin: 0;
|
|
}
|
|
|
|
.block {
|
|
background: #fafafa;
|
|
border: 1px solid var(--border);
|
|
border-radius: 8px;
|
|
padding: 12px;
|
|
margin-bottom: 12px;
|
|
}
|
|
|
|
.block h2 {
|
|
font-size: 14px;
|
|
font-weight: 600;
|
|
margin: 0 0 10px 0;
|
|
}
|
|
|
|
.kvs {
|
|
display: grid;
|
|
grid-template-columns: 80px 1fr;
|
|
gap: 6px 10px;
|
|
align-items: start;
|
|
font-size: 13px;
|
|
}
|
|
|
|
.kvs div:first-child {
|
|
color: var(--muted);
|
|
font-weight: 500;
|
|
}
|
|
|
|
.kvs div:last-child {
|
|
word-break: break-all;
|
|
overflow-wrap: anywhere;
|
|
}
|
|
|
|
.status {
|
|
display: inline-block;
|
|
padding: 3px 8px;
|
|
border-radius: 4px;
|
|
font-size: 12px;
|
|
font-weight: 500;
|
|
}
|
|
|
|
.status-connected {
|
|
background: #e6f4ea;
|
|
color: #1e8e3e;
|
|
}
|
|
|
|
.status-waiting {
|
|
background: #fef7e0;
|
|
color: #f9ab00;
|
|
}
|
|
|
|
.capture-list {
|
|
margin-top: 12px;
|
|
}
|
|
|
|
.capture-list h2 {
|
|
font-size: 14px;
|
|
font-weight: 600;
|
|
margin: 0 0 10px 0;
|
|
}
|
|
|
|
.capture-list-item {
|
|
padding: 10px 12px;
|
|
border: 1px solid var(--border);
|
|
border-radius: 6px;
|
|
margin-bottom: 8px;
|
|
cursor: pointer;
|
|
transition: all 0.2s;
|
|
background: var(--panel);
|
|
}
|
|
|
|
.capture-list-item:hover {
|
|
border-color: var(--accent);
|
|
background: #fff5f5;
|
|
}
|
|
|
|
.capture-list-item.active {
|
|
border-color: var(--accent);
|
|
background: #fff5f5;
|
|
box-shadow: 0 2px 4px rgba(194, 12, 12, 0.1);
|
|
}
|
|
|
|
.capture-list-path {
|
|
font-weight: 600;
|
|
color: var(--accent);
|
|
font-size: 13px;
|
|
margin-bottom: 4px;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
white-space: nowrap;
|
|
}
|
|
|
|
.capture-list-time {
|
|
font-size: 12px;
|
|
color: var(--muted);
|
|
}
|
|
|
|
.empty-list {
|
|
text-align: center;
|
|
padding: 30px 20px;
|
|
color: var(--muted);
|
|
font-size: 13px;
|
|
}
|
|
|
|
.empty-list .icon {
|
|
font-size: 36px;
|
|
margin-bottom: 8px;
|
|
opacity: 0.5;
|
|
}
|
|
|
|
.detail-panel {
|
|
background: var(--panel);
|
|
border: 1px solid var(--border);
|
|
border-radius: 8px;
|
|
padding: 20px;
|
|
}
|
|
|
|
.detail-header {
|
|
margin-bottom: 20px;
|
|
padding-bottom: 16px;
|
|
border-bottom: 1px solid var(--border);
|
|
}
|
|
|
|
.detail-header h2 {
|
|
font-size: 18px;
|
|
font-weight: 600;
|
|
margin: 0 0 8px 0;
|
|
color: var(--accent);
|
|
}
|
|
|
|
.detail-time {
|
|
font-size: 13px;
|
|
color: var(--muted);
|
|
}
|
|
|
|
.detail-section {
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
.detail-section:last-child {
|
|
margin-bottom: 0;
|
|
}
|
|
|
|
.detail-section strong {
|
|
display: block;
|
|
margin-bottom: 10px;
|
|
font-size: 14px;
|
|
color: var(--muted);
|
|
font-weight: 600;
|
|
}
|
|
|
|
.copy-btn {
|
|
display: inline-block;
|
|
padding: 6px 12px;
|
|
background: var(--accent);
|
|
color: white;
|
|
border: none;
|
|
border-radius: 4px;
|
|
font-size: 12px;
|
|
cursor: pointer;
|
|
transition: background 0.2s;
|
|
margin-left: 8px;
|
|
}
|
|
|
|
.copy-btn:hover {
|
|
background: #a00a0a;
|
|
}
|
|
|
|
.copy-btn:active {
|
|
transform: scale(0.98);
|
|
}
|
|
|
|
pre {
|
|
margin: 0;
|
|
background: #f9f9f9;
|
|
border: 1px solid var(--border);
|
|
border-radius: 6px;
|
|
padding: 14px;
|
|
overflow-x: auto;
|
|
white-space: pre-wrap;
|
|
word-break: break-all;
|
|
font-size: 13px;
|
|
line-height: 1.5;
|
|
}
|
|
|
|
code {
|
|
font-family: 'Courier New', monospace;
|
|
font-size: 13px;
|
|
}
|
|
|
|
.no-selection {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
height: 100%;
|
|
color: var(--muted);
|
|
font-size: 14px;
|
|
}
|
|
|
|
.no-selection .icon {
|
|
font-size: 48px;
|
|
margin-right: 16px;
|
|
opacity: 0.5;
|
|
}
|
|
|
|
.toast {
|
|
position: fixed;
|
|
top: 20px;
|
|
right: 20px;
|
|
padding: 12px 20px;
|
|
background: #333;
|
|
color: white;
|
|
border-radius: 6px;
|
|
font-size: 14px;
|
|
opacity: 0;
|
|
transform: translateY(-10px);
|
|
transition: all 0.3s;
|
|
z-index: 1000;
|
|
}
|
|
|
|
.toast.show {
|
|
opacity: 1;
|
|
transform: translateY(0);
|
|
}
|
|
|
|
.clear-btn {
|
|
display: inline-block;
|
|
padding: 4px 10px;
|
|
background: #f5f5f5;
|
|
color: var(--muted);
|
|
border: 1px solid var(--border);
|
|
border-radius: 4px;
|
|
font-size: 12px;
|
|
cursor: pointer;
|
|
transition: all 0.2s;
|
|
margin-left: 8px;
|
|
}
|
|
|
|
.clear-btn:hover {
|
|
background: var(--accent);
|
|
color: white;
|
|
border-color: var(--accent);
|
|
}
|
|
|
|
.clear-btn:active {
|
|
transform: scale(0.98);
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="main-container">
|
|
<div class="left-panel">
|
|
<div class="header">
|
|
<h1>网易云音乐抓包工具 <span class="badge" id="version-badge">加载中...</span></h1>
|
|
<p class="sub">🔍 简易网易云音乐客户端抓包工具</p>
|
|
</div>
|
|
<div class="left-content">
|
|
<section class="block">
|
|
<h2>状态</h2>
|
|
<div class="kvs">
|
|
<div>连接状态</div><div><span id="status" class="status status-waiting">等待连接...</span></div>
|
|
<div>Base URL</div><div id="base-url">—</div>
|
|
<div>抓包数量</div><div id="capture-count">0</div>
|
|
</div>
|
|
</section>
|
|
|
|
<section class="block">
|
|
<h2>使用说明</h2>
|
|
<div class="kvs">
|
|
<div>1. 启动服务</div><div>运行 <code>npm run dev</code></div>
|
|
<div>2. 设置代理</div><div>客户端代理: <code>localhost:9000</code></div>
|
|
<div>3. 开始抓包</div><div>在客户端中操作,数据实时显示</div>
|
|
</div>
|
|
</section>
|
|
|
|
<div class="capture-list">
|
|
<h2>抓包列表 <button class="clear-btn" onclick="clearCaptures()">清空</button></h2>
|
|
<div id="capture-list"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="right-panel">
|
|
<div id="detail-panel" class="detail-panel">
|
|
<div class="no-selection">
|
|
<span class="icon">📡</span>
|
|
<span>请从左侧选择一个抓包记录查看详情</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="toast" class="toast">已复制到剪贴板</div>
|
|
|
|
<script>
|
|
let capturedData = [];
|
|
let selectedIndex = -1;
|
|
|
|
function updateStatus() {
|
|
const statusEl = document.getElementById('status');
|
|
statusEl.className = 'status status-connected';
|
|
statusEl.textContent = '已连接';
|
|
}
|
|
|
|
function renderCaptureList() {
|
|
const container = document.getElementById('capture-list');
|
|
const countEl = document.getElementById('capture-count');
|
|
|
|
if (!capturedData || capturedData.length === 0) {
|
|
container.innerHTML = `
|
|
<div class="empty-list">
|
|
<div class="icon">📡</div>
|
|
<p>暂无抓包数据</p>
|
|
<p style="font-size: 12px; margin-top: 6px; opacity: 0.7;">请设置网易云音乐客户端代理并开始使用</p>
|
|
</div>
|
|
`;
|
|
countEl.textContent = '0';
|
|
return;
|
|
}
|
|
|
|
countEl.textContent = capturedData.length;
|
|
|
|
container.innerHTML = capturedData.map((item, index) => `
|
|
<div class="capture-list-item ${index === selectedIndex ? 'active' : ''}"
|
|
onclick="selectCapture(${index})">
|
|
<div class="capture-list-path">${escapeHtml(item.path)}</div>
|
|
<div class="capture-list-time">${formatTime(item.timestamp)}</div>
|
|
</div>
|
|
`).join('');
|
|
}
|
|
|
|
function selectCapture(index) {
|
|
selectedIndex = index;
|
|
const item = capturedData[index];
|
|
const detailPanel = document.getElementById('detail-panel');
|
|
|
|
if (!item) {
|
|
detailPanel.innerHTML = `
|
|
<div class="no-selection">
|
|
<span class="icon">📡</span>
|
|
<span>请从左侧选择一个抓包记录查看详情</span>
|
|
</div>
|
|
`;
|
|
renderCaptureList();
|
|
return;
|
|
}
|
|
|
|
const filteredParam = filterParam(item.param);
|
|
|
|
detailPanel.innerHTML = `
|
|
<div class="detail-header">
|
|
<h2>${escapeHtml(item.path)}</h2>
|
|
<div class="detail-time">${formatTime(item.timestamp)}</div>
|
|
</div>
|
|
<div class="detail-section">
|
|
<strong>
|
|
请求参数
|
|
<button class="copy-btn" onclick="copyParam(${index})">复制参数</button>
|
|
</strong>
|
|
<pre><code>${formatJson(filteredParam)}</code></pre>
|
|
</div>
|
|
${item.response ? `
|
|
<div class="detail-section">
|
|
<strong>响应数据</strong>
|
|
<pre><code>${formatJson(item.response)}</code></pre>
|
|
</div>
|
|
` : ''}
|
|
`;
|
|
|
|
renderCaptureList();
|
|
}
|
|
|
|
function filterParam(param) {
|
|
if (!param || typeof param !== 'object') return param;
|
|
|
|
const filtered = {};
|
|
for (const key in param) {
|
|
if (key !== 'e_r' && key !== 'header') {
|
|
filtered[key] = param[key];
|
|
}
|
|
}
|
|
return filtered;
|
|
}
|
|
|
|
function copyParam(index) {
|
|
const item = capturedData[index];
|
|
if (!item || !item.param) return;
|
|
|
|
const filteredParam = filterParam(item.param);
|
|
const jsonStr = formatJson(filteredParam);
|
|
|
|
navigator.clipboard.writeText(jsonStr).then(() => {
|
|
showToast('已复制到剪贴板');
|
|
}).catch(err => {
|
|
console.error('Copy failed:', err);
|
|
showToast('复制失败,请手动复制');
|
|
});
|
|
}
|
|
|
|
function showToast(message) {
|
|
const toast = document.getElementById('toast');
|
|
toast.textContent = message;
|
|
toast.classList.add('show');
|
|
setTimeout(() => {
|
|
toast.classList.remove('show');
|
|
}, 2000);
|
|
}
|
|
|
|
function formatJson(obj) {
|
|
try {
|
|
return JSON.stringify(obj, null, 2);
|
|
} catch (e) {
|
|
return String(obj);
|
|
}
|
|
}
|
|
|
|
function formatTime(timestamp) {
|
|
try {
|
|
const date = new Date(timestamp);
|
|
return date.toLocaleTimeString('zh-CN', { hour12: false });
|
|
} catch (e) {
|
|
return timestamp;
|
|
}
|
|
}
|
|
|
|
function escapeHtml(text) {
|
|
const div = document.createElement('div');
|
|
div.textContent = text;
|
|
return div.innerHTML;
|
|
}
|
|
|
|
function fetchVersion() {
|
|
fetch('/api/version')
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.version) {
|
|
document.getElementById('version-badge').textContent = 'v' + data.version;
|
|
} else {
|
|
document.getElementById('version-badge').textContent = 'v0.1.0';
|
|
}
|
|
})
|
|
.catch(err => {
|
|
console.error('Failed to fetch version:', err);
|
|
document.getElementById('version-badge').textContent = 'v0.1.0';
|
|
});
|
|
}
|
|
|
|
function clearCaptures() {
|
|
if (!capturedData || capturedData.length === 0) {
|
|
showToast('暂无抓包数据可清空');
|
|
return;
|
|
}
|
|
|
|
if (!confirm('确定要清空所有抓包信息吗?')) {
|
|
return;
|
|
}
|
|
|
|
capturedData = [];
|
|
selectedIndex = -1;
|
|
renderCaptureList();
|
|
|
|
// 重置右侧详情面板
|
|
const detailPanel = document.getElementById('detail-panel');
|
|
detailPanel.innerHTML = `
|
|
<div class="no-selection">
|
|
<span class="icon">📡</span>
|
|
<span>请从左侧选择一个抓包记录查看详情</span>
|
|
</div>
|
|
`;
|
|
|
|
// 向服务器发送清空请求
|
|
fetch('/api/clear', { method: 'POST' })
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
showToast('已清空所有抓包信息');
|
|
} else {
|
|
showToast('清空失败: ' + (data.message || '未知错误'));
|
|
}
|
|
showToast('已清空所有抓包信息');
|
|
})
|
|
.catch(err => {
|
|
console.error('Clear failed:', err);
|
|
showToast('清空失败,请重试');
|
|
});
|
|
}
|
|
|
|
function setupSSE() {
|
|
const eventSource = new EventSource('/api/events');
|
|
|
|
eventSource.onmessage = function(event) {
|
|
try {
|
|
const data = JSON.parse(event.data);
|
|
|
|
// 更新状态为已连接
|
|
updateStatus();
|
|
|
|
// 直接使用服务器返回的数据
|
|
capturedData = data;
|
|
renderCaptureList();
|
|
|
|
// 如果当前没有选中且数据不为空,自动选中第一个
|
|
if (selectedIndex === -1 && data.length > 0) {
|
|
selectCapture(0);
|
|
}
|
|
|
|
// 如果选中的索引超出了数据范围,重置选中状态
|
|
if (selectedIndex >= data.length) {
|
|
selectedIndex = -1;
|
|
const detailPanel = document.getElementById('detail-panel');
|
|
detailPanel.innerHTML = `
|
|
<div class="no-selection">
|
|
<span class="icon">📡</span>
|
|
<span>请从左侧选择一个抓包记录查看详情</span>
|
|
</div>
|
|
`;
|
|
}
|
|
} catch (e) {
|
|
console.error('Failed to parse SSE data:', e);
|
|
}
|
|
};
|
|
|
|
eventSource.onerror = function(error) {
|
|
console.error('SSE error:', error);
|
|
};
|
|
}
|
|
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
var origin = window.location.origin;
|
|
document.getElementById('base-url').textContent = origin;
|
|
|
|
// 获取版本信息
|
|
fetchVersion();
|
|
|
|
// 设置 SSE 连接
|
|
setupSSE();
|
|
});
|
|
</script>
|
|
</body>
|
|
</html> |