Created
October 18, 2023 05:21
-
-
Save abhijit-hota/b9bdbd889845377f56afcd1227d549fc 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 GitHubDocJSONView | |
// @namespace http://tampermonkey.net/ | |
// @version 1.0 | |
// @description Show link icon in github doc | |
// @author Abhijit Hota (abhijithota.me) | |
// @match https://docs.github.com/en/rest/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const responseBlocks = document.querySelectorAll("div[class*=RestCodeSamples_responseCodeBlock]"); | |
responseBlocks.forEach((block) => { | |
const jsonCode = block.querySelector("code").textContent; | |
const encodedJSON = btoa(jsonCode); | |
const href = `data:application/json;base64,${encodedJSON}`; | |
const linkBtn = Object.assign(document.createElement("a"), { | |
textContent: "View", | |
className: "float-right btn-octicon", | |
target: "_blank", | |
href, | |
}); | |
block.previousSibling.append(linkBtn); | |
}) | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment