New feature: hashtag stuffing collapsing

This commit is contained in:
Lim Chee Aun 2023-04-20 18:56:22 +08:00
parent 6fb68d34c5
commit 7a7693ae52
2 changed files with 49 additions and 0 deletions

View file

@ -686,6 +686,26 @@ body:has(#modal-container .carousel) .status .media img:hover {
background-blend-mode: multiply;
}
.status:not(.large) .hashtag-stuffing {
opacity: 0.75;
transition: opacity 0.2s ease-in-out;
}
.status:not(.large) .hashtag-stuffing:is(:hover, :focus, :focus-within) {
opacity: 1;
}
.status:not(.large) .hashtag-stuffing {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
max-width: 100%;
}
.status:not(.large) .hashtag-stuffing:first-child {
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
white-space: normal;
}
.carousel-item {
position: relative;
}

View file

@ -136,6 +136,35 @@ function enhanceContent(content, opts = {}) {
node.replaceWith(...nodes);
});
// HASHTAG STUFFING
// ================
// Get the <p> that contains a lot of hashtags, add a class to it
const hashtagStuffedParagraph = Array.from(dom.querySelectorAll('p')).find(
(p) => {
for (let i = 0; i < p.childNodes.length; i++) {
const node = p.childNodes[i];
if (node.nodeType === Node.TEXT_NODE) {
const text = node.textContent.trim();
if (text !== '') {
return false;
}
} else if (node.tagName === 'A') {
const linkText = node.textContent.trim();
if (!linkText || !linkText.startsWith('#')) {
return false;
}
} else {
return false;
}
}
return true;
},
);
if (hashtagStuffedParagraph) {
hashtagStuffedParagraph.classList.add('hashtag-stuffing');
}
if (postEnhanceDOM) {
postEnhanceDOM(dom); // mutate dom
}