Skip to content

Instantly share code, notes, and snippets.

@bcrtvkcs
Created February 25, 2026 01:20
Show Gist options
  • Select an option

  • Save bcrtvkcs/b81ca1500ebcc5739376c6d00b1f7843 to your computer and use it in GitHub Desktop.

Select an option

Save bcrtvkcs/b81ca1500ebcc5739376c6d00b1f7843 to your computer and use it in GitHub Desktop.
Jules Auto-Collapse Diffs (Userscript)
// ==UserScript==
// @name Jules Auto-Collapse Diffs
// @namespace http://tampermonkey.net/
// @version 1.2
// @description Automatically collapses diffs on Jules.google.com upon page load
// @author BCRTVKCS
// @license MIT
// @match https://jules.google.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
let lastUrl = location.href;
let hasCollapsed = false;
function attemptCollapse() {
const btn = document.querySelector('button.collapse-all-button');
// Button found and not yet collapsed on this page
if (btn && !hasCollapsed) {
hasCollapsed = true; // Lock immediately to prevent re-triggering
// Wait 200 milliseconds for the framework to attach the event listener before clicking
setTimeout(() => {
const currentBtn = document.querySelector('button.collapse-all-button');
if (currentBtn) {
currentBtn.click();
console.log("Jules Auto-Collapse: Diffs successfully collapsed.");
}
}, 200);
}
}
// Reset state if URL changes in SPA (Single Page Application) architecture
const observer = new MutationObserver(() => {
if (location.href !== lastUrl) {
lastUrl = location.href;
hasCollapsed = false; // Navigated to a new file, allow collapsing again
}
attemptCollapse();
});
// Start observing DOM changes
observer.observe(document.body, { childList: true, subtree: true });
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment