@@ -185,6 +185,7 @@ const config = {
185185 replaceLogo : true ,
186186 restoreLinkHeadlines : true ,
187187 restoreOtherInteractionLinks : false ,
188+ unwrapTcoLinks : true ,
188189 restoreQuoteTweetsLink : true ,
189190 restoreTweetSource : true ,
190191 retweets : 'separate' ,
@@ -5812,6 +5813,10 @@ function onTimelineChange($timeline, page, options = {}) {
58125813 if ( ! hideItem && config . restoreLinkHeadlines ) {
58135814 restoreLinkHeadline ( $tweet )
58145815 }
5816+
5817+ if ( ! hideItem ) {
5818+ unwrapTcoLinks ( $tweet )
5819+ }
58155820 }
58165821 else if ( isOnNotificationsTimeline ) {
58175822 /** @type {?import("./types").NotificationType } */
@@ -6046,6 +6051,10 @@ function onIndividualTweetTimelineChange($timeline, options) {
60466051 if ( ! hideItem && config . restoreLinkHeadlines ) {
60476052 restoreLinkHeadline ( $tweet )
60486053 }
6054+
6055+ if ( ! hideItem ) {
6056+ unwrapTcoLinks ( $tweet )
6057+ }
60496058 }
60506059 else {
60516060 let $article = $item . querySelector ( 'article' )
@@ -6513,6 +6522,41 @@ function restoreLinkHeadline($tweet) {
65136522 }
65146523}
65156524
6525+ /**
6526+ * Unwraps t.co shortened links to show/use the actual destination URL.
6527+ * @param {HTMLElement } $tweet
6528+ */
6529+ function unwrapTcoLinks ( $tweet ) {
6530+ if ( ! config . unwrapTcoLinks ) return
6531+
6532+ let $links = $tweet . querySelectorAll ( 'a[href^="https://t.co/"]' )
6533+ for ( let $link of $links ) {
6534+ if ( $link . dataset . tcoUnwrapped ) continue
6535+
6536+ let expandedUrl = null
6537+ let textContent = $link . textContent ?. trim ( )
6538+
6539+ if ( textContent ) {
6540+ // Remove ellipsis that Twitter adds for truncation
6541+ textContent = textContent . replace ( / … $ / , '' ) . trim ( )
6542+
6543+ if ( textContent . startsWith ( 'http://' ) || textContent . startsWith ( 'https://' ) ) {
6544+ expandedUrl = textContent
6545+ } else if ( textContent . includes ( '.' ) && ! textContent . includes ( ' ' ) ) {
6546+ expandedUrl = 'https://' + textContent
6547+ }
6548+ }
6549+
6550+ if ( expandedUrl ) {
6551+ $link . dataset . originalTco = $link . href
6552+ $link . href = expandedUrl
6553+ $link . dataset . tcoUnwrapped = 'true'
6554+ } else {
6555+ $link . dataset . tcoUnwrapped = 'attempted'
6556+ }
6557+ }
6558+ }
6559+
65166560/**
65176561 * @param {HTMLElement } $focusedTweet
65186562 */
0 commit comments