Skip to content

Instantly share code, notes, and snippets.

@abhijit-hota
Created October 18, 2023 05:21
Show Gist options
  • Save abhijit-hota/b9bdbd889845377f56afcd1227d549fc to your computer and use it in GitHub Desktop.
Save abhijit-hota/b9bdbd889845377f56afcd1227d549fc to your computer and use it in GitHub Desktop.
// ==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