mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fixed quote scroll to start of match
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
function handleQuoteClick(reply, parentCid, threadCid) {
|
||||
const cid = parentCid ? parentCid : reply.shortCid;
|
||||
const isMobile = window.innerWidth <= 480;
|
||||
const postNumberSelector = isMobile ? '.post-number-mobile' : '.post-number-desktop';
|
||||
|
||||
if (threadCid && cid === threadCid) {
|
||||
const highlightedElements = document.querySelectorAll('.highlighted');
|
||||
@@ -9,11 +10,24 @@ function handleQuoteClick(reply, parentCid, threadCid) {
|
||||
el.classList.remove('highlighted');
|
||||
});
|
||||
|
||||
const opElementSelector = isMobile ? '.op-mobile' : '.op-desktop';
|
||||
|
||||
const opElement = [...document.querySelectorAll(opElementSelector)]
|
||||
.find(el => {
|
||||
const postNumberElement = el.querySelector(postNumberSelector);
|
||||
return postNumberElement && postNumberElement.innerHTML.includes(threadCid);
|
||||
});
|
||||
|
||||
if (opElement) {
|
||||
opElement.scrollIntoView({ behavior: "auto", block: "start" });
|
||||
} else {
|
||||
console.log('Could not find OP element');
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const targetElementSelector = isMobile ? '.post-reply-mobile' : '.post-reply-desktop';
|
||||
const postNumberSelector = isMobile ? '.post-number-mobile' : '.post-number-desktop';
|
||||
const targetElementSelector = isMobile ? '.post-reply-mobile, .op-mobile' : '.post-reply-desktop, .op-desktop';
|
||||
|
||||
const targetElement = [...document.querySelectorAll(targetElementSelector)]
|
||||
.find(el => {
|
||||
@@ -28,8 +42,11 @@ function handleQuoteClick(reply, parentCid, threadCid) {
|
||||
el.classList.remove('highlighted');
|
||||
});
|
||||
|
||||
targetElement.scrollIntoView({ behavior: "auto", block: "center" });
|
||||
targetElement.classList.add('highlighted');
|
||||
targetElement.scrollIntoView({ behavior: "auto", block: "start" });
|
||||
|
||||
if (!targetElement.classList.contains('op-mobile') && !targetElement.classList.contains('op-desktop')) {
|
||||
targetElement.classList.add('highlighted');
|
||||
}
|
||||
|
||||
} else {
|
||||
console.log('Could not find target element');
|
||||
|
||||
Reference in New Issue
Block a user