mirror of
https://github.com/cheeaun/phanpy.git
synced 2024-11-24 10:15:37 +03:00
New feature: hashtag stuffing collapsing
This commit is contained in:
parent
6fb68d34c5
commit
7a7693ae52
2 changed files with 49 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue