Created
October 8, 2015 13:42
-
-
Save ultim8k/a9c6f2e98d606caf3f1d to your computer and use it in GitHub Desktop.
Visit Twitter user's Medium blog and vice versa
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
var url = window.location.href; | |
var unRE = /\/\@?(\w+)$/; | |
var userName = ''; | |
var unMatch = url.match(unRE); | |
if (unMatch && unMatch.length) { | |
userName = (unMatch.length > 1) ? unMatch[1] : unMatch[0]; | |
userName = userName.replace('/', '').replace('@', ''); | |
} | |
var mediumMatch = url.match(/medium/); | |
var twitterMatch = url.match(/twitter/); | |
var isMedium = !!(mediumMatch && mediumMatch.length); | |
var isTwitter = !!(twitterMatch && twitterMatch.length); | |
var next = 'https://' + ((!isMedium) ? 'medium.com/@' : 'twitter.com/') + userName; | |
window.location.href = next; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment