Last active
December 9, 2016 20:52
-
-
Save timwco/aaf75cdb3e2ca0481cb0 to your computer and use it in GitHub Desktop.
Github to GH Pages to Github 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
/* | |
Takes you from a Github Repo URL to the GH Pages version on github.io | |
*/ | |
javascript: (function() { | |
var s = location.href; | |
var r = /^((http[s]?|ftp):\/)?\/?([^:\/\s]+)((\/\w+)*\/)([\w\-\.]+[^#?\s]+)(.*)?(#[\w\-]+)?$/g; | |
location.href = s.replace(r, "http:/$5.github.io/$6"); | |
})(); | |
// URL Encoded Version (for use as a bookmarklet) | |
javascript:(function()%7Bvar s%3Dlocation.href%3Bvar r%3D/%5E((http%5Bs%5D%3F%7Cftp):%5C/)%3F%5C/%3F(%5B%5E:%5C/%5Cs%5D%2B)((%5C/%5Cw%2B)*%5C/)(%5B%5Cw%5C-%5C.%5D%2B%5B%5E%23%3F%5Cs%5D%2B)(.*)%3F(%23%5B%5Cw%5C-%5D%2B)%3F%24/g%3Blocation.href%3Ds.replace(r,"http:/%245.github.io/%246")%3B%7D)()%3B | |
/* | |
Takes you from a GH Pages URL to the Github Repo | |
*/ | |
javascript: (function() { | |
var s = location.href; | |
var r = /^((http[s]?|ftp):\/)?\/?([^:\.\s]+).([^:\.\s]+).([^:\/\s]+)((\/\w+)*\/)([\w\-\.]+[^#?\s]+)(.*)?(#[\w\-]+)?$/g; | |
location.href = s.replace(r, "http://github.com/$3/$8"); | |
})(); | |
// URL Encoded Version (for use as a bookmarklet) | |
javascript:(function()%7Bvar%20s%20%3D%20location.href%3Bvar%20r%20%3D%20%2F%5E((http%5Bs%5D%3F%7Cftp)%3A%5C%2F)%3F%5C%2F%3F(%5B%5E%3A%5C.%5Cs%5D%2B).(%5B%5E%3A%5C.%5Cs%5D%2B).(%5B%5E%3A%5C%2F%5Cs%5D%2B)((%5C%2F%5Cw%2B)*%5C%2F)(%5B%5Cw%5C-%5C.%5D%2B%5B%5E%23%3F%5Cs%5D%2B)(.*)%3F(%23%5B%5Cw%5C-%5D%2B)%3F%24%2Fg%3Blocation.href%20%3D%20s.replace(r,"http://github.com/$3/$8")%3B%7D)()%3B |
Here is a combo that works both ways so you don't need 2 bookmarklet
javascript:location = location.href.replace(...[...location.host === "github.com"
? [/^((http[s]?):\/)?\/?([^:\/\s]+)((\/\w+)*\/)([\w\-\.]+[^#?\s]+)(.*)?(#[\w\-]+)?$/g, "https:/$5.github.io/$6"]
: [/^((http[s]?):\/)?\/?([^:\.\s]+).([^:\.\s]+).([^:\/\s]+)((\/\w+)*\/)([\w\-\.]+[^#?\s]+)(.*)?(#[\w\-]+)?$/g, "https://github.com/$3/$8"]])
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Noice.