Overview
This article introduces a simple JavaScript bookmarklet that removes unwanted \n from text entered into Codex’s prompt input area. The goal is to ensure that the prompt is sent as a single continuous line of text, avoiding formatting issues caused by accidental line breaks.
Purpose
When entering prompts into Codex, \n can sometimes be inserted unintentionally. These line breaks may affect how the prompt is interpreted. The bookmarklet is designed to clean the input text just before you submit a request to Codex.
The intended workflow is:
- Enter your prompt text as usual.
- Run the bookmarklet.
- Submit the cleaned prompt to Codex.
How It Works
The script scans the prompt input area and processes each paragraph element found inside it. For each element, it removes carriage returns (\r) and newline characters (\n) from the HTML content.
JavaScript Code
Array.from(document.querySelectorAll("#prompt-textarea > p")).forEach((e) => {
console.log(JSON.stringify(e.innerHTML));
e.innerHTML = e.innerHTML.replaceAll("\r", "").replaceAll("\n", "");
});
This code performs the following steps:
- Selects all
<p>elements inside the prompt text area. - Logs the original content to the console for reference.
- Replaces all newline-related characters with empty strings.
Bookmarklet Version
To use this functionality easily in your browser, the same logic can be saved as a bookmarklet. Add a new bookmark and paste the following code as the URL:
javascript:Array.from(document.querySelectorAll("%23prompt-textarea%20%3E%20p")).forEach(e=>{console.log(JSON.stringify(e.innerHTML));e.innerHTML=e.innerHTML.replaceAll("%5Cr","").replaceAll("%5Cn","")});
Once saved, clicking this bookmarklet will immediately clean the prompt text currently entered in Codex.
Conclusion
This bookmarklet provides a quick and reliable way to remove unintended newline characters from Codex prompts. By running it just before submitting a request, you can ensure cleaner input and more predictable prompt handling.
Another option
A Bookmarklet Overlay for Faster, Cleaner ChatGPT Prompt Entry
Top comments (0)