Skip to content

Instantly share code, notes, and snippets.

@SBejga
Forked from yckart/README.md
Created September 30, 2016 08:25
Show Gist options
  • Save SBejga/a04581524934bcaa5d9bc85eeea67cd3 to your computer and use it in GitHub Desktop.
Save SBejga/a04581524934bcaa5d9bc85eeea67cd3 to your computer and use it in GitHub Desktop.
rawgit.com / rawgithub.com - 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,"http://rawgit.com","/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 http://backtick.io/

Notes

  • Firefox CSP interfere currently with the operation of bookmarklets.
    But, yay! There's already a bugreport: https://bugzilla.mozilla.org/show_bug.cgi?id=866522
    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, 'http://rawgit.com', '/master/'));
{
"name": "rawgit.com",
"description": "Opens a GitHub-file/path with rawgit.com.",
"icon": "http://rawgit.com/img/sushi.png",
"link": "http://rawgit.com/"
}
(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,"http://rawgit.com","/master/");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment