Skip to content

Commit

Permalink
Implement role filter (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
tilfin authored Nov 17, 2018
1 parent 5173451 commit ba57290
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "AWS Extend Switch Roles",
"version": "0.9.0",
"version": "0.10.0",
"description": "Extend your AWS IAM switching roles. You can set the configuration like aws config format",
"short_name": "Extend SwitchRole",
"permissions": ["storage"],
Expand Down
2 changes: 1 addition & 1 deletion manifest_firefox.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.9.1",
"version": "0.10.0",
"applications": {
"gecko": {
"id": "[email protected]",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aws-extend-switch-roles",
"version": "0.8.1",
"version": "0.10.0",
"description": "Extend your AWS IAM switching roles by Chrome extension",
"main": "index.js",
"directories": {
Expand Down
36 changes: 36 additions & 0 deletions src/lib/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,42 @@ function loadProfiles(profile, list, csrf, hidesHistory, hidesAccountId) {
hookBeforeExit(this);
});
}

// Place role filter textinput
var AWSR_firstForm = null;

document.getElementById('awsc-recent-roles-label').insertAdjacentHTML('beforeend', '<input id="AESR_RoleFilter" type="text" placeholder="Filter by profile name" style="border:1px solid #ccc;border-radius:3px;font-size:13px;margin-left:0.25em;max-width:20ex;padding:0.4ex">');

document.getElementById('AESR_RoleFilter').onkeyup = function(e) {
const str = this.value;
if (e.keyCode === 13) {
if (AWSR_firstForm) {
AWSR_firstForm.querySelector('input[type="submit"]').click()
}
} else {
const lis = Array.from(document.querySelectorAll('#awsc-username-menu-recent-roles > li'));
let firstHitLi = null;
lis.forEach(li => {
const profileName = li.firstElementChild.dataset.aesrProfile.toLowerCase();
const hit = str ? profileName.indexOf(str) > -1 : false;
const shown = str ? hit : true;
li.style.display = shown ? 'block' : 'none';
li.style.background = null;
if (hit && firstHitLi === null) firstHitLi = li;
});

if (firstHitLi) {
firstHitLi.style.background = '#f0f9ff';
AWSR_firstForm = firstHitLi.querySelector('form');
} else {
AWSR_firstForm = null;
}
}
}

document.getElementById('nav-usernameMenu').addEventListener('click', () => {
document.getElementById('AESR_RoleFilter').focus()
})
}

function attachColorLine(profiles) {
Expand Down

0 comments on commit ba57290

Please sign in to comment.