Skip to content

Commit 55b9553

Browse files
committed
address PR comments
1 parent 57d8053 commit 55b9553

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

src/ext/twitter.tsx

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ async function handleNewNode(
124124
);
125125
if (linkPreview) {
126126
anchor = linkPreview.anchor;
127-
container?.remove();
127+
container && container.remove();
128128
container = linkPreview.card.parentElement as HTMLElement;
129129
} else {
130130
if (container) {
@@ -137,7 +137,7 @@ async function handleNewNode(
137137
}
138138
}
139139

140-
if (!anchor) return;
140+
if (!anchor || !container) return;
141141

142142
const shortenedUrl = anchor.href;
143143
const actionUrl = await resolveTwitterShortenedUrl(shortenedUrl);
@@ -188,7 +188,7 @@ async function handleNewNode(
188188
return;
189189
}
190190

191-
addMargin(container)?.replaceChildren(
191+
addMargin(container).replaceChildren(
192192
createAction({
193193
originalUrl: actionUrl,
194194
action,
@@ -259,37 +259,39 @@ function findElementByTestId(element: Element, testId: string) {
259259

260260
function findContainerInTweet(element: Element, searchUp?: boolean) {
261261
const message = searchUp
262-
? element.closest(`[data-testid="tweet"]`) ??
263-
element.closest(`[data-testid="messageEntry"]`)
264-
: findElementByTestId(element, 'tweet') ??
265-
findElementByTestId(element, 'messageEntry');
262+
? (element.closest(`[data-testid="tweet"]`) ??
263+
element.closest(`[data-testid="messageEntry"]`))
264+
: (findElementByTestId(element, 'tweet') ??
265+
findElementByTestId(element, 'messageEntry'));
266266

267267
if (message) {
268268
return message.querySelector('.dialect-wrapper') as HTMLElement;
269269
}
270+
return null;
270271
}
271272

272273
function findLinkPreview(element: Element) {
273274
const card = findElementByTestId(element, 'card.wrapper');
274-
if (card) {
275-
const linkPreview = card.children[0];
276-
if (linkPreview) {
277-
const anchor = linkPreview.children[0] as HTMLAnchorElement;
278-
return { anchor, card };
279-
}
275+
if (!card) {
276+
return null;
280277
}
278+
279+
const anchor = card.children[0]?.children[0] as HTMLAnchorElement;
280+
281+
return anchor ? { anchor, card } : null;
281282
}
282283
function findLastLinkInText(element: Element) {
283284
const tweetText = findElementByTestId(element, 'tweetText');
284285
if (!tweetText) {
285-
return;
286+
return null;
286287
}
287288

288289
const links = tweetText.getElementsByTagName('a');
289290
if (links.length > 0) {
290291
const anchor = links[links.length - 1] as HTMLAnchorElement;
291292
return { anchor, tweetText };
292293
}
294+
return null;
293295
}
294296

295297
function getContainerForLink(tweetText: Element) {
@@ -305,7 +307,7 @@ function getContainerForLink(tweetText: Element) {
305307
return root;
306308
}
307309

308-
function addMargin(element?: HTMLElement) {
310+
function addMargin(element: HTMLElement) {
309311
if (element && element.classList.contains('dialect-wrapper')) {
310312
element.style.marginTop = '12px';
311313
if (element.classList.contains('dialect-dm')) {

src/ui/ActionLayout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export const ActionLayout = ({
115115
<a
116116
href={websiteUrl}
117117
target="_blank"
118-
className="group -mt-1 inline-flex items-center truncate text-subtext hover:cursor-pointer"
118+
className="group inline-flex items-center truncate text-subtext hover:cursor-pointer"
119119
rel="noopener noreferrer"
120120
>
121121
<LinkIcon className="mr-2 text-icon-primary transition-colors group-hover:text-icon-primary-hover motion-reduce:transition-none" />
@@ -125,7 +125,7 @@ export const ActionLayout = ({
125125
</a>
126126
)}
127127
{websiteText && !websiteUrl && (
128-
<span className="-mt-1 inline-flex items-center truncate text-subtext text-text-link">
128+
<span className="inline-flex items-center truncate text-subtext text-text-link">
129129
{websiteText}
130130
</span>
131131
)}

0 commit comments

Comments
 (0)