Skip to content

Instantly share code, notes, and snippets.

@rynomad
Last active April 8, 2023 20:55
Show Gist options
  • Save rynomad/35e0495627767fff1aaca638801e1bd5 to your computer and use it in GitHub Desktop.
Save rynomad/35e0495627767fff1aaca638801e1bd5 to your computer and use it in GitHub Desktop.
test vm via gpt
// ==UserScript==
// @name New script - github.com
// @namespace Violentmonkey Scripts
// @match https://github.com/*
// @grant none
// @version 1.0
// ==/UserScript==
function publishGist(button) {
if (localStorage.getItem("gistTokenName")) {
// get the gist token and publish the gist
const tokenName = localStorage.getItem("gistTokenName");
const tokenValue = localStorage.getItem("gistTokenValue");
const codeElement = button.nextElementSibling;
const gistPayload = {
description: "My Gist",
public: true,
files: {
"my-file.js": {
content: codeElement.textContent,
},
},
};
const requestOptions = {
method: "POST",
headers: {
Authorization: `token ${tokenValue}`,
"Content-Type": "application/json",
},
body: JSON.stringify(gistPayload),
};
fetch("https://api.github.com/gists", requestOptions)
.then((response) => response.json())
.then((data) => {
console.log(`Gist URL: ${data.html_url}`);
})
.catch((error) => {
console.error(error);
});
} else {
// prompt the user for a gist token
const tokenName = prompt("Please enter your GitHub Gist token name:");
const tokenValue = prompt("Please enter your GitHub Gist token value:");
localStorage.setItem("gistTokenName", tokenName);
localStorage.setItem("gistTokenValue", tokenValue);
publishGist(button);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment