Greasy Fork is available in English.

CodeWhisperer auth

Auto-selects and pastes (if possible) the CodeWhisperer auth code

  1. // ==UserScript==
  2. // @name CodeWhisperer auth
  3. // @namespace urn://https://www.georgegillams.co.uk/api/greasemonkey/codewhisperer-auth
  4. // @include *device.sso.us-east-1.amazonaws.com*
  5. // @include *awsapps.com/start*
  6. // @exclude none
  7. // @version 1.1.0
  8. // @description:en Auto-selects and pastes (if possible) the CodeWhisperer auth code
  9. // @grant none
  10. // @description Auto-selects and pastes (if possible) the CodeWhisperer auth code
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. function closeTab(targetElement) {
  15. const existingButton = document.getElementById(
  16. 'script-added-auto-close-button',
  17. );
  18. if (existingButton) {
  19. existingButton.click();
  20. return;
  21. }
  22.  
  23. const newElement = document.createElement('a');
  24. newElement.id = 'script-added-auto-close-button';
  25. newElement.href = "javascript:window.open('','_self').close();";
  26. newElement.innerText = 'Close';
  27. targetElement.appendChild(newElement);
  28. newElement.click();
  29. }
  30.  
  31. function doTask() {
  32. const codeInputElement = document.getElementById('verification_code');
  33. const buttons = [...document.getElementsByTagName('BUTTON')];
  34. let pasted = false;
  35. if (codeInputElement) {
  36. codeInputElement.focus();
  37. try {
  38. // get clipboard content
  39. const clipboardText = window.clipboardData.getData('Text');
  40. codeInputElement.value = clipboardText;
  41. pasted = true;
  42. } catch (e) {
  43. console.log('Code could not be pasted');
  44. }
  45. }
  46. const [confirmAndContinueButton] = buttons.filter((b) => b.innerText === "Confirm and continue")
  47. confirmAndContinueButton?.click();
  48. const [nextButton] = buttons.filter((b) => b.innerText === 'Next');
  49. if (pasted || codeInputElement?.value?.length === 9) {
  50. nextButton?.click();
  51. }
  52. const [allowButton] = buttons.filter((b) => b.innerText === 'Allow');
  53. allowButton?.click();
  54. if (document.body.innerText.includes('You can close this window')) {
  55. closeTab(document.getElementsByClassName('awsui-signin-success')[0]);
  56. }
  57. }
  58.  
  59. function worker() {
  60. try {
  61. doTask();
  62. } catch (e) {
  63. // eslint-disable-next-line no-console
  64. console.log(e);
  65. }
  66. }
  67.  
  68. setInterval(worker, 200);