Skip to content

Instantly share code, notes, and snippets.

@GarrettS
Created January 29, 2012 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GarrettS/1700144 to your computer and use it in GitHub Desktop.
Save GarrettS/1700144 to your computer and use it in GitHub Desktop.
UsurpTCO
function tcoToLinkTitleURL(ev) {
var target = ev.target;
if(/^(http(?:s?):)?\/\/t.co\//.test(target.href) && /^(http(?:s?):)?\/\//.test(target.title)) {
target.href = target.title;
}
}
if(location.hostname == "twitter.com") {
document.addEventListener("mousedown", tcoToLinkTitleURL, true);
}
@GarrettS
Copy link
Author

It's clearer to test the host property of the link instead of regex. Also was reported that using target.title did not work in Opera, and seems more reliable to use the attribute data-expanded-url (the corresponding HTML5 dataset.expandedUrl property will not be supported in older browsers)

javascript:alert(document.querySelector("[data-expanded-url]").dataset.expandedUrl)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment