Created
January 29, 2012 18:58
-
-
Save GarrettS/1700144 to your computer and use it in GitHub Desktop.
UsurpTCO
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
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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 attributedata-expanded-url
(the corresponding HTML5dataset.expandedUrl
property will not be supported in older browsers)