diff --git a/README.md b/README.md index a473cad..6fabcf7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ ![Chrome ChatGPT Helper Logo](./images/icon-128.png) - # Chrome ChatGPT Helper Tired of copy pasting text into ChatGPT? Tired of switching tabs? Do you wish you could just run a prompt within Chrome with just a click? Well now you can! @@ -27,7 +26,11 @@ Click **Add Prompt** to add a new prompt. Make sure that your prompt names are u When a prompt is run via the right-click menu, your text selection will be replaced by the prompt result, and your original selection will be copied to the clipboard, so you can press Ctrl + V to get it back. You can use _$selection_ inside your prompts to insert the selected text into the prompt, please see the built-in prompts for examples. -Keep in mind that **changes won't be saved until the Save button is clicked!** +> [!NOTE] +> When using this extension with Reddit, please switch to **Markdown Mode** first, as Reddit's "fancy" editor has issues with handling paste events. + +> [!IMPORTANT] +> Keep in mind that **changes won't be saved until the Save button is clicked!** ## Disclaimer diff --git a/css/options.css b/css/options.css index aef15b7..941fa6c 100644 --- a/css/options.css +++ b/css/options.css @@ -51,10 +51,23 @@ h1 { font-size: 2.5em; } -legend { +p { font-size: 1.2em; } +input, +textarea { + font-size: 1.1em; +} + +legend { + font-size: 1.5em; +} + +label { + font-size: 1.3em; +} + #base { margin-right: auto; margin-left: auto; @@ -102,5 +115,5 @@ textarea { } .secondary { - color: var(--secondary-color); -} \ No newline at end of file + color: var(--secondary-color); +} diff --git a/html/options.html b/html/options.html index 00d635c..d187873 100644 --- a/html/options.html +++ b/html/options.html @@ -106,6 +106,11 @@

Chrome ChatGPT Helper

$selection inside your prompts to insert the selected text into the prompt.

+

+ When using this extension with Reddit, please switch to + Markdown Mode first, as Reddit's "fancy" + editor has issues with handling paste events. +

Keep in mind that changes won't be saved until the diff --git a/manifest.json b/manifest.json index 198dc84..75052a4 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "Chrome ChatGPT Helper", - "version": "1.4", + "version": "1.5", "description": "Create ChatGPT prompts, and execute them via the right click menu.", "permissions": ["contextMenus", "storage"], "icons": { diff --git a/scripts/content.js b/scripts/content.js index 73616c8..3072ee0 100644 --- a/scripts/content.js +++ b/scripts/content.js @@ -6,10 +6,10 @@ chrome.runtime.onMessage.addListener(function (request, _, _) { return; } - replaceSelectedText(request.replacement, request.selection); + replaceSelectedText(request.replacement); }); -function replaceSelectedText(toReplace, originalSelection) { +function replaceSelectedText(toReplace) { const activeElement = document.activeElement; if (activeElement.value) { @@ -28,22 +28,15 @@ function replaceSelectedText(toReplace, originalSelection) { activeElement.value.slice(0, activeElement.selectionStart) + toReplace + activeElement.value.slice(activeElement.selectionEnd); - } else if ( - activeElement.textContent !== undefined || - activeElement.textContent !== null - ) { - // Custom textbox, like Draft.js. Even though it is deprecated, we need to use execCommand here- setting the innerText manually just causes React to override the value. - const val = activeElement.textContent; + } else { + // A custom text input field, probably something like Draft.js. + // While `execCommand` is deprecated, as of writing (2024) there is still no replacement, + // and since there are so many apps / services that depend on it, it is unlikely to be removed anytime soon. + // One exception to this is Reddit; since Reddit is a horrible website that refuses to follow established standards, + // `execCommand` breaks backspace & deletion in their "fancy" text editor. Literally nothing works, not `execComand`, + // not `dispatchEvent`, nothing. The only thing that can be done is do switch to the Markdown editor, paste, and then + // go back. - const selection = originalSelection.trim(); - if (selection) { - navigator.clipboard.writeText(selection); - // There is a potential problem here; since we don't have the selection indices (like we do for regular input fields), we have to do a naive string replace. - // This means that if the selected text is duplicated in the textContent, only the first occurance will be replaced, as we don't know which one is selected. - const newText = val.replace(selection, toReplace); - document.execCommand("insertText", false, newText); - } else { - document.execCommand("insertText", false, toReplace); - } + document.execCommand("insertText", false, toReplace); } } diff --git a/scripts/options.js b/scripts/options.js index f32e944..5ad9a15 100644 --- a/scripts/options.js +++ b/scripts/options.js @@ -69,7 +69,6 @@ function getPromptsFromDocument() { for (let index = 0; index < promptElems.length; index++) { const element = promptElems[index]; - console.log(element); const promptName = element.querySelector("input").value; const promptBody = element.querySelector("textarea").value; results.push({ name: promptName, body: promptBody }); @@ -89,12 +88,8 @@ function restoreOptions() { } addPromptUI(prompt.name, prompt.body); }); - const deletePromptButtons = document.querySelectorAll(".deletePrompt"); - - deletePromptButtons.forEach((button) => { - button.addEventListener("click", deletePromptUI); - }); - + + setDeleteEvents(); keyInput.value = items.oaiKey; modelSelect.value = items.model; checkKeyValidity(); @@ -102,6 +97,14 @@ function restoreOptions() { ); } +function setDeleteEvents() { + const deletePromptButtons = document.querySelectorAll(".deletePrompt"); + + deletePromptButtons.forEach((button) => { + button.addEventListener("click", deletePromptUI); + }); +} + function checkKeyValidity() { const key = keyInput.value; if (!key) { @@ -163,6 +166,7 @@ function getPromptUI(name, body) { function addEmptyPromptUI() { addPromptUI("", ""); + setDeleteEvents(); } function addPromptUI(name, body) { diff --git a/scripts/service-worker.js b/scripts/service-worker.js index e7cd682..b50aa8c 100644 --- a/scripts/service-worker.js +++ b/scripts/service-worker.js @@ -113,6 +113,10 @@ async function init() { name: "Rewrite Casually", body: "Please rewrite the following in a casual manner: $selection", }, + { + name: "Fix typos", + body: "Please rewrite the following with all the typos fixed: $selection", + }, { name: "Cat Joke", body: "Please give me a funny joke about cats.",