AWS-SSO-Auth-Close-Browser-Tab

This script is useful with AWS SSO cli tools, where it opens a browser tab to perform authentication.

Pada tanggal 19 September 2023. Lihat %(latest_version_link).

// ==UserScript==
// @name         AWS-SSO-Auth-Close-Browser-Tab
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  This script is useful with AWS SSO cli tools, where it opens a browser tab to perform authentication.
// @description  This script automatically closes the tab on successful finish.
// @author       John Polansky
// @icon         https://www.google.com/s2/favicons?domain=userscript.zone
// @include      https://d-906769c34d.awsapps.com/*
// @include      https://device.sso.us-east-1.amazonaws.com/*
// @run-at       document-end
// @license      MIT
// @noframes
// @grant window.close
// @grant window.focus
// ==/UserScript==

(function() {
    'use strict';
switch (location.pathname) {
    case "/start/user-consent/authorize.html":
        var evt = document.createEvent ("HTMLEvents");
        evt.initEvent ("click", true, true);
        document.getElementById('cli_login_button').dispatchEvent (evt);
        break;
    case "/":
        let str = location.search
        if (str.match(/user_code=/)?.input) {
          var evt = document.createEvent ("HTMLEvents");
          evt.initEvent ("click", true, true);
          document.getElementById('cli_verification_btn').dispatchEvent (evt);
        }
        break;
    case "/start/user-consent/login-success.html":
        window.close()
        break;
    default:
        console.log("default case executed.. nothing happens");
}

})();