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

54 lines
1.7 KiB
JavaScript
Raw Normal View History

2023-04-18 12:11:29 +02:00
function handleQuoteClick(reply, parentCid, threadCid) {
2023-09-16 21:40:23 +02:00
const cid = parentCid ? parentCid : reply.shortCid;
const isMobile = window.innerWidth <= 480;
const postNumberSelector = isMobile ? '.post-number-mobile' : '.post-number-desktop';
2023-04-18 12:11:29 +02:00
2023-09-16 21:40:23 +02:00
if (threadCid && cid === threadCid) {
const highlightedElements = document.querySelectorAll('.highlighted');
2023-04-18 12:11:29 +02:00
2023-09-16 21:40:23 +02:00
highlightedElements.forEach((el) => {
el.classList.remove('highlighted');
});
2023-04-18 15:23:39 +02:00
2023-09-16 21:40:23 +02:00
const opElementSelector = isMobile ? '.op-mobile' : '.op-desktop';
2023-04-19 10:45:42 +02:00
2023-09-16 21:40:23 +02:00
const opElement = [...document.querySelectorAll(opElementSelector)].find((el) => {
const postNumberElement = el.querySelector(postNumberSelector);
return postNumberElement && postNumberElement.innerHTML.includes(threadCid);
});
2023-04-19 10:45:42 +02:00
2023-09-16 21:40:23 +02:00
if (opElement) {
opElement.scrollIntoView({ behavior: 'auto', block: 'start' });
} else {
return;
}
2023-04-18 12:11:29 +02:00
2023-09-16 21:40:23 +02:00
return;
}
2023-04-18 15:23:39 +02:00
2023-09-16 21:40:23 +02:00
const targetElementSelector = isMobile ? '.post-reply-mobile, .op-mobile' : '.post-reply-desktop, .op-desktop';
2023-04-17 18:52:21 +02:00
2023-09-16 21:40:23 +02:00
const targetElement = [...document.querySelectorAll(targetElementSelector)].find((el) => {
const postNumberElement = el.querySelector(postNumberSelector);
return postNumberElement && postNumberElement.innerHTML.includes(cid);
});
2023-04-13 17:08:35 +02:00
2023-09-16 21:40:23 +02:00
if (targetElement) {
const highlightedElements = document.querySelectorAll('.highlighted-click');
highlightedElements.forEach((el) => {
el.classList.remove('highlighted-click');
});
targetElement.scrollIntoView({ behavior: 'auto', block: 'start' });
if (!targetElement.classList.contains('op-mobile') && !targetElement.classList.contains('op-desktop')) {
targetElement.classList.add('highlighted-click');
}
} else {
return;
}
}
export default handleQuoteClick;