From 1b6348fb08acdb59450dda90d66e8a72ffb95a51 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Thu, 19 Jan 2023 15:51:54 +0800 Subject: [PATCH] Fix some links that are actually not user-links --- src/components/status.jsx | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/components/status.jsx b/src/components/status.jsx index e3d524b5..d66369b4 100644 --- a/src/components/status.jsx +++ b/src/components/status.jsx @@ -355,13 +355,10 @@ function Status({ target.tagName.toLowerCase() === 'a' && target.classList.contains('u-url') ) { - e.preventDefault(); - e.stopPropagation(); - const username = ( + const targetText = ( target.querySelector('span') || target - ).innerText - .trim() - .replace(/^@/, ''); + ).innerText.trim(); + const username = targetText.replace(/^@/, ''); const url = target.getAttribute('href'); const mention = mentions.find( (mention) => @@ -370,8 +367,13 @@ function Status({ mention.url === url, ); if (mention) { + e.preventDefault(); + e.stopPropagation(); 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'); states.showAccount = href; } @@ -385,7 +387,9 @@ function Status({ .querySelectorAll('a.u-url[target="_blank"]') .forEach((a) => { // Remove target="_blank" from links - a.removeAttribute('target'); + if (!/http/i.test(a.innerText.trim())) { + a.removeAttribute('target'); + } }); }, }),