Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save glesperance/6c0b80b5f068690e0eeecdd29d101e9f to your computer and use it in GitHub Desktop.
Save glesperance/6c0b80b5f068690e0eeecdd29d101e9f to your computer and use it in GitHub Desktop.
Thoropass GCP Account Permission Setup
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