Created
March 9, 2023 15:54
-
-
Save acip/3485c1d918142dcc86bd7cb77d762f4d to your computer and use it in GitHub Desktop.
Copy data as JSON from OpenAI ChatGPT 3.5 Turbo playground bookmarklet
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
javascript: (function () { const messagesArray = []; messagesArray.push({ role: "system", message: document.querySelector(".chat-pg-instructions textarea").value }); const chatExchange = document.querySelector('.chat-pg-exchange'); const chatMessages = chatExchange.querySelectorAll('.chat-pg-message'); chatMessages.forEach(message => { const el = message.querySelector('.chat-message-role-text'); if (!el) { return; } const role = el.textContent; const messageTextarea = message.querySelector('.text-input'); if (!messageTextarea) { return; } const messageValue = messageTextarea.value; const messageObject = { role: role, message: messageValue }; messagesArray.push(messageObject); }); const messagesJSON = JSON.stringify(messagesArray); console.log(messagesJSON); const params = {}; const parameterPanelGrid = document.querySelector('.parameter-panel-grid'); const textContents = ['Temperature', 'Top P', 'Frequency penalty', 'Presence penalty']; const elements = parameterPanelGrid.querySelectorAll('*'); for (let i = 0; i < elements.length; i++) { const element = elements[i]; const textContent = element.textContent.trim(); if (textContents.includes(textContent)) { const input = element.nextElementSibling; if (input && input.tagName === 'INPUT') { params[textContent] = input.value; } } } console.log(params); const paramsJSON = JSON.stringify({ messages: messagesArray, params: params }); navigator.clipboard.writeText(paramsJSON) .then(() => { alert('Input values copied to clipboard.'); }) .catch((error) => { alert(`Failed to copy input values to clipboard: ${error}`); }); })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@acip Thanks, this was really helpful.
However, I made a few updates with fixes and enhancements:
I unobfustucated the code because I Edge did not support bookmarklet, so instead, I used this CSS and JS injector to inject the js to the page
.