Skip to content

Commit

Permalink
Update config2.js
Browse files Browse the repository at this point in the history
  • Loading branch information
asgeirtj authored Jul 13, 2024
1 parent d7217bf commit eaadf09
Showing 1 changed file with 45 additions and 77 deletions.
122 changes: 45 additions & 77 deletions config2.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,33 @@
// Function to adjust the menu height
function adjustMenuHeight(newHeight) {
const menuContainer = document.querySelector('nav[class*="jsx-2562846439"]');
if (menuContainer) {
menuContainer.style.maxHeight = `${newHeight}px`;
menuContainer.style.overflowY = 'auto';
} else {
console.error('Menu container not found');
document.addEventListener('keydown', function(event) {
if (event.metaKey) {
// New Chat Button
if (event.key === 'k') {
event.preventDefault();
clickElementBySelector(`button[data-element-id="new-chat-button-in-side-bar"].jsx-2562846439`);
}
// Voice Input Button
if (event.key === '3') {
event.preventDefault();
clickElementBySelector(`button[data-element-id="voice-input-button"].rounded-md.py-1.px-1.flex.items-center.justify-center.transition-all.space-x-2.shrink-0.text-gray-500.hover\\:text-gray-900.dark\\:hover\\:text-white`);
}
// Settings Button and Preferences
if (event.key === ',') {
event.preventDefault();
clickSettingsAndPreferences(`button[data-element-id='settings-button'].cursor-default.bg-white\\/20`, "Preferences");
}
// Model Settings Menu Button and Menu Item
if (event.key === '.') {
event.preventDefault();
clickModelSettings(`button#headlessui-menu-button-:rk8:.inline-flex.items-center.justify-center.gap-2.p-2.rounded-md.hover\\:bg-black\\/5.active\\:bg-black\\/10`, "Model Settings (Current Chat)");
}
// Regenerate Button
if (event.key === 'R' && event.shiftKey) {
event.preventDefault();
clickElementBySelector(`button[data-element-id="regenerate-button"].inline-flex.items-center.justify-center.rounded-md.px-3.py-2.shadow-md.transition-all.group.font-semibold.text-xs.hover\\:scale-105.border.border-transparent.text-white.bg-blue-600.hover\\:bg-blue-500.active\\:bg-blue-600.dark\\:bg-blue-900.dark\\:hover\\:bg-blue-800`);
}
}
}

// Function to create a control panel for menu height
function createControlPanel() {
const panel = document.createElement('div');
panel.style.position = 'fixed';
panel.style.top = '10px';
panel.style.right = '10px';
panel.style.zIndex = '9999';
panel.style.background = 'white';
panel.style.padding = '10px';
panel.style.border = '1px solid black';

const input = document.createElement('input');
input.type = 'number';
input.value = '500'; // Default height set to 500px
input.style.width = '60px';

const button = document.createElement('button');
button.textContent = 'Adjust Height';
button.onclick = () => adjustMenuHeight(input.value);

panel.appendChild(input);
panel.appendChild(button);
document.body.appendChild(panel);
}
});

// Function to click elements by selector
function clickElementBySelector(selector) {
const element = document.querySelector(selector);
if (element) {
Expand All @@ -44,7 +37,6 @@ function clickElementBySelector(selector) {
}
}

// Function to click settings and preferences
function clickSettingsAndPreferences(settingsButtonSelector, preferencesText) {
const settingsButton = document.querySelector(settingsButtonSelector);
if (settingsButton) {
Expand All @@ -66,7 +58,6 @@ function clickSettingsAndPreferences(settingsButtonSelector, preferencesText) {
}
}

// Function to click model settings
function clickModelSettings(menuButtonSelector, modelSettingsText) {
const modelSettingsMenuButton = document.querySelector(menuButtonSelector);
if (modelSettingsMenuButton) {
Expand All @@ -77,6 +68,7 @@ function clickModelSettings(menuButtonSelector, modelSettingsText) {

if (modelSettingsOption) {
modelSettingsOption.click();
adjustSpecificElementHeight(); // Adjust height after clicking
obs.disconnect(); // Stop observing
}
});
Expand All @@ -88,61 +80,37 @@ function clickModelSettings(menuButtonSelector, modelSettingsText) {
}
}

// Function to set textarea rows
function adjustSpecificElementHeight() {
const specificElement = document.querySelector('div.py-2.max-h-\\[300px\\].overflow-auto[role="none"]');
if (specificElement) {
specificElement.style.maxHeight = '500px';
} else {
console.log('Specific element for height adjustment not found');
}
}

function setTextareaRows() {
const textarea = document.querySelector('[data-element-id="ai-characters-system-instruction-input"]');
if (textarea) {
textarea.setAttribute('rows', '30');
}
}

// Event listener for keyboard shortcuts
document.addEventListener('keydown', function(event) {
if (event.metaKey) {
// New Chat Button
if (event.key === 'k') {
event.preventDefault();
clickElementBySelector(`button[data-element-id="new-chat-button-in-side-bar"].jsx-2562846439`);
}
// Voice Input Button
if (event.key === '3') {
event.preventDefault();
clickElementBySelector(`button[data-element-id="voice-input-button"].rounded-md.py-1.px-1.flex.items-center.justify-center.transition-all.space-x-2.shrink-0.text-gray-500.hover\\:text-gray-900.dark\\:hover\\:text-white`);
}
// Settings Button and Preferences
if (event.key === ',') {
event.preventDefault();
clickSettingsAndPreferences(`button[data-element-id='settings-button'].cursor-default.bg-white\\/20`, "Preferences");
}
// Model Settings Menu Button and Menu Item
if (event.key === '.') {
event.preventDefault();
clickModelSettings(`button[id^="headlessui-menu-button-"]`, "Model Settings (Current Chat)");
}
// Regenerate Button
if (event.key === 'R' && event.shiftKey) {
event.preventDefault();
clickElementBySelector(`button[data-element-id="regenerate-button"]`);
}
}
});

// Set textarea rows and observe for changes
setTextareaRows();
const textareaObserver = new MutationObserver((mutations) => {
adjustSpecificElementHeight(); // Initial height adjustment

const observer = new MutationObserver((mutations) => {
for (let mutation of mutations) {
if (mutation.type === 'childList') {
setTextareaRows();
adjustSpecificElementHeight(); // Ensure the height adjustment is applied dynamically
}
}
});
textareaObserver.observe(document.body, {

observer.observe(document.body, {
childList: true,
subtree: true
});

// Initialize menu height adjustment
createControlPanel();
adjustMenuHeight(500); // Set initial height to 500px

console.log('Enhanced script loaded with all functionalities including menu height adjustment and setting textarea rows.');
console.log('Updated script loaded with all functionalities including specific element height adjustment to 500px.');

0 comments on commit eaadf09

Please sign in to comment.