mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-02-09 01:26:24 +01:00
Differentiate username displays
When there're mentions of multiple same username + different instances in a post
This commit is contained in:
parent
39d96f22a0
commit
d4dce2fa45
1 changed files with 15 additions and 4 deletions
|
@ -33,15 +33,26 @@ function enhanceContent(content, opts = {}) {
|
||||||
|
|
||||||
// Spanify un-spanned mentions
|
// Spanify un-spanned mentions
|
||||||
if (hasLink) {
|
if (hasLink) {
|
||||||
const notMentionLinks = Array.from(dom.querySelectorAll('a[href]'));
|
const links = Array.from(dom.querySelectorAll('a[href]'));
|
||||||
notMentionLinks.forEach((link) => {
|
const usernames = [];
|
||||||
|
links.forEach((link) => {
|
||||||
const text = link.innerText.trim();
|
const text = link.innerText.trim();
|
||||||
const hasChildren = link.querySelector('*');
|
const hasChildren = link.querySelector('*');
|
||||||
// If text looks like @username@domain, then it's a mention
|
// If text looks like @username@domain, then it's a mention
|
||||||
if (/^@[^@]+(@[^@]+)?$/g.test(text)) {
|
if (/^@[^@]+(@[^@]+)?$/g.test(text)) {
|
||||||
// Only show @username
|
// Only show @username
|
||||||
const username = text.split('@')[1];
|
const [_, username, domain] = text.split('@');
|
||||||
if (!hasChildren) link.innerHTML = `@<span>${username}</span>`;
|
if (!hasChildren) {
|
||||||
|
if (
|
||||||
|
!usernames.find(([u]) => u === username) ||
|
||||||
|
usernames.find(([u, d]) => u === username && d === domain)
|
||||||
|
) {
|
||||||
|
link.innerHTML = `@<span>${username}</span>`;
|
||||||
|
usernames.push([username, domain]);
|
||||||
|
} else {
|
||||||
|
link.innerHTML = `@<span>${username}@${domain}</span>`;
|
||||||
|
}
|
||||||
|
}
|
||||||
link.classList.add('mention');
|
link.classList.add('mention');
|
||||||
}
|
}
|
||||||
// If text looks like #hashtag, then it's a hashtag
|
// If text looks like #hashtag, then it's a hashtag
|
||||||
|
|
Loading…
Reference in a new issue