fix set rating on item view
This commit is contained in:
@@ -38,11 +38,23 @@ window.cancelAnimFrame = (function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
window.getCurrentItemId = () => {
|
window.getCurrentItemId = () => {
|
||||||
|
const idEl = document.querySelector('a.id-link[data-item-id], #a_toggle[data-item-id], #a_favo[data-item-id], #comments-container[data-item-id], [data-item-id]');
|
||||||
|
if (idEl && idEl.dataset && idEl.dataset.itemId) {
|
||||||
|
const parsed = parseInt(idEl.dataset.itemId, 10);
|
||||||
|
if (!isNaN(parsed)) return String(parsed);
|
||||||
|
}
|
||||||
const path = window.location.pathname;
|
const path = window.location.pathname;
|
||||||
// Explicitly ignore admin/mod/settings paths to avoid false positives from user IDs, etc.
|
// Explicitly ignore admin/mod/settings paths to avoid false positives from user IDs, etc.
|
||||||
if (path.includes('/admin/') || path.includes('/mod/') || path.includes('/settings') || path.includes('/user/')) return null;
|
if (path.includes('/admin/') || path.includes('/mod/') || path.includes('/settings') || path.includes('/user/')) return null;
|
||||||
const match = path.match(/\/(\d+)\/?$/);
|
const match = path.match(/\/(\d+)\/?$/);
|
||||||
return match ? match[1] : null;
|
if (match) return match[1];
|
||||||
|
|
||||||
|
const idLink = document.querySelector('a.id-link');
|
||||||
|
if (idLink && idLink.innerText) {
|
||||||
|
const parsed = parseInt(idLink.innerText.trim(), 10);
|
||||||
|
if (!isNaN(parsed)) return String(parsed);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
// OS and Browser detection for CSS targeting
|
// OS and Browser detection for CSS targeting
|
||||||
@@ -4369,9 +4381,10 @@ window.cancelAnimFrame = (function () {
|
|||||||
} else if (target.closest('button#a_toggle')) {
|
} else if (target.closest('button#a_toggle')) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const toggleBtn = target.closest('button#a_toggle');
|
const toggleBtn = target.closest('button#a_toggle');
|
||||||
const idLink = document.querySelector("a.id-link");
|
const itemIdStr = toggleBtn.dataset.itemId || window.getCurrentItemId();
|
||||||
if (!idLink) return;
|
if (!itemIdStr) return;
|
||||||
const postid = +idLink.innerText;
|
const postid = parseInt(itemIdStr, 10);
|
||||||
|
if (isNaN(postid)) return;
|
||||||
|
|
||||||
// Determine current rating
|
// Determine current rating
|
||||||
let currentRating = 'sfw';
|
let currentRating = 'sfw';
|
||||||
@@ -4475,8 +4488,8 @@ window.cancelAnimFrame = (function () {
|
|||||||
toggleBtn._activeRequestsCount = Math.max(0, (toggleBtn._activeRequestsCount || 1) - 1);
|
toggleBtn._activeRequestsCount = Math.max(0, (toggleBtn._activeRequestsCount || 1) - 1);
|
||||||
|
|
||||||
// Verify we are still on the same post (prevent dynamic/PJAX page leaks)
|
// Verify we are still on the same post (prevent dynamic/PJAX page leaks)
|
||||||
const activeIdLink = document.querySelector("a.id-link");
|
const currentIdStr = window.getCurrentItemId();
|
||||||
const currentPostId = activeIdLink ? +activeIdLink.innerText : null;
|
const currentPostId = currentIdStr ? parseInt(currentIdStr, 10) : null;
|
||||||
if (currentPostId !== postid) return;
|
if (currentPostId !== postid) return;
|
||||||
|
|
||||||
if (toggleBtn._lastCycleReqId !== reqId) return; // ignore stale responses
|
if (toggleBtn._lastCycleReqId !== reqId) return; // ignore stale responses
|
||||||
@@ -4502,8 +4515,8 @@ window.cancelAnimFrame = (function () {
|
|||||||
toggleBtn._activeRequestsCount = Math.max(0, (toggleBtn._activeRequestsCount || 1) - 1);
|
toggleBtn._activeRequestsCount = Math.max(0, (toggleBtn._activeRequestsCount || 1) - 1);
|
||||||
|
|
||||||
// Verify we are still on the same post (prevent dynamic/PJAX page leaks)
|
// Verify we are still on the same post (prevent dynamic/PJAX page leaks)
|
||||||
const activeIdLink = document.querySelector("a.id-link");
|
const currentIdStr = window.getCurrentItemId();
|
||||||
const currentPostId = activeIdLink ? +activeIdLink.innerText : null;
|
const currentPostId = currentIdStr ? parseInt(currentIdStr, 10) : null;
|
||||||
if (currentPostId !== postid) return;
|
if (currentPostId !== postid) return;
|
||||||
|
|
||||||
if (toggleBtn._lastCycleReqId !== reqId) return;
|
if (toggleBtn._lastCycleReqId !== reqId) return;
|
||||||
@@ -8685,8 +8698,8 @@ class NotificationSystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if we are currently viewing this item
|
// Check if we are currently viewing this item
|
||||||
const idLink = document.querySelector('.id-link');
|
const currentIdStr = window.getCurrentItemId();
|
||||||
const currentId = idLink ? parseInt(idLink.innerText) : null;
|
const currentId = currentIdStr ? parseInt(currentIdStr, 10) : null;
|
||||||
|
|
||||||
window.f0ckDebug(`[NotificationSystem] Processing tag update for #${data.item_id}. Current view is #${currentId}`);
|
window.f0ckDebug(`[NotificationSystem] Processing tag update for #${data.item_id}. Current view is #${currentId}`);
|
||||||
|
|
||||||
@@ -8768,8 +8781,8 @@ class NotificationSystem {
|
|||||||
if (!data || !data.item_id) return;
|
if (!data || !data.item_id) return;
|
||||||
|
|
||||||
// Check if we are currently viewing this item
|
// Check if we are currently viewing this item
|
||||||
const idLink = document.querySelector('#main .id-link');
|
const currentIdStr = window.getCurrentItemId();
|
||||||
if (!idLink || parseInt(idLink.innerText) !== parseInt(data.item_id)) return;
|
if (!currentIdStr || parseInt(currentIdStr, 10) !== parseInt(data.item_id, 10)) return;
|
||||||
|
|
||||||
const favsContainer = document.querySelector('#favs');
|
const favsContainer = document.querySelector('#favs');
|
||||||
if (!favsContainer) return;
|
if (!favsContainer) return;
|
||||||
|
|||||||
@@ -192,7 +192,7 @@
|
|||||||
<i class="fa-solid fa-plus"></i>
|
<i class="fa-solid fa-plus"></i>
|
||||||
</a>
|
</a>
|
||||||
@if(can_manage_item)
|
@if(can_manage_item)
|
||||||
<button class="rating-btn {{ item.is_nsfl ? 'is-nsfl' : (item.is_nsfw ? 'is-nsfw' : (item.is_sfw ? 'is-sfw' : 'is-untagged')) }}" id="a_toggle" title="Toggle Rating"><i class="fa-solid fa-arrow-right-arrow-left"></i></button>
|
<button class="rating-btn {{ item.is_nsfl ? 'is-nsfl' : (item.is_nsfw ? 'is-nsfw' : (item.is_sfw ? 'is-sfw' : 'is-untagged')) }}" id="a_toggle" data-item-id="{{ item.id }}" title="Toggle Rating"><i class="fa-solid fa-arrow-right-arrow-left"></i></button>
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
<i class="fa-solid fa-plus"></i>
|
<i class="fa-solid fa-plus"></i>
|
||||||
</a>
|
</a>
|
||||||
@if(can_manage_item)
|
@if(can_manage_item)
|
||||||
<button class="rating-btn {{ item_rating_class }}" id="a_toggle" title="Toggle Rating"><i class="fa-solid fa-arrow-right-arrow-left"></i></button>
|
<button class="rating-btn {{ item_rating_class }}" id="a_toggle" data-item-id="{{ item.id }}" title="Toggle Rating"><i class="fa-solid fa-arrow-right-arrow-left"></i></button>
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
|
|||||||
Reference in New Issue
Block a user