Skip to content

Instantly share code, notes, and snippets.

@knight42
Created February 22, 2019 07:18
Show Gist options
  • Save knight42/f8de80d8c4d8ebdb56a197af88a74e5e to your computer and use it in GitHub Desktop.
Save knight42/f8de80d8c4d8ebdb56a197af88a74e5e to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Open in godoc
// @namespace https://github.com/knight42
// @version 0.1
// @description Open godoc from GitHub
// @author knight42
// @include https://github.com/*/*
// @exclude https://github.com/*/*/blob/*
// @exclude https://github.com/settings/*
// @exclude https://github.com/orgs/*
// @exclude https://github.com/organizations/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
var grp = document.querySelector('div.BtnGroup')
var godocLink = document.createElement('a');
var pathname = document.location.pathname.slice(1);
var parts = pathname.split('/');
var godocOrg = parts[0] === 'kubernetes' ? 'k8s.io' : parts[0];
var godocPath = pathname.slice(parts[0].length).replace(/tree\/[^/]+\//, '');
godocLink.classList.add('btn', 'btn-sm', 'BtnGroup-item')
godocLink.id = 'godoc'
godocLink.innerText = 'Open in godoc'
godocLink.href = `https://godoc.org/${godocOrg}${godocPath}`;
grp.prepend(godocLink);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment