-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaws-saml-filter.user.js
173 lines (149 loc) · 4.47 KB
/
aws-saml-filter.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// ==UserScript==
// @name AWS-SAML-SSO-filter
// @namespace signin.aws.amazon.com
// @description Adds account list filter to AWS SSO sign-in page
// @include https://signin.aws.amazon.com/saml
// @version 1.01
// @grant none
// ==/UserScript==
window.clearSearch = function () {
$("#searchbox > input").val("");
$("#searchbox > input").focus();
$("#searchbox > input").keyup();
};
$("#saml_form > p").before(
'<div id="searchbar">\
<div id="searchbox">\
<input type="text" placeholder="Filter accounts and roles...">\
</div>\
<div id="button_container">\
<a id="clear_button" class="css3button" href="#" onClick=window.clearSearch() style="display: inline;">Clear</a>\
</div>\
</div>\
<div id="hint">Filter is case-insensitive and ignores dashes \'-\'. Press <b>enter</b> to sign in when your filter returns only one role.</div>'
);
$("#saml_form > p").hide();
$("#searchbar").css("display", "flex");
$("#button_container").css("padding", "24px 0 0 8px");
$("#searchbox").css("margin", "5px");
$("#searchbox").css("padding", "8px 32px");
$("#searchbox").css("width", "100%");
$("#searchbox > input").css("width", "100%");
$("#searchbox > input").css("padding", "8px 16px");
$("#searchbox > input").focus();
$("#hint").css("padding", "0 56px 12px");
$("#hint").css("margin-top", "-8px");
$("#hint").css("color", "lightgray");
$("#input_signin_button").before('<div id="filter-error"></div>');
$("#filter-error").css("padding", "0px 32px 32px");
$("#filter-error").css("font-size", "16px");
$(document).keypress(function (e) {
if (e.which === 13) {
$("form#saml_form").submit();
}
});
$("#searchbox > input").keydown(function (e) {
if (e.which === 13) {
var visibleRoles = $(
"fieldset > div.saml-account:visible > div.saml-account > div.saml-role:visible"
);
event.preventDefault();
if (visibleRoles.size() === 1) {
$("form#saml_form").submit();
}
}
});
$("#searchbox > input").keyup(function (e) {
if (e.which === 40) {
$(
"fieldset > div.saml-account:visible > div.saml-account > div.saml-role:visible"
)
.first()
.children("input")
.focus();
$(
"fieldset > div.saml-account:visible > div.saml-account > div.saml-role:visible"
)
.first()
.children("input")
.prop("checked", true);
return;
}
if ($(this).val() === "") {
$("fieldset > div.saml-account").show();
} else {
var keyword = $(this).val().replaceAll("-", "").toLowerCase();
$("fieldset > div.saml-account").each(function () {
var roles = $(this).children(".saml-account").children(".saml-role");
roles.each(function () {
$(this).show();
});
$(this).show();
var accountName = $(this)
.find(".saml-account-name")
.text()
.replaceAll("-", "")
.toLowerCase();
var accountNameMatch = accountName.indexOf(keyword) !== -1;
if (accountNameMatch) {
return;
}
var roleNamesConcat = $(this)
.find(".saml-role-description")
.text()
.replaceAll("-", "")
.toLowerCase();
var searchRoles = roleNamesConcat.indexOf(keyword) !== -1;
if (searchRoles) {
roles.each(function () {
var roleName = $(this)
.find(".saml-role-description")
.text()
.replaceAll("-", "")
.toLowerCase();
if (roleName.indexOf(keyword) !== -1) {
$(this).show();
} else {
$(this).hide();
}
});
return;
}
$(this).hide();
});
}
$("#signin_button").show();
var visibleAccounts = $("fieldset > div.saml-account:visible");
var visibleRoles = $(
"fieldset > div.saml-account:visible > div.saml-account > div.saml-role:visible"
);
if (visibleRoles.size() === 1) {
checkRadio(visibleRoles[0]);
} else {
$("input:radio").attr("checked", false);
}
if (visibleAccounts.size() > 0) {
document.getElementById("filter-error").innerHTML = "";
} else {
document.getElementById(
"filter-error"
).innerHTML = `No accounts containing <b>${$(this).val()}</b> found.`;
$("#signin_button").hide();
}
});
window.addEventListener(
"load",
() => {
[].forEach.call(
document.querySelectorAll("#saml_form input[name=roleIndex]"),
(el) => {
el.onclick = (e) => {
if (e.clientX !== 0 && e.clientY !== 0) {
el.form.submit();
}
};
}
);
},
false
);