Skip to content

Instantly share code, notes, and snippets.

@banterability
Created January 11, 2011 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save banterability/775137 to your computer and use it in GitHub Desktop.
Save banterability/775137 to your computer and use it in GitHub Desktop.
Bookmarklet to switch between GitHub code & documentation in GitHub pages
h = location.href
docStr = /^http:\/\/(\w*).github.com\/(\w*)(?:\/.*)?/
codeStr = /^https?:\/\/github.com\/(\w*)\/(\w*)(?:\/.*)?/
docTmp = "http://$user.github.com/$proj"
codeTmp = "https://github.com/$user/$proj"
isDoc = h.match(docStr)
isCode = h.match(codeStr)
redirect = (loc) ->
location.href = loc
true
if isDoc
user = isDoc[1]
proj = isDoc[2]
redirect(codeTmp.replace("$user", user).replace("$proj", proj))
else if isCode
user = isCode[1]
proj = isCode[2]
redirect(docTmp.replace("$user", user).replace("$proj", proj))
else
false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment