Created
February 22, 2019 07:18
-
-
Save knight42/f8de80d8c4d8ebdb56a197af88a74e5e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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