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

35 lines
997 B
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 12:11:29 +02:00
if (threadCid && cid === threadCid) {
const highlightedElements = document.querySelectorAll('.highlighted');
highlightedElements.forEach(el => {
el.classList.remove('highlighted');
});
return;
}
2023-04-13 17:08:35 +02:00
const targetElement = [...document.querySelectorAll('.post-reply')]
2023-04-17 18:52:21 +02:00
.find(el => {
const postNumberElement = el.querySelector('.post-number');
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');
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;