Skip to content

Instantly share code, notes, and snippets.

@yckart
Last active October 30, 2016 19:04
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save yckart/5832645 to your computer and use it in GitHub Desktop.
Save yckart/5832645 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/");
@austinpray
Copy link

Why isn't this more popular??

@yckart
Copy link
Author

yckart commented Sep 3, 2014

@jasondavis
Copy link

jasondavis commented Jul 2, 2016

THANK YOOOOU! Now we need to add auto clipboard copy capability. Maybe this
https://clipboardjs.com/
https://cdn.rawgit.com/zenorocha/clipboard.js/v1.5.12/dist/clipboard.min.js

any interest?

@yckart
Copy link
Author

yckart commented Oct 30, 2016

@jasondavis

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