Skip to content

Instantly share code, notes, and snippets.

@gpedro
Created October 27, 2016 15:44
Show Gist options
  • Save gpedro/9dcf9b9038e492d000616b47e0b1d7f4 to your computer and use it in GitHub Desktop.
Save gpedro/9dcf9b9038e492d000616b47e0b1d7f4 to your computer and use it in GitHub Desktop.
shortcut to open godoc from github repository

Minified Version

javascript:(function(t,o){if("github.com"===o.hostname){var n=o.pathname,i=n.split("/")[1],a=n.split("/")[2],c=function(){return/^\/[^\/]+\/[^\/]+/.test(o.pathname)};c()&&t.open("https://godoc.org/github.com/"+i+"/"+a)}})(window,location);

Full Version

javascript:(function(w, l){
  // functions & variables
  // powered by sindresorhus@refined-github
  if (l.hostname !== 'github.com') { return; }
  var path = l.pathname;
  var ownerName = path.split('/')[1];
  var repoName = path.split('/')[2];
  var isRepo = function () { return /^\/[^/]+\/[^/]+/.test(l.pathname); };

  if (isRepo()) {
      w.open('https://godoc.org/github.com/' + ownerName + '/' + repoName);  
  }
})(window, location);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment