Fix some links that are actually not user-links

This commit is contained in:
Lim Chee Aun 2023-01-19 15:51:54 +08:00
parent a362a9367f
commit 1b6348fb08

View file

@ -355,13 +355,10 @@ function Status({
target.tagName.toLowerCase() === 'a' && target.tagName.toLowerCase() === 'a' &&
target.classList.contains('u-url') target.classList.contains('u-url')
) { ) {
e.preventDefault(); const targetText = (
e.stopPropagation();
const username = (
target.querySelector('span') || target target.querySelector('span') || target
).innerText ).innerText.trim();
.trim() const username = targetText.replace(/^@/, '');
.replace(/^@/, '');
const url = target.getAttribute('href'); const url = target.getAttribute('href');
const mention = mentions.find( const mention = mentions.find(
(mention) => (mention) =>
@ -370,8 +367,13 @@ function Status({
mention.url === url, mention.url === url,
); );
if (mention) { if (mention) {
e.preventDefault();
e.stopPropagation();
states.showAccount = mention.acct; states.showAccount = mention.acct;
} else { } else if (!/^http/i.test(targetText)) {
console.log('mention not found', targetText);
e.preventDefault();
e.stopPropagation();
const href = target.getAttribute('href'); const href = target.getAttribute('href');
states.showAccount = href; states.showAccount = href;
} }
@ -385,7 +387,9 @@ function Status({
.querySelectorAll('a.u-url[target="_blank"]') .querySelectorAll('a.u-url[target="_blank"]')
.forEach((a) => { .forEach((a) => {
// Remove target="_blank" from links // Remove target="_blank" from links
if (!/http/i.test(a.innerText.trim())) {
a.removeAttribute('target'); a.removeAttribute('target');
}
}); });
}, },
}), }),