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

39 lines
1.2 KiB
JavaScript
Raw Normal View History

2023-04-20 17:20:26 +02:00
function handleAddressClick(shortAddress) {
2023-09-16 21:40:23 +02:00
const isMobile = window.innerWidth <= 480;
const addressSelector = isMobile ? '.address-mobile' : '.address-desktop';
const postReplySelector = isMobile ? '.post-reply-mobile' : '.post-reply-desktop';
const opSelector = isMobile ? '.op-mobile' : '.op-desktop';
2023-04-20 17:20:26 +02:00
2023-09-16 21:40:23 +02:00
const matchingElements = [...document.querySelectorAll(postReplySelector + ',' + opSelector)].filter((el) => {
const addressElement = el.querySelector(addressSelector);
return addressElement && addressElement.textContent.includes(shortAddress);
});
2023-04-20 17:20:26 +02:00
2023-09-16 21:40:23 +02:00
if (matchingElements.length === 0) {
return;
}
2023-04-20 17:20:26 +02:00
2023-09-16 21:40:23 +02:00
const highlightedElements = document.querySelectorAll('.highlighted-address');
2023-04-20 17:20:26 +02:00
2023-09-16 21:40:23 +02:00
let allHighlighted = true;
matchingElements.forEach((el) => {
if (!el.classList.contains('highlighted-address')) {
allHighlighted = false;
}
});
2023-06-21 09:57:00 +02:00
2023-09-16 21:40:23 +02:00
highlightedElements.forEach((el) => {
el.classList.remove('highlighted-address');
});
2023-06-21 09:57:00 +02:00
2023-09-16 21:40:23 +02:00
if (!allHighlighted) {
matchingElements.forEach((el) => {
if (!el.classList.contains('op-mobile') && !el.classList.contains('op-desktop')) {
el.classList.add('highlighted-address');
}
});
}
2023-04-20 17:20:26 +02:00
}
2023-09-16 21:40:23 +02:00
export default handleAddressClick;