Last active
April 8, 2023 20:55
-
-
Save rynomad/35e0495627767fff1aaca638801e1bd5 to your computer and use it in GitHub Desktop.
test vm via gpt
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 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