mbnuqw / sidebery

Firefox extension for managing tabs and bookmarks in sidebar.
MIT License
3.49k stars 175 forks source link

Prefix/Rename tabs that are in a specific container #1220

Open Makeshift opened 1 year ago

Makeshift commented 1 year ago

Description

I'm using the AWS SSO Containers extension to open multiple AWS consoles with different sets of cookies.

This works fantastically with Sidebery and I have a container set up for each of the AWS accounts: image

However, all of the tabs are named the same thing, and unfortunately there's no extension (currently) that I can find that will either name the tab based on the account, or name the tab based on the container it's in: image

Would it be possible to have Sidebery automatically prefix or rename the tabs that are in a specific container in its sidebar?

Makeshift commented 1 year ago

As a workaround, I wrote a little userscript that adds the account ID as a prefix to the page title:

// ==UserScript==
// @name        Add Account ID to Title on AWS Console
// @match       https://*.console.aws.amazon.com/*
// @grant       unsafeWindow
// @version     1.0
// @author      https://github.com/Makeshift
// @description Adds the account ID of the current account into the page title when using the AWS console
// @run-at      document.end
// @sandbox     JavaScript
// ==/UserScript==

/* There are a few variables that are set in the AWS console that we can use to get useful info.
 The most easily accessible one I found is `window.ConsoleNavService.AccountInfo`, which has the following vars:
{
  "userAccountNumber": Contains a string with the users account in XXXX-XXXX-XXXX format,
  "loginDisplayNameAccount": Contains a string with the users account in XXXX-XXXX-XXXX format,
  "loginDisplayNameUser": If logged in via SSO or cross-account role, contains the temporary role name eg "AWSReservedSSO_role-name_abcd1234/user@example.com",
  "roleDisplayNameAccount": Empty for me, but probably would contain the account name if you were assuming a role,
  "roleDisplayNameUser": Empty for me, but probably would contain the account name if you were assuming a role
}

Chosen var must be resolvable from the global scope, ie `window` (note that the `window` of the loaded page is in the `unsafeWindow` var in a userscript)

Unfortunately I couldn't find anything that contains the account name from AWS SSO, so we default to UserAccountNumber.
*/

function setTitle() {
    try {
        const info = unsafeWindow.ConsoleNavService.AccountInfo.userAccountNumber
        const prefix = `[${info}]`
        if (!document.title.startsWith(prefix)) {
            document.title = `${prefix} ${document.title}`
        }
    } catch (e) {
        setTimeout(setTitle, 1000)
    }
}

setTitle()
jaybhanushali3195 commented 10 months ago

This can happen with the below extension. Would be great if Sideberry can have this as well

https://github.com/mbnuqw/sidebery/issues/1414