Last active
January 4, 2024 10:51
-
-
Save AitorAstorga/cae2b3deddd112ef8306f421b7f13f78 to your computer and use it in GitHub Desktop.
ChatGPT Width Expander - Tampermonkey Script
This file contains 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 Width Expander | |
// @namespace http://tampermonkey.net/ | |
// @version 1.0.0 | |
// @description Always expand the width of the chat to 90% | |
// @author Aitor Astorga Saez de Vicuña | |
// @match https://chat.openai.com/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// Function to modify the styles of the specified elements | |
function changeStyles(elements, styleProperties) { | |
for (const element of elements) { | |
for (const property in styleProperties) { | |
element.style[property] = styleProperties[property]; | |
} | |
} | |
} | |
// Function to apply custom styles when the page content is loaded | |
function applyCustomStyles() { | |
// Target elements with the specific class | |
const elements = document.querySelectorAll('.xl\\:max-w-\\[48rem\\]'); | |
const customStyles = { | |
'max-width': '90%' | |
}; | |
changeStyles(elements, customStyles); | |
} | |
// Apply custom styles when the page is loaded or updated | |
const observer = new MutationObserver(function(mutations) { | |
mutations.forEach(function(mutation) { | |
if (mutation.addedNodes && mutation.addedNodes.length > 0) { | |
// Apply custom styles every time new nodes are added to the DOM | |
applyCustomStyles(); | |
} | |
}); | |
}); | |
observer.observe(document.body, { childList: true, subtree: true }); | |
// Apply custom styles immediately for the elements already present in the DOM | |
applyCustomStyles(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment