Created
December 17, 2025 18:52
-
-
Save muness/a1d2dda6ae0d565c8af4cbaeb2d4d3c3 to your computer and use it in GitHub Desktop.
Google Cloud Console Project + User default
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 GCP Auto Project & User Selector | |
| // @namespace http://tampermonkey.net/ | |
| // @version 1.0 | |
| // @description Automatically sets the project and authuser in GCP Console URLs | |
| // @author You | |
| // @match https://console.cloud.google.com/* | |
| // @grant none | |
| // @run-at document-start | |
| // ==/UserScript== | |
| (function() { | |
| 'use strict'; | |
| const TARGET_PROJECT = 'innov-connector-720215328878'; | |
| const TARGET_USER = '1'; | |
| function updateURL() { | |
| const url = new URL(window.location.href); | |
| let updated = false; | |
| // Check if project is missing or incorrect | |
| if (url.searchParams.get('project') !== TARGET_PROJECT) { | |
| url.searchParams.set('project', TARGET_PROJECT); | |
| updated = true; | |
| } | |
| // Check if authuser is missing or incorrect | |
| if (url.searchParams.get('authuser') !== TARGET_USER) { | |
| url.searchParams.set('authuser', TARGET_USER); | |
| updated = true; | |
| } | |
| if (updated) { | |
| // Replace the current state so we don't break the 'Back' button history | |
| window.location.replace(url.href); | |
| } | |
| } | |
| // Run on initial load | |
| updateURL(); | |
| // Monitor for URL changes (common in GCP's Single Page App architecture) | |
| let lastUrl = location.href; | |
| new MutationObserver(() => { | |
| if (location.href !== lastUrl) { | |
| lastUrl = location.href; | |
| updateURL(); | |
| } | |
| }).observe(document, {subtree: true, childList: true}); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment