Last active
April 12, 2023 20:36
-
-
Save rynomad/61a00627cb46d88d7895ef29d5cb27ff to your computer and use it in GitHub Desktop.
add auto-insert rules to chatGPT
This file contains hidden or 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
// ==UserScript== | |
// @name ChatGPT rulesTextArea | |
// @namespace Violentmonkey Scripts | |
// @match https://chat.openai.com/* | |
// @grant none | |
// @version 1.1 | |
// @author - | |
// @description 4/12/2023, 2:22:19 PM | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const style = document.createElement('style'); | |
style.innerHTML = ` | |
#enhanced-textarea { | |
position: fixed; | |
bottom: 0; | |
right: 10px; | |
width: 50%; | |
min-height: 20px; | |
max-height: 300px; | |
padding: 5px; | |
border: 1px solid #ccc; | |
border-radius: 5px; | |
overflow: hidden; | |
background-color: white; | |
resize: none; | |
} | |
#enhanced-textarea:focus { | |
outline: none; | |
box-shadow: 0 0 4px rgba(0, 0, 0, 0.2); | |
} | |
#handle { | |
position: absolute; | |
top: -6px; | |
left: 50%; | |
transform: translateX(-50%); | |
width: 10px; | |
height: 10px; | |
border-radius: 50%; | |
background-color: #ccc; | |
cursor: pointer; | |
} | |
`; | |
document.head.appendChild(style); | |
const enhancedTextarea = document.createElement('textarea'); | |
enhancedTextarea.id = 'enhanced-textarea'; | |
enhancedTextarea.style.display = 'none'; | |
const handle = document.createElement('div'); | |
handle.id = 'handle'; | |
enhancedTextarea.appendChild(handle); | |
document.body.appendChild(enhancedTextarea); | |
handle.addEventListener('click', () => { | |
if (enhancedTextarea.style.display === 'none') { | |
enhancedTextarea.style.display = 'block'; | |
} else { | |
enhancedTextarea.style.display = 'none'; | |
} | |
}); | |
document.addEventListener( | |
'keydown', | |
(e) => { | |
if (e.key === 'Enter' && !e.shiftKey) { | |
console.log('enter pressed', e); | |
e.preventDefault(); | |
e.stopPropagation(); | |
const textareas = Array.from(document.querySelectorAll('textarea')); | |
const textarea = textareas.filter(t => t.id !== 'enhanced-textarea')[0]; | |
const button = textarea.nextElementSibling; | |
button.click(); | |
} | |
}, | |
{ capture: true } | |
); | |
function initPatchButtonAndEnter() { | |
const textareas = Array.from(document.querySelectorAll('textarea')); | |
const textarea = textareas.filter(t => t.id !== 'enhanced-textarea')[0]; | |
if (textarea) { | |
const button = textarea.nextElementSibling; | |
if (button) { | |
function patchButton() { | |
const textareas = Array.from(document.querySelectorAll('textarea')); | |
const textarea = textareas.filter(t => t.id !== 'enhanced-textarea')[0]; | |
const button = textarea.nextElementSibling; | |
const enhancedTextarea = document.getElementById('enhanced-textarea'); | |
if (!button) { | |
return requestIdleCallback(patchButton); | |
} | |
button.onclick = () => { | |
textarea.value += `\n${enhancedTextarea.value}`; | |
insertReminders(); | |
}; | |
setTimeout(() => requestIdleCallback(patchButton), 2000); | |
} | |
patchButton(); | |
} else { | |
requestIdleCallback(initPatchButtonAndEnter); | |
} | |
} else { | |
requestIdleCallback(initPatchButtonAndEnter); | |
} | |
} | |
initPatchButtonAndEnter(); | |
})(); | |
(function () { | |
'use strict'; | |
// Create textarea | |
const textarea = document.createElement('textarea'); | |
textarea.id = 'expandable-textarea'; | |
textarea.style.cssText = ` | |
position: fixed; | |
bottom: 30px; | |
right: 20px; | |
z-index: 9999; | |
width: 300px; | |
height: 0; | |
padding: 0; | |
overflow: hidden; | |
transition: height 0.3s ease-in-out; | |
box-sizing: border-box; | |
resize: none; | |
color: black; | |
border: 1px solid #ccc; | |
`; | |
document.body.appendChild(textarea); | |
// Create toggle button | |
const button = document.createElement('button'); | |
button.textContent = 'Rules'; | |
button.style.cssText = ` | |
position: fixed; | |
bottom: 0; | |
right: 20px; | |
z-index: 9999; | |
cursor: pointer; | |
background-color: #ccc; | |
border: none; | |
padding: 5px 10px; | |
`; | |
document.body.appendChild(button); | |
// Toggle textarea visibility on button click | |
button.addEventListener('click', () => { | |
if (textarea.style.height === '0px') { | |
textarea.style.height = '200px'; | |
textarea.style.padding = '5px'; | |
} else { | |
textarea.style.height = '0'; | |
textarea.style.padding = '0'; | |
} | |
}); | |
document.addEventListener( | |
'keydown', | |
(e) => { | |
if (e.key === 'Enter' && !e.shiftKey) { | |
console.log('enter pressed', e); | |
e.preventDefault(); | |
e.stopPropagation(); | |
const textareas = Array.from(document.querySelectorAll('textarea')); | |
const textarea = textareas.filter(t => t.id !== 'enhanced-textarea')[0]; | |
const button = textarea.nextElementSibling; | |
button.click(); | |
} | |
}, | |
{ capture: true } | |
); | |
const rulesTextArea = textarea; | |
function initPatchButtonAndEnter() { | |
const textareas = Array.from(document.querySelectorAll('textarea')); | |
const textarea = textareas.filter(t => t.id !== 'enhanced-textarea')[0]; | |
if (textarea) { | |
const button = textarea.nextElementSibling; | |
if (button) { | |
function patchButton() { | |
const textareas = Array.from(document.querySelectorAll('textarea')); | |
const textarea = textareas.filter(t => t.id !== 'enhanced-textarea')[0]; | |
const button = textarea.nextElementSibling; | |
const enhancedTextarea = rulesTextArea; | |
if (!button) { | |
return requestIdleCallback(patchButton); | |
} | |
button.onclick = () => { | |
textarea.value = `${enhancedTextarea.value}\n\n${textarea.value}`; | |
}; | |
setTimeout(() => requestIdleCallback(patchButton), 2000); | |
} | |
patchButton(); | |
} else { | |
requestIdleCallback(initPatchButtonAndEnter); | |
} | |
} else { | |
requestIdleCallback(initPatchButtonAndEnter); | |
} | |
} | |
initPatchButtonAndEnter(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment