AWS-SSO-Console-User-Title-IAM-Alias

Inspired by https://greasyfork.org/en/scripts/430620-aws-sso-console-user-title-fix but modified to require less maintenence

Stan na 31-01-2023. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         AWS-SSO-Console-User-Title-IAM-Alias
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  Inspired by https://greasyfork.org/en/scripts/430620-aws-sso-console-user-title-fix but modified to require less maintenence
// @author       Nick Carpenter
// @include      https://console.aws.amazon.*
// @include      https://*.console.aws.amazon.*
// @run-at       document-end
// @inject-into content
// @license      MIT
// @noframes
// @grant window.close
// @grant window.focus
// ==/UserScript==

function assert(condition, message) {
    if (!condition) {
        throw message || "Assertion failed";
    }
}


(function() {
    'use strict';
    // console.log("======================================================")
    // The query selector might need to change.  But this is trying to find the span inside the button.
    let nodes = document.querySelectorAll('[data-testid="awsc-nav-account-menu-button"]')
    assert(nodes.length == 1, "Could not find proper span")
    let str = nodes[0].children[0].title

    // console.log(`Element: ${str})
    let re = /\w+_(\w+)_(\w+)\/(.*)\s+@\s+(.+)/
    let results = re.exec(str)
    assert (results!=null, "String contents from span title attribute was not parsed properly by regular expression")
    let role = results[1]
    let username = results[3]
    let account = results[4]
    // console.log(`Username: ${username}  Account: ${account}  Role: ${role}`)
    // console.log("======================================================")
    button.children[0].children[0].innerText = `${account} / ${role} / ${username}`
})();