Skip to content

Instantly share code, notes, and snippets.

@muness
Created December 17, 2025 18:52
Show Gist options
  • Select an option

  • Save muness/a1d2dda6ae0d565c8af4cbaeb2d4d3c3 to your computer and use it in GitHub Desktop.

Select an option

Save muness/a1d2dda6ae0d565c8af4cbaeb2d4d3c3 to your computer and use it in GitHub Desktop.
Google Cloud Console Project + User default
// ==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