Files
web_huangguo2_h5/app/static/js/favorites-manage.js
T
谢宇宁andClaude Opus 5.5 0fbdba5ccf Initial commit
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 11:47:47 +07:00

57 lines
2.1 KiB
JavaScript

(() => {
const root = document.querySelector('[data-favorites]');
const manage = root?.querySelector('[data-favorites-manage]');
if (!manage) return;
manage.addEventListener('click', () => {
const active = document.body.classList.toggle('is-managing');
manage.setAttribute('aria-pressed', String(active));
manage.querySelector('span').textContent = active ? '完成' : '管理';
});
root.querySelectorAll('[data-favorites-remove]').forEach(button => {
button.addEventListener('click', async (event) => {
event.preventDefault();
event.stopPropagation();
if (button.disabled) return;
button.disabled = true;
const kind = button.dataset.kind || 'short';
const id = Number(button.dataset.id);
let url = '/api/playlet/collect/set';
let body = {id, isCollect: false};
if (kind === 'chapter') {
url = '/api/playlet/chapter/collect/set';
body = {chapterId: id, isCollect: false};
} else if (kind === 'series') {
url = '/api/video/collect/set';
body = {id, isCollect: false};
}
const trackerContext = kind === 'series' ? null : {
media_id: '',
drama_id: String(button.dataset.dramaId || ''),
drama_title: String(button.dataset.dramaTitle || ''),
episode: Math.max(1, Number(button.dataset.episode) || 1),
total_episode: Math.max(1, Number(button.dataset.totalEpisode) || 1),
video_id: String(button.dataset.videoId || ''),
drama_content_type: 'short_drama',
recommend_trace_id: '',
};
try {
if (!window.HttpRequest || typeof window.HttpRequest.post !== 'function') {
throw new Error('请求服务未就绪');
}
const result = await window.HttpRequest.post(
url,
body,
trackerContext ? {trackerContext} : undefined,
);
if (!result || Number(result.code) !== 200) throw new Error((result && (result.tip || result.msg)) || '取消收藏失败');
window.location.reload();
} catch (_) {
button.disabled = false;
window.alert('操作失败,请稍后重试');
}
});
});
})();