Created
May 20, 2025 14:57
-
-
Save yuuahp/beb5bd433a7fba7aef776b7bacfd0992 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name No t.co Redirects | |
| // @namespace http://tampermonkey.net/ | |
| // @version 1.0 | |
| // @description Skip t.co redirects on X/Twitter and jump directly to the actual website. | |
| // @author yuua | |
| // @match https://x.com/* | |
| // @icon https://www.google.com/s2/favicons?sz=64&domain=x.com | |
| // @grant none | |
| // ==/UserScript== | |
| (function() { | |
| 'use strict'; | |
| document.addEventListener('click', function (e) { | |
| const a = e.target.closest('a[href]'); | |
| if (!a) return; | |
| const regex = /^https:\/\/t\.co\/[a-zA-Z0-9]+$/; | |
| const href = a.getAttribute('href'); | |
| if (regex.test(href)) { | |
| e.preventDefault(); | |
| let url = a.textContent.replace(/\s+/g, '').trim(); | |
| const possibleTruncate = a.children[a.children.length - 1] | |
| if (possibleTruncate.textContent === "…") { | |
| url = url.slice(0, -1); | |
| } | |
| try { | |
| const parsedUrl = new URL(url); | |
| console.log("[NO T.CO] Jumping to", url) | |
| window.location.href = parsedUrl.href; | |
| } catch (err) { | |
| console.warn('[NO T.CO] Failed to parse URL:', url); | |
| } | |
| } | |
| }); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment