Last active
December 9, 2025 08:58
-
-
Save DediqaTech/74639a9f7ad93bbc08a2b3b77bfcc53b to your computer and use it in GitHub Desktop.
Google Cloud Snackbar Auto Dismiss
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 Google Cloud Snackbar Auto Dismiss | |
| // @author DediqaTech | |
| // @namespace https://github.com/DediqaTech | |
| // @version 1.0 | |
| // @description Automatically remove that annoying sticky popover | |
| // @icon https://www.google.com/s2/favicons?sz=64&domain=console.cloud.google.com | |
| // @downloadURL https://gist.github.com/DediqaTech/74639a9f7ad93bbc08a2b3b77bfcc53b/raw/f93674149371e004dd4abe1036a99d34882cca4e/dediqatech-gcloud-dismiss-popover.user.js | |
| // @updateURL https://gist.github.com/DediqaTech/74639a9f7ad93bbc08a2b3b77bfcc53b/raw/f93674149371e004dd4abe1036a99d34882cca4e/dediqatech-gcloud-dismiss-popover.user.js | |
| // @match https://console.cloud.google.com/run* | |
| // @run-at document-idle | |
| // @grant none | |
| // ==/UserScript== | |
| (function () { | |
| "use strict"; | |
| var DISMISS_DELAY_MS = 3000; | |
| function scheduleDismiss(snackbarElement) { | |
| if (!snackbarElement || snackbarElement.dataset.cfcAutoDismissScheduled === "1") { | |
| return; | |
| } | |
| snackbarElement.dataset.cfcAutoDismissScheduled = "1"; | |
| window.setTimeout(function () { | |
| if (!document.contains(snackbarElement)) { | |
| return; | |
| } | |
| // Prefer clicking the official close button if present | |
| var closeButton = snackbarElement.querySelector("button.cfc-snack-bar-close-button"); | |
| if (closeButton) { | |
| closeButton.click(); | |
| return; | |
| } | |
| // Fallback: remove enclosing overlay or the container itself | |
| var overlayElement = snackbarElement.closest(".cdk-overlay-popover, .cdk-overlay-pane, .mat-mdc-snack-bar-container"); | |
| var elementToRemove = overlayElement || snackbarElement; | |
| if (elementToRemove && elementToRemove.parentNode) { | |
| elementToRemove.parentNode.removeChild(elementToRemove); | |
| } | |
| }, DISMISS_DELAY_MS); | |
| } | |
| function findAndScheduleAll() { | |
| var selectorList = [ | |
| "mat-snack-bar-container", | |
| ".mat-mdc-snack-bar-container", | |
| ".gmat-mdc-snack-bar.cm-snack-bar" | |
| ]; | |
| var snackbarElements = document.querySelectorAll(selectorList.join(",")); | |
| snackbarElements.forEach(function (snackbarElement) { | |
| scheduleDismiss(snackbarElement); | |
| }); | |
| } | |
| function observeSnackbars() { | |
| if (!document.body) { | |
| return; | |
| } | |
| var mutationObserver = new MutationObserver(function (mutationList) { | |
| mutationList.forEach(function (mutationRecord) { | |
| mutationRecord.addedNodes.forEach(function (addedNode) { | |
| if (!(addedNode instanceof HTMLElement)) { | |
| return; | |
| } | |
| // If the added node itself is a snackbar, schedule it | |
| if ( | |
| addedNode.matches("mat-snack-bar-container, .mat-mdc-snack-bar-container, .gmat-mdc-snack-bar.cm-snack-bar") | |
| ) { | |
| scheduleDismiss(addedNode); | |
| return; | |
| } | |
| // Otherwise, look for snackbars inside it | |
| var selectorList = [ | |
| "mat-snack-bar-container", | |
| ".mat-mdc-snack-bar-container", | |
| ".gmat-mdc-snack-bar.cm-snack-bar" | |
| ]; | |
| var innerSnackbars = addedNode.querySelectorAll(selectorList.join(",")); | |
| innerSnackbars.forEach(function (innerSnackbar) { | |
| scheduleDismiss(innerSnackbar); | |
| }); | |
| }); | |
| }); | |
| }); | |
| mutationObserver.observe(document.body, { | |
| childList: true, | |
| subtree: true | |
| }); | |
| } | |
| // Initial scan for already visible snackbars | |
| findAndScheduleAll(); | |
| // Watch for snackbars appearing later | |
| observeSnackbars(); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment