Skip to content

Instantly share code, notes, and snippets.

Last active March 28, 2023 04:38
Show Gist options
  • Save xoxfaby/0595de39f1c59d9f5c18a9b4b5dcb4af to your computer and use it in GitHub Desktop.
Save xoxfaby/0595de39f1c59d9f5c18a9b4b5dcb4af to your computer and use it in GitHub Desktop.
ChatGPT code execution
// ==UserScript==
// @name New script
// @namespace Violentmonkey Scripts
// @match
// @grant none
// @version 1.1
// @author XoXFaby
// @description 07/12/2022, 12:24:00
// ==/UserScript==
const promptDone = function (timeout = 10000) {
return new Promise((resolve, reject) => {
const button = document.getElementsByClassName("text-gray-500")[0]
const observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
// Check if the mutation affects an element with the class PromptTextarea__PositionSubmit-sc-4snkpf-1
if ('button')) {
// Check if the element no longer has the disabled attribute
if (!'disabled')) {
// Start observing the element for changes
observer.observe(button, {
attributeFilter: ['disabled'],
attributeOldValue: true,
childList: true,
subtree: true,
setTimeout(reject, timeout)
// Select the node that will be observed for mutations
const targetNode = document.body;
// Options for the observer (which mutations to observe)
const config = { childList: true, subtree: true };
// Callback function to execute when mutations are observed
const callback = async (mutationList, observer) => {
for (const mutation of mutationList) {
if (mutation.type === 'childList') {
// Loop through the added nodes
for (const node of mutation.addedNodes) {
// Check if the added node is a code element
if (node.nodeName === 'PRE') {
// Get the text content of the code element
await promptDone()
const code = node.children[0].children[1].textContent;
// Use the text content of the code element as a variable in your JavaScript code
const output = eval(code);
// get prompt box and set value
const input = document.querySelectorAll("textarea")[0]
input.value = JSON.stringify(output, null, 2)
// Create an observer instance linked to the callback function
const observere = new MutationObserver(callback);
// Start observing the target node for configured mutations
observere.observe(targetNode, config);
// Add an event listener for the load event on the window object
window.addEventListener('load', function () {
const input = document.querySelectorAll("textarea")[0]
const inputEvent = new Event('input', {bubbles: true});
window.setTimeout(() => {
input.value = "You're a javascipt-based bot. We're using code blocks to communicate. They will be executed in a browser environment. Reply only with a single commentless code-block. No text."
}, 1000)
Copy link

I tried this script; however, my script not run and I think maybe its window.addEventListener not fired, does anyone have similar issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment