Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
GitHub Pages Switcher Bookmarklet
/**
* 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
You can’t perform that action at this time.