Skip to content

Instantly share code, notes, and snippets.

Last active October 30, 2016 19:04
  • Star 13 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do? / - Bookmarklet

A simple bookmarklet which makes our painful life a bit easier.

javascript:(function(b,a,c,d,e){if(/\.\w+$/.test(a))b.location=c+a.replace("/blob/","/");else if(e=prompt("Insert a filename:","index.html"))b.location=c+a.replace("/tree/","/")+(~a.indexOf(d)?"/":d)+e})(window,location.pathname,"","/master/");

The usage is quite simple:

Go to any repo where you like to preview a file, and execute the booklet. If the current url is a file, it should open the file directly, otherwise it will prompt for a filename (per default it is index.html).

I've tested it with the following url-usecases:

New: optimized for


  • Firefox CSP interfere currently with the operation of bookmarklets.
    But, yay! There's already a bugreport:
    So, to use this booklet on HTTPS-enabled sites you've to disable security.csp.enable via about:config
    (...or look for a better solution [...and note it here!]).
(function (window, pathname, rawgit, master, file) {
if ( /\.\w+$/.test(pathname) ) {
window.location = rawgit + pathname.replace('/blob/', '/');
} else if ( (file = prompt('Insert a filename:', 'index.html')) ) {
window.location = rawgit + pathname.replace('/tree/', '/') + (~pathname.indexOf(master) ? '/' : master) + file;
}(window, location.pathname, '', '/master/'));
"name": "",
"description": "Opens a GitHub-file/path with",
"icon": "",
"link": ""
(function(b,a,c,d,e){if(/\.\w+$/.test(a))b.location=c+a.replace("/blob/","/");else if(e=prompt("Insert a filename:","index.html"))b.location=c+a.replace("/tree/","/")+(~a.indexOf(d)?"/":d)+e})(window,location.pathname,"","/master/");
Copy link

Why isn't this more popular??

Copy link

yckart commented Sep 3, 2014

Copy link

jasondavis commented Jul 2, 2016

THANK YOOOOU! Now we need to add auto clipboard copy capability. Maybe this

any interest?

Copy link

yckart commented Oct 30, 2016


Hmm... such a big library for this simple task?

Just replace window.location = ... with window.prompt('Copy to clipboard:', ...).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment