hip
This commit is contained in:
+37
-13
@@ -293,17 +293,34 @@
|
||||
return;
|
||||
}
|
||||
const favoBtns = document.querySelectorAll("#a_favo");
|
||||
if (!favoBtns.length) return;
|
||||
const firstFavoBtn = favoBtns[0];
|
||||
const chanRehostBtn = document.querySelector('#chan-item-rehost-btn');
|
||||
const isChan = firstFavoBtn?.dataset?.isChan === 'true' || !!chanRehostBtn;
|
||||
const chanUrl = firstFavoBtn?.dataset?.chanUrl || chanRehostBtn?.dataset?.url;
|
||||
let localId = firstFavoBtn?.dataset?.localId;
|
||||
|
||||
const wasAlreadyFav = favoBtns[0].classList.contains('fa-solid') && !favoBtns[0].classList.contains('fa-spinner');
|
||||
|
||||
const setFavoUi = (isFav) => {
|
||||
favoBtns.forEach(btn => {
|
||||
btn.classList.remove('fa-spinner', 'fa-spin');
|
||||
btn.classList.add('iconset', 'fa-heart');
|
||||
btn.classList.toggle('fa-solid', isFav);
|
||||
btn.classList.toggle('fa-regular', !isFav);
|
||||
});
|
||||
};
|
||||
|
||||
const setFavoLoading = () => {
|
||||
favoBtns.forEach(btn => {
|
||||
btn.classList.remove('fa-heart');
|
||||
btn.classList.add('iconset', 'fa-solid', 'fa-spinner', 'fa-spin');
|
||||
});
|
||||
};
|
||||
|
||||
// If viewing un-rehosted 4chan post, auto-rehost first
|
||||
if (isChan && !localId && chanUrl) {
|
||||
favoBtns.forEach(btn => {
|
||||
btn.className = 'iconset fa-solid fa-spinner fa-spin';
|
||||
});
|
||||
setFavoLoading();
|
||||
try {
|
||||
const csrfToken = window.f0ckSession?.csrf_token || '';
|
||||
const rehostResp = await fetch('/api/v2/scroller/rehost', {
|
||||
@@ -331,6 +348,15 @@
|
||||
const infoEl = document.querySelector("#a_info");
|
||||
if (infoEl) infoEl.dataset.itemId = localId;
|
||||
|
||||
const timeEl = document.querySelector('time.timeago');
|
||||
if (timeEl) {
|
||||
const nowIso = new Date().toISOString();
|
||||
timeEl.dataset.iso = nowIso;
|
||||
const fullDate = typeof window.f0ckFormatDateFull === 'function' ? window.f0ckFormatDateFull(nowIso) : new Date().toLocaleString();
|
||||
timeEl.setAttribute('tooltip', fullDate);
|
||||
timeEl.textContent = (window.f0ckTimeAgo ? window.f0ckTimeAgo(nowIso) : (window.f0ckI18n?.timeago_just_now || 'just now'));
|
||||
}
|
||||
|
||||
if (chanRehostBtn) {
|
||||
chanRehostBtn.classList.add('rehosted');
|
||||
chanRehostBtn.outerHTML = `
|
||||
@@ -345,9 +371,7 @@
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('[CHAN-FAV-ADMIN] Auto-rehost error:', err);
|
||||
favoBtns.forEach(btn => {
|
||||
btn.className = 'iconset fa-regular fa-heart';
|
||||
});
|
||||
setFavoUi(wasAlreadyFav);
|
||||
if (typeof window.flashMessage === 'function') {
|
||||
window.flashMessage('Failed to favorite post', 3000, 'error');
|
||||
}
|
||||
@@ -356,11 +380,12 @@
|
||||
}
|
||||
|
||||
const ctx = getContext();
|
||||
if (!ctx) return;
|
||||
if (!ctx) {
|
||||
setFavoUi(wasAlreadyFav);
|
||||
return;
|
||||
}
|
||||
const postid = localId ? Number(localId) : ctx.postid;
|
||||
|
||||
const wasAlreadyFav = favoBtns.length > 0 && favoBtns[0].classList.contains('fa-solid');
|
||||
|
||||
try {
|
||||
const res = await post('/api/v2/togglefav', {
|
||||
postid: postid,
|
||||
@@ -373,10 +398,7 @@
|
||||
// Authoritative server state takes priority; fallback to inverting previous UI state
|
||||
const isNowFav = (res.favorited !== undefined) ? !!res.favorited : !wasAlreadyFav;
|
||||
|
||||
favoBtns.forEach(favoBtn => {
|
||||
favoBtn.classList.toggle('fa-solid', isNowFav);
|
||||
favoBtn.classList.toggle('fa-regular', !isNowFav);
|
||||
});
|
||||
setFavoUi(isNowFav);
|
||||
|
||||
const favcontainer = document.querySelector('#favs');
|
||||
if (favcontainer) {
|
||||
@@ -446,12 +468,14 @@
|
||||
window.flashMessage((window.f0ckI18n && (isNowFav ? window.f0ckI18n.fav_added : window.f0ckI18n.fav_removed)) || (isNowFav ? 'ADDED TO FAVORITES' : 'REMOVED FROM FAVORITES'));
|
||||
if (navigator.vibrate) navigator.vibrate(50);
|
||||
} else {
|
||||
setFavoUi(wasAlreadyFav);
|
||||
const errMsg = (res && (res.msg || res.error)) || 'Anonymous favoriting is disabled.';
|
||||
if (typeof window.flashMessage === 'function') {
|
||||
window.flashMessage(errMsg, 3000, 'error');
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
setFavoUi(wasAlreadyFav);
|
||||
if (typeof window.flashMessage === 'function') {
|
||||
window.flashMessage('Failed to update favorite.', 3000, 'error');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user