Last active
February 23, 2017 11:11
-
-
Save thomasjbradley/5f6a9fbe9a8847c5299d to your computer and use it in GitHub Desktop.
GitHub Pages Switcher Bookmarklet
This file contains 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
/** | |
* Detects the GitHub URL and redirects: | |
* - From Repo to Pages | |
* - or from Pages to Repo | |
*/ | |
javascript:(function () { | |
var url = document.location.href, | |
username, | |
repo, | |
finalUrl | |
; | |
if (!url.match(/github/)) { return; } | |
url = url.replace(/https?\:\/\//, ''); | |
if (url.match(/github\.io/)) { | |
username = url.match(/.+\.github/)[0].replace(/\.github/, ''); | |
repo = url.match(/\.github\.io\/([^\/]+)/)[1]; | |
finalUrl = 'https://github.com/' + username + '/' + repo; | |
} else { | |
username = url.match(/github.com\/([^\/]+)/)[1]; | |
repo = url.match(new RegExp('github\.com\/' + username +'/([^\/]+)'))[1]; | |
finalUrl = 'http://' + username + '.github.io/' + repo; | |
} | |
window.open(finalUrl); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment