fix set rating on item view
This commit is contained in:
@@ -38,11 +38,23 @@ window.cancelAnimFrame = (function () {
|
||||
};
|
||||
|
||||
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;
|
||||
// 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;
|
||||
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
|
||||
@@ -4369,9 +4381,10 @@ window.cancelAnimFrame = (function () {
|
||||
} else if (target.closest('button#a_toggle')) {
|
||||
e.preventDefault();
|
||||
const toggleBtn = target.closest('button#a_toggle');
|
||||
const idLink = document.querySelector("a.id-link");
|
||||
if (!idLink) return;
|
||||
const postid = +idLink.innerText;
|
||||
const itemIdStr = toggleBtn.dataset.itemId || window.getCurrentItemId();
|
||||
if (!itemIdStr) return;
|
||||
const postid = parseInt(itemIdStr, 10);
|
||||
if (isNaN(postid)) return;
|
||||
|
||||
// Determine current rating
|
||||
let currentRating = 'sfw';
|
||||
@@ -4475,8 +4488,8 @@ window.cancelAnimFrame = (function () {
|
||||
toggleBtn._activeRequestsCount = Math.max(0, (toggleBtn._activeRequestsCount || 1) - 1);
|
||||
|
||||
// Verify we are still on the same post (prevent dynamic/PJAX page leaks)
|
||||
const activeIdLink = document.querySelector("a.id-link");
|
||||
const currentPostId = activeIdLink ? +activeIdLink.innerText : null;
|
||||
const currentIdStr = window.getCurrentItemId();
|
||||
const currentPostId = currentIdStr ? parseInt(currentIdStr, 10) : null;
|
||||
if (currentPostId !== postid) return;
|
||||
|
||||
if (toggleBtn._lastCycleReqId !== reqId) return; // ignore stale responses
|
||||
@@ -4502,8 +4515,8 @@ window.cancelAnimFrame = (function () {
|
||||
toggleBtn._activeRequestsCount = Math.max(0, (toggleBtn._activeRequestsCount || 1) - 1);
|
||||
|
||||
// Verify we are still on the same post (prevent dynamic/PJAX page leaks)
|
||||
const activeIdLink = document.querySelector("a.id-link");
|
||||
const currentPostId = activeIdLink ? +activeIdLink.innerText : null;
|
||||
const currentIdStr = window.getCurrentItemId();
|
||||
const currentPostId = currentIdStr ? parseInt(currentIdStr, 10) : null;
|
||||
if (currentPostId !== postid) return;
|
||||
|
||||
if (toggleBtn._lastCycleReqId !== reqId) return;
|
||||
@@ -8685,8 +8698,8 @@ class NotificationSystem {
|
||||
}
|
||||
|
||||
// Check if we are currently viewing this item
|
||||
const idLink = document.querySelector('.id-link');
|
||||
const currentId = idLink ? parseInt(idLink.innerText) : null;
|
||||
const currentIdStr = window.getCurrentItemId();
|
||||
const currentId = currentIdStr ? parseInt(currentIdStr, 10) : null;
|
||||
|
||||
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;
|
||||
|
||||
// Check if we are currently viewing this item
|
||||
const idLink = document.querySelector('#main .id-link');
|
||||
if (!idLink || parseInt(idLink.innerText) !== parseInt(data.item_id)) return;
|
||||
const currentIdStr = window.getCurrentItemId();
|
||||
if (!currentIdStr || parseInt(currentIdStr, 10) !== parseInt(data.item_id, 10)) return;
|
||||
|
||||
const favsContainer = document.querySelector('#favs');
|
||||
if (!favsContainer) return;
|
||||
|
||||
Reference in New Issue
Block a user