第 1 项 / 共 10 项
location.pathname + window.location.search; var pageTitle = "北北的橱窗一图库一梦幻天景09"; var module = 'gallery'; var module_id = '86'; fetch('/deshi/favourite/add_to_favorites.php', { method: 'POST', headers: { 'Content-Type': 'application/json' }, credentials: 'same-origin', body: JSON.stringify({ userId: userId, pageUrl: pageUrl, pageTitle: pageTitle, module: module, module_id: module_id }) }) .then(function (res) { if (!res.ok) throw new Error('HTTP ' + res.status); return res.json(); }) .then(function (data) { if (!data.success) return; document.querySelectorAll('#shopBtn, #shopBtn2').forEach(function (b) { b.setAttribute('data-favorited', '1'); var t = b.querySelector('.txt'); if (t) t.textContent = '取消收藏'; }); if (typeof window.__applyMergedFollowCollectLabel === 'function') window.__applyMergedFollowCollectLabel(); }) .catch(function () {}); }); // 取消关注成功后:合并模式下同步取消收藏,按钮文案恢复为「关注+收藏」 document.addEventListener('deshi-follow-delete-success', function () { var main = document.getElementById('followBtn'); if (!main || main.getAttribute('data-merge-follow-fav') !== '1') return; var module = 'gallery'; var module_id = '86'; var favEl = document.querySelector('#shopBtn2') || document.querySelector('#shopBtn'); function refreshMergedLabel() { if (typeof window.__applyMergedFollowCollectLabel === 'function') window.__applyMergedFollowCollectLabel(); } if (!favEl || favEl.getAttribute('data-favorited') !== '1') { refreshMergedLabel(); return; } fetch('/deshi/favourite/favorites_remove.php', { method: 'POST', headers: { 'Content-Type': 'application/json' }, credentials: 'same-origin', body: JSON.stringify({ module: module, module_id: module_id }) }) .then(function (res) { if (!res.ok) throw new Error('HTTP ' + res.status); return res.json(); }) .then(function (data) { if (data.success) { document.querySelectorAll('#shopBtn, #shopBtn2').forEach(function (b) { b.setAttribute('data-favorited', '0'); var t = b.querySelector('.txt'); if (t) t.textContent = '收藏'; }); refreshMergedLabel(); } else if (typeof window.__applyMergedFollowCollectLabel === 'function') { window.__applyMergedFollowCollectLabel(); } }) .catch(function () { if (typeof window.__applyMergedFollowCollectLabel === 'function') window.__applyMergedFollowCollectLabel(); }); }); // 合并按钮:已关注且已收藏 →「已关注+已收藏」,否则→「关注+收藏」 (function mergedFollowCollectLabel() { function applyMergedFollowCollectLabel() { var main = document.getElementById('followBtn'); if (!main || main.getAttribute('data-merge-follow-fav') !== '1') return; var favEl = document.querySelector('#shopBtn2') || document.querySelector('#shopBtn'); var favorited = favEl && favEl.getAttribute('data-favorited') === '1'; var following = main.getAttribute('aria-pressed') === 'true'; var label; var ariaLab; if (following && favorited) { label = '已关注+已收藏'; ariaLab = '已关注+已收藏'; } else { label = '关注+收藏'; ariaLab = '关注/收藏'; } ['followBtn', 'fsFollowBtn'].forEach(function (id) { var btn = document.getElementById(id); if (!btn) return; btn.setAttribute('aria-label', ariaLab); var txt = btn.querySelector('.txt'); if (txt) txt.textContent = label; if (id === 'fsFollowBtn') btn.setAttribute('aria-pressed', main.getAttribute('aria-pressed') || 'false'); }); } window.__applyMergedFollowCollectLabel = applyMergedFollowCollectLabel; applyMergedFollowCollectLabel(); document.addEventListener('deshi-follow-changed', applyMergedFollowCollectLabel); })(); });