Files
5chan/src/utils/handleQuoteClick.js
T

39 lines
1.2 KiB
JavaScript
Raw Normal View History

2023-04-18 12:11:29 +02:00
function handleQuoteClick(reply, parentCid, threadCid) {
2023-04-17 18:52:21 +02:00
const cid = parentCid ? parentCid : reply.shortCid;
2023-04-18 15:23:39 +02:00
const isMobile = window.innerWidth <= 480;
2023-04-18 12:11:29 +02:00
if (threadCid && cid === threadCid) {
const highlightedElements = document.querySelectorAll('.highlighted');
highlightedElements.forEach(el => {
el.classList.remove('highlighted');
});
2023-04-18 15:23:39 +02:00
2023-04-18 12:11:29 +02:00
return;
}
2023-04-18 15:23:39 +02:00
const targetElementSelector = isMobile ? '.post-reply-mobile' : '.post-reply-desktop';
const postNumberSelector = isMobile ? '.post-number-mobile' : '.post-number-desktop';
const targetElement = [...document.querySelectorAll(targetElementSelector)]
2023-04-17 18:52:21 +02:00
.find(el => {
2023-04-18 15:23:39 +02:00
const postNumberElement = el.querySelector(postNumberSelector);
2023-04-17 18:52:21 +02:00
return postNumberElement && postNumberElement.innerHTML.includes(cid);
});
2023-04-13 17:08:35 +02:00
if (targetElement) {
2023-04-17 18:52:21 +02:00
const highlightedElements = document.querySelectorAll('.highlighted');
2023-04-18 15:23:39 +02:00
2023-04-17 18:52:21 +02:00
highlightedElements.forEach(el => {
el.classList.remove('highlighted');
});
targetElement.scrollIntoView({ behavior: "auto", block: "center" });
targetElement.classList.add('highlighted');
2023-04-13 17:08:35 +02:00
} else {
console.log('Could not find target element');
}
};
export default handleQuoteClick;