Skip to content

Instantly share code, notes, and snippets.

@yuuahp
Created May 20, 2025 14:57
Show Gist options
  • Select an option

  • Save yuuahp/beb5bd433a7fba7aef776b7bacfd0992 to your computer and use it in GitHub Desktop.

Select an option

Save yuuahp/beb5bd433a7fba7aef776b7bacfd0992 to your computer and use it in GitHub Desktop.
// ==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