Instantly share code, notes, and snippets.
Created
February 6, 2026 21:03
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
-
Save jhauga/6ed0d7b27e2214fb3444a0757129d9c6 to your computer and use it in GitHub Desktop.
Bookmarklet - use this bookmarklet for resizing the Gmail sidebar when labels have long and similar names. Ensure to copy/paste the top condensed line of the bookmarklet. Info at "https://github.com/isocialPractice/bookmarklets".
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
| /// *********************************************************** /// | |
| // ****************** BROWSER BOOKMARKLET GIST ***************** // | |
| // ************************************************************* // | |
| // // | |
| // LICENSE ///////////////////////////////////////////////////// | |
| // ******* // | |
| // The code in this gist is public domain. // | |
| // Licensed as Public Domain CC0 // | |
| ////////////////////////////////////////////////////////////////// | |
| // | |
| // COPY / PAST BELOW LINE TO USE | |
| javascript:(function(){ /* Global variables. */ const gmailResizeSideBarStyle = ` div.wT { min-width: unset; max-width: unset; }`; /********************************************************************************************* MAIN FUNCTION *********************************************************************************************/ function gmailResizeSideBar() { if (location.href.toLowerCase().indexOf("mail.google.com") > -1) { const target = document.querySelector('.aeN.WR.baA.nH.oy8Mbf'); /* side bar */ if (!target) return console.log("Error: Target element not found."); /* error */ if (document.getElementById('gmail-resizer-handle')) /* no duplicates */ return console.log("Resizer already exists."); /* 1. reset outer sidebar constraints */ target.style.minWidth = '100px'; target.style.maxWidth = '80vw'; target.style.position = 'relative'; target.style.flexBasis = 'auto'; target.style.width = /* close enough but enough to indicate bm ready for use */ target.offsetWidth + 75 + 'px'; /* 2. create the invisible drag handle */ const handle = document.createElement('div'); handle.id = 'gmail-resizer-handle'; Object.assign(handle.style, { position: 'absolute', right: '-4px', top: '0', width: '8px', height: '100%', cursor: 'col-resize', zIndex: '9999', backgroundColor: 'transparent' }); /* add event for resize */ handle.onmouseenter = () => handle.style.backgroundColor = 'rgba(0,0,0,0.1)'; handle.onmouseleave = () => handle.style.backgroundColor = 'transparent'; /* add element to target */ target.appendChild(handle); /* drag Logic */ let isResizing = false; /* switch */ let startX, startWidth; /* ready resize */ handle.addEventListener('mousedown', (e) => { isResizing = true; startX = e.clientX; startWidth = target.offsetWidth; document.body.style.cursor = 'col-resize'; document.body.style.userSelect = 'none'; }); /* resizing */ window.addEventListener('mousemove', (e) => { if (!isResizing) return; const newWidth = startWidth + (e.clientX - startX); target.style.width = newWidth + 'px'; window.dispatchEvent(new Event('resize')); }); /* done resizing */ window.addEventListener('mouseup', () => { isResizing = false; document.body.style.cursor = 'default'; document.body.style.userSelect = 'auto'; }); /* ready for use logged */ console.log("Custom Gmail Sidebar Resizer Active!"); /* apply min-width and max-width to nested elements */ let style = document.createElement("style"); /* new style tag */ style.innerText = gmailResizeSideBarStyle; /* global var */ document.body.insertAdjacentElement("afterbegin", style); /* add */ } else { /* address is not gmail */ console.log("Error: gmail not detected"); } } gmailResizeSideBar();})(); | |
| // MAKE ANY EDITS AS NEEDED | |
| // ************************************************************* | |
| // Use the JS Formatted Bookmarklet below to see if any changes | |
| // need to be made in accordance to the page you want to use | |
| // it for. After making needed changes ensure that the revised | |
| // bookmarklet is condensed before using it in your browser. | |
| // For more info on this bookmarklet visit: | |
| // https://github.com/isocialPractice/bookmarklets | |
| // ************************************************************* | |
| // ************************************************************* | |
| // ************************JS-FORMATTED************************* | |
| javascript:(function(){ | |
| /* Global variables. */ | |
| const gmailResizeSideBarStyle = ` | |
| div.wT { | |
| min-width: unset; | |
| max-width: unset; | |
| }`; | |
| /********************************************************************************************* | |
| MAIN FUNCTION | |
| *********************************************************************************************/ | |
| function gmailResizeSideBar() { | |
| if (location.href.toLowerCase().indexOf("mail.google.com") > -1) { | |
| const target = document.querySelector('.aeN.WR.baA.nH.oy8Mbf'); /* side bar */ | |
| if (!target) return console.log("Error: Target element not found."); /* error */ | |
| if (document.getElementById('gmail-resizer-handle')) /* no duplicates */ | |
| return console.log("Resizer already exists."); | |
| /* 1. reset outer sidebar constraints */ | |
| target.style.minWidth = '100px'; | |
| target.style.maxWidth = '80vw'; | |
| target.style.position = 'relative'; | |
| target.style.flexBasis = 'auto'; | |
| target.style.width = /* close enough but enough to indicate bm ready for use */ | |
| target.offsetWidth + 75 + 'px'; | |
| /* 2. create the invisible drag handle */ | |
| const handle = document.createElement('div'); | |
| handle.id = 'gmail-resizer-handle'; | |
| Object.assign(handle.style, { | |
| position: 'absolute', | |
| right: '-4px', | |
| top: '0', | |
| width: '8px', | |
| height: '100%', | |
| cursor: 'col-resize', | |
| zIndex: '9999', | |
| backgroundColor: 'transparent' | |
| }); | |
| /* add event for resize */ | |
| handle.onmouseenter = () => handle.style.backgroundColor = 'rgba(0,0,0,0.1)'; | |
| handle.onmouseleave = () => handle.style.backgroundColor = 'transparent'; | |
| /* add element to target */ | |
| target.appendChild(handle); | |
| /* drag Logic */ | |
| let isResizing = false; /* switch */ | |
| let startX, startWidth; | |
| /* ready resize */ | |
| handle.addEventListener('mousedown', (e) => { | |
| isResizing = true; | |
| startX = e.clientX; | |
| startWidth = target.offsetWidth; | |
| document.body.style.cursor = 'col-resize'; | |
| document.body.style.userSelect = 'none'; | |
| }); | |
| /* resizing */ | |
| window.addEventListener('mousemove', (e) => { | |
| if (!isResizing) return; | |
| const newWidth = startWidth + (e.clientX - startX); | |
| target.style.width = newWidth + 'px'; | |
| window.dispatchEvent(new Event('resize')); | |
| }); | |
| /* done resizing */ | |
| window.addEventListener('mouseup', () => { | |
| isResizing = false; | |
| document.body.style.cursor = 'default'; | |
| document.body.style.userSelect = 'auto'; | |
| }); | |
| /* ready for use logged */ | |
| console.log("Custom Gmail Sidebar Resizer Active!"); | |
| /* apply min-width and max-width to nested elements */ | |
| let style = document.createElement("style"); /* new style tag */ | |
| style.innerText = gmailResizeSideBarStyle; /* global var */ | |
| document.body.insertAdjacentElement("afterbegin", style); /* add */ | |
| } else { | |
| /* address is not gmail */ | |
| console.log("Error: gmail not detected"); | |
| } | |
| } | |
| gmailResizeSideBar(); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment