Skip to content

Instantly share code, notes, and snippets.

@ultim8k
Created October 8, 2015 13:42
Show Gist options
  • Save ultim8k/a9c6f2e98d606caf3f1d to your computer and use it in GitHub Desktop.
Save ultim8k/a9c6f2e98d606caf3f1d to your computer and use it in GitHub Desktop.
Visit Twitter user's Medium blog and vice versa
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