Skip to content
This repository was archived by the owner on Aug 27, 2025. It is now read-only.

Commit 392d472

Browse files
committed
fix: tweet links
1 parent 226a3b9 commit 392d472

1 file changed

Lines changed: 29 additions & 11 deletions

File tree

src/content-script/hooks/twitter.ts

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -298,22 +298,13 @@ class TwitterHook {
298298

299299
// All tweets
300300
const allTweets = document.querySelectorAll('[data-testid="tweet"]');
301-
Array.from(allTweets).forEach((tweet) => {
301+
allTweets.forEach((tweet) => {
302302
if (tweet && !tweet.querySelector('[cssc="sync-status"]')) {
303303
// Get link
304304
const tweetPath = tweet.querySelector('time')?.parentElement?.getAttribute('href');
305305
if (tweetPath && tweetPath.includes(`/${username}/status/`)) {
306306
const link = `https://twitter.com${tweetPath}`;
307-
// Get tweet data
308-
const tweetText = tweet.querySelector('[data-testid="tweetText"]')?.textContent || '';
309-
const tweetMedia = [
310-
...Array.from(
311-
tweet.querySelectorAll(`a[href^="/${username}/status/"] [data-testid="tweetPhoto"] img`),
312-
).map((img) => img.getAttribute('src')),
313-
...Array.from(tweet.querySelectorAll('[data-testid="videoPlayer"] video')).map((video) =>
314-
video.getAttribute('poster'),
315-
),
316-
].filter((url) => !!url) as string[];
307+
317308
const syncStatus = createApp(SyncStatus, {
318309
link: link,
319310
getNote: async () => {
@@ -335,6 +326,33 @@ class TwitterHook {
335326
}
336327
},
337328
postNote: async () => {
329+
// Get tweet data
330+
const tweetTextNode = tweet.querySelector('[data-testid="tweetText"]');
331+
let tweetText = tweetTextNode?.textContent || '';
332+
const tweetTextAnchors = tweetTextNode?.querySelectorAll('a');
333+
// Get full url for all links
334+
const tweetTextLinks = tweetTextAnchors
335+
? Array.from(tweetTextAnchors)
336+
.map((a) => a.textContent)
337+
.filter((link) => !!link)
338+
: [];
339+
340+
// Remove final '…'
341+
tweetTextLinks.forEach((link) => {
342+
tweetText = tweetText.replace(link!, link!.replace('…', ''));
343+
});
344+
345+
const tweetMedia = [
346+
...Array.from(
347+
tweet.querySelectorAll(
348+
`a[href^="/${username}/status/"] [data-testid="tweetPhoto"] img`,
349+
),
350+
).map((img) => img.getAttribute('src')),
351+
...Array.from(tweet.querySelectorAll('[data-testid="videoPlayer"] video')).map(
352+
(video) => video.getAttribute('poster'),
353+
),
354+
].filter((url) => !!url) as string[];
355+
338356
const note = {
339357
tags: ['CrossSync', 'Twitter'],
340358
applications: ['CrossSync', 'Twitter'],

0 commit comments

Comments
 (0)