Skip to content

Instantly share code, notes, and snippets.

@timwco
Created November 20, 2014 03:02
Show Gist options
  • Save timwco/86fcecf3920d470e5a0d to your computer and use it in GitHub Desktop.
Save timwco/86fcecf3920d470e5a0d to your computer and use it in GitHub Desktop.
Github Repo to Github Pages Website - JavaScript Regex - 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
// I'm sure there is a way to make this cleaner, but I was in a hurry
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");
/*
Grab the bookmarklet above. I used http://ted.mielczarek.org/code/mozilla/bookmarklet.html to compress it
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment