Created
December 8, 2020 21:28
-
-
Save fallsimply/09f8f3f2734b7f8033d049fca7f2dc97 to your computer and use it in GitHub Desktop.
violentmonkey scripts - com.fallsimply.tweaks
This file contains hidden or 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 github go docs (about) | |
// @namespace com.fallsimply.tweaks | |
// @version 1.0 | |
// @author fallsimply | |
// @description adds documentation link to go projects on github | |
// @grant GM_xmlhttpRequest | |
// ==/UserScript== | |
let re = new RegExp('github.com/([^/]+)/([^/]+)'); | |
const goLogoSvg = (color = "#fff") => `<svg class="octicon" width="24" height="24" viewBox="0 0 24 24" aria-hidden="true" style="margin: -6px 0 -2px 0; color: ${color}; vertical-align: middle;"><path d="M1.811 10.715c-.047 0-.058-.023-.035-.059l.246-.315c.023-.035.081-.058.128-.058h4.172c.046 0 .058.035.035.07l-.199.303c-.023.036-.082.07-.117.07l-4.23-.011zM.047 11.79c-.047 0-.059-.023-.035-.058l.245-.316c.023-.035.082-.058.129-.058h5.328c.047 0 .07.035.058.07l-.093.28c-.012.047-.058.07-.105.07l-5.527.012zm2.828 1.075c-.047 0-.059-.035-.035-.07l.163-.292c.023-.035.07-.07.117-.07h2.337c.047 0 .07.035.07.082l-.023.28c0 .047-.047.082-.082.082l-2.547-.012zM15.004 10.505c-.736.187-1.239.327-1.963.514-.176.046-.187.058-.34-.117-.174-.199-.303-.327-.548-.444-.737-.362-1.45-.257-2.115.175-.795.514-1.204 1.274-1.192 2.22.011.935.654 1.706 1.577 1.835.795.105 1.46-.175 1.987-.771.105-.129.198-.269.315-.433H10.47c-.245 0-.304-.152-.222-.35.152-.362.432-.97.596-1.274a.315.315 0 0 1 .292-.187h4.253c-.023.316-.023.631-.07.947a4.983 4.983 0 0 1-.958 2.29c-.841 1.11-1.94 1.8-3.33 1.986-1.145.152-2.209-.07-3.143-.77-.865-.655-1.356-1.52-1.484-2.595-.152-1.274.222-2.419.993-3.424.83-1.086 1.928-1.776 3.272-2.021 1.098-.199 2.15-.07 3.096.572.62.41 1.063.97 1.356 1.648.07.105.023.164-.117.199 M18.872 16.967c-1.064-.024-2.034-.328-2.852-1.029a3.665 3.665 0 0 1-1.262-2.255c-.21-1.32.152-2.489.947-3.529.853-1.122 1.881-1.706 3.272-1.951 1.192-.21 2.314-.094 3.33.596.923.63 1.496 1.484 1.648 2.605.198 1.578-.257 2.863-1.344 3.962-.771.783-1.718 1.273-2.805 1.495-.315.059-.63.07-.934.106zm2.78-4.721c-.011-.152-.011-.269-.034-.386-.21-1.157-1.274-1.811-2.384-1.554-1.087.245-1.788.935-2.045 2.033-.21.912.234 1.835 1.075 2.209.643.28 1.285.245 1.905-.07.923-.48 1.425-1.227 1.484-2.232z"/></svg>` | |
const makeDocUrl = (user, repo) => `https://pkg.go.dev/github.com/${user}/${repo}` | |
const makeGoDocUrl = (user, repo) => `https://godoc.org/github.com/${user}/${repo}` | |
const tmpl = (user, repo) => ` | |
<div class="mt-3 d-flex flex-justify-center"> | |
<a class="btn btn-primary mr-2" href="${makeDocUrl(user, repo)}" style="background-color: #00ADD8">${goLogoSvg()} View Docs</a> | |
<a class="btn" href="${makeGoDocUrl(user, repo)}">${goLogoSvg("#00ADD8")} View Godoc</a> | |
</div> | |
` | |
const draw = (vals) => { | |
let user = vals[1] | |
let repo = vals[2] | |
let elem = document.querySelector(".repository-content .col-md-3 .BorderGrid .BorderGrid-row .BorderGrid-cell") | |
elem.insertAdjacentHTML("beforeend", tmpl(user, repo)) | |
console.log("go documentation links injected"); | |
} | |
const goStuff = () => { | |
let result = re.exec(document.location); | |
fetch(`https://api.github.com/repos/${result[1]}/${result[2]}/languages`) | |
.then(response => response.json()) | |
.then(data => (Object.keys(data).includes("Go") && result.length == 3) ? draw(result) : null); | |
} | |
document.addEventListener("pjax:success", goStuff) | |
goStuff() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment