Created
April 2, 2025 20:22
-
-
Save glesperance/6c0b80b5f068690e0eeecdd29d101e9f to your computer and use it in GitHub Desktop.
Thoropass GCP Account Permission Setup
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
async function typeStringsWithDelay(stringsToType) { | |
console.log('Starting 10 second initial delay...'); | |
await new Promise(resolve => setTimeout(resolve, 10000)); | |
console.log('Checking focused element...'); | |
const activeElement = document.activeElement; | |
if (!activeElement) { | |
console.error('β No element is focused'); | |
return; | |
} | |
console.log('π Focused element:', { | |
tagName: activeElement.tagName, | |
id: activeElement.id, | |
className: activeElement.className, | |
isContentEditable: activeElement.isContentEditable, | |
type: activeElement.type | |
}); | |
function insertText(text) { | |
if (activeElement instanceof HTMLInputElement || activeElement instanceof HTMLTextAreaElement) { | |
const start = activeElement.selectionStart; | |
const end = activeElement.selectionEnd; | |
const currentValue = activeElement.value; | |
activeElement.value = currentValue.substring(0, start) + text + currentValue.substring(end); | |
activeElement.selectionStart = activeElement.selectionEnd = start + text.length; | |
} else if (activeElement.isContentEditable) { | |
const selection = window.getSelection(); | |
const range = selection.getRangeAt(0); | |
const textNode = document.createTextNode(text); | |
range.deleteContents(); | |
range.insertNode(textNode); | |
range.setStartAfter(textNode); | |
range.setEndAfter(textNode); | |
selection.removeAllRanges(); | |
selection.addRange(range); | |
} else { | |
console.error('β Element is neither input/textarea nor contenteditable'); | |
return false; | |
} | |
return true; | |
} | |
for (const str of stringsToType) { | |
console.log(`\nπ€ Starting to type string: "${str}"`); | |
for (const char of str) { | |
try { | |
if (!insertText(char)) { | |
return; | |
} | |
activeElement.dispatchEvent(new Event('input', { | |
bubbles: true, | |
cancelable: true | |
})); | |
['keydown', 'keypress', 'keyup'].forEach(eventType => { | |
activeElement.dispatchEvent(new KeyboardEvent(eventType, { | |
key: char, | |
code: `Key${char.toUpperCase()}`, | |
bubbles: true, | |
cancelable: true, | |
composed: true | |
})); | |
}); | |
} catch (error) { | |
console.error(`β Error while typing character "${char}":`, error); | |
} | |
await new Promise(resolve => setTimeout(resolve, 1)); | |
} | |
console.log('\nβ©οΈ Simulating Enter key...'); | |
try { | |
insertText('\n'); | |
['keydown', 'keypress', 'keyup'].forEach(eventType => { | |
activeElement.dispatchEvent(new KeyboardEvent(eventType, { | |
key: 'Enter', | |
code: 'Enter', | |
bubbles: true, | |
cancelable: true, | |
composed: true | |
})); | |
}); | |
} catch (error) { | |
console.error('β Error while simulating Enter key:', error); | |
} | |
// Changed from 10000 to 1000 (1 second) | |
console.log(`\nβ³ Waiting 1 second before next string...`); | |
await new Promise(resolve => setTimeout(resolve, 100)); | |
} | |
console.log('\nβ Typing sequence completed!'); | |
} | |
// Example usage with logging: | |
console.log('π Starting the typing automation...'); | |
console.log('β οΈ You have 10 seconds to focus the desired element...'); | |
typeStringsWithDelay([ | |
'"cloudbuild.builds.get"', 'OR', | |
'"cloudbuild.builds.list"', 'OR', | |
'"cloudkms.keyRings.list"', 'OR', | |
'"cloudkms.cryptoKeys.list"', 'OR', | |
'"cloudsql.backupRuns.list"', 'OR', | |
'"cloudsql.instances.get"', 'OR', | |
'"cloudsql.instances.list"', 'OR', | |
'"compute.autoscalers.list"', 'OR', | |
'"compute.disks.list"', 'OR', | |
'"compute.firewalls.list"', 'OR', | |
'"compute.images.list"', 'OR', | |
'"compute.instanceGroups.list"', 'OR', | |
'"compute.instances.list"', 'OR', | |
'"compute.projects.get"', 'OR', | |
'"container.clusters.list"', 'OR', | |
'"iam.roles.get"', 'OR', | |
'"iam.roles.list"', 'OR', | |
'"iam.serviceAccounts.get"', 'OR', | |
'"iam.serviceAccounts.getIamPolicy"', 'OR', | |
'"iam.serviceAccounts.list"', 'OR', | |
'"logging.buckets.list"', 'OR', | |
'"monitoring.alertPolicies.list"', 'OR', | |
'"monitoring.notificationChannels.get"', 'OR', | |
'"monitoring.notificationChannels.list"', 'OR', | |
'"recommender.cloudsqlIdleInstanceRecommendations.get"', 'OR', | |
'"resourcemanager.projects.get"', 'OR', | |
'"resourcemanager.projects.getIamPolicy"', 'OR', | |
'"resourcemanager.folders.getIamPolicy"', 'OR', | |
'"resourcemanager.organizations.getIamPolicy"', 'OR', | |
'"serviceusage.services.get"', 'OR', | |
'"serviceusage.services.list"', 'OR', | |
'"storage.buckets.list"', 'OR', | |
'"resourcemanager.organizations.get"', | |
]).then(() => { | |
console.log('π All done!'); | |
}).catch(error => { | |
console.error('β Something went wrong:', error); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment