can you write a simple chrome extension that will save the content of a chatgpt…
- User
can you write a simple chrome extension that will save the content of a chatgpt conversation
- Assistantjavascript
// manifest.json { "manifest_version": 3, "name": "ChatGPT Saver", "version": "1.0", "description": "Saves the content of a ChatGPT conversation.", "permissions": [ "activeTab", "storage" ], "action": { "default_popup": "popup.html" } } // popup.html <!DOCTYPE html> <html> <head> <title>ChatGPT Saver</title> </head> <body> <h1>Save ChatGPT Conversation</h1> <button id="saveBtn">Save</button> <script src="popup.js"></script> </body> </html> // popup.js document.getElementById('saveBtn').addEventListener('click', () => { chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => { chrome.scripting.executeScript({ target: { tabId: tabs[0].id }, function: saveConversation }); }); }); function saveConversation() { // Get the conversation content from the ChatGPT page const conversation = document.querySelector('.conversation-container').innerHTML; // Save the conversation to Chrome storage chrome.storage.local.set({ conversation: conversation }, () => { alert('Conversation saved!'); }); }Explanation:
-
manifest.json:
- Defines the extension's metadata (name, version, description).
- Requests permissions to access the active tab and Chrome storage.
- Specifies the popup HTML file (
popup.html).
-
popup.html:
- A simple HTML page with a button to trigger the saving process.
- Includes the
popup.jsscript.
-
popup.js:
- Listens for a click on the "Save" button.
- Uses
chrome.tabs.queryto get the active tab.
-
- User
can you extend the extension code to save the conversation in html that looks similar to what is shared in the conversation
- Assistantjavascript
- User
does this include the css
- Assistant
The provided code does not include the CSS for the saved conversation. To include the CSS, you can extract the relevant styles from the ChatGPT page and add them to the saved HTML. Here's an updated version of the
saveConversationfunction that includes CSS:javascript
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.