Skip to content

Instantly share code, notes, and snippets.

@samrawal
Last active January 15, 2024 22:09
Show Gist options
  • Save samrawal/9c70d4dd12efd2d560dd88538591f42e to your computer and use it in GitHub Desktop.
Save samrawal/9c70d4dd12efd2d560dd88538591f42e to your computer and use it in GitHub Desktop.
Inline Prompt Scratchpad for ChatGPT
// Paste the following into Tampermonkey, as an Arc Boost, etc.
// See https://twitter.com/samarthrawal/status/1648867725316435973
// ==UserScript==
// @name Prompt Scratchpad for ChatGPT
// @version 0.1
// @description Collapsible prompt scratchpad for ChatGPT interface
// @namespace com.samrawal.promptscratchpad
// @author Sam Rawal and ChatGPT :)
// @match https://chat.openai.com/
// @icon https://www.google.com/s2/favicons?sz=64&domain=openai.com
// @grant none
// ==/UserScript==
(function() {
'use strict';
const style = `
#injected-iframe {
position: fixed;
top: 0;
right: -30%;
width: 30%;
height: 100%;
border: 2px solid black;
z-index: 1000;
}
#iframe-toggle {
position: fixed;
top: 50%;
left: calc(100% - 25px);
transform: translateY(-50%);
width: 50px;
height: 50px;
background-color: #0076ff;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
font-size: 25px;
color: white;
cursor: pointer;
z-index: 1001;
}
body {
transition: margin-right 0.5s ease;
}
body.with-iframe {
margin-right: 40%;
}
`;
function addStyle(css) {
const head = document.getElementsByTagName('head')[0];
if (!head) { return; }
const style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
head.appendChild(style);
}
function createIFrame() {
const iFrame = document.createElement('iframe');
iFrame.src = 'https://labs.cactiml.com/promptscratchpad';
iFrame.id = 'injected-iframe';
return iFrame;
}
function createToggleButton() {
const button = document.createElement('div');
button.id = 'iframe-toggle';
button.innerHTML = '←';
return button;
}
function toggleIFrame() {
const iFrame = document.getElementById('injected-iframe');
const toggleButton = document.getElementById('iframe-toggle');
const body = document.body;
if (iFrame.style.right === '-40%') {
iFrame.style.right = '0';
toggleButton.innerHTML = '→';
body.classList.add('with-iframe');
} else {
iFrame.style.right = '-40%';
toggleButton.innerHTML = '←';
body.classList.remove('with-iframe');
}
}
addStyle(style);
const iFrame = createIFrame();
const toggleButton = createToggleButton();
toggleButton.addEventListener('click', toggleIFrame);
document.body.appendChild(iFrame);
document.body.appendChild(toggleButton);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment