-
Notifications
You must be signed in to change notification settings - Fork 2
/
script.js
50 lines (45 loc) · 1.57 KB
/
script.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
// Code goes here
var bookmarklet = function(roleName, account, displayName, color) {
if (window.AWSC == undefined || window.AWSC.Auth == undefined) {
alert('Please go to the AWS Console to use this bookmark.');
return;
}
var p = {
"roleName": roleName,
"account": account,
"displayName": displayName,
"color": color,
"action": "switchFromBasis",
"src": "nav",
"mfaNeeded": 0,
"csrf": window.AWSC.Auth.getMbtc(),
"redirect_uri": escape(window.location.href)
};
var f = document.createElement("form");
f.setAttribute("method", "post");
f.setAttribute("action", "https://signin.aws.amazon.com/switchrole");
for (var k in p) {
if (p.hasOwnProperty(k)) {
var i = document.createElement("input");
i.setAttribute("type", "hidden");
i.setAttribute("name", k);
i.setAttribute("value", p[k]);
f.appendChild(i);
}
}
document.body.appendChild(f);
f.submit();
}
function gen(roleName, account, displayName, color) {
var code = '(' + bookmarklet + ')("' + roleName + '","' + account + '","' + displayName + '","' + color + '")';
var href = 'javascript:' + escape(code.replace(/\s+/g, ' '));
var textnode = document.createTextNode(displayName);
var node = document.createElement("a");
node.setAttribute("href", href);
node.appendChild(textnode);
node.setAttribute("class", "bookmarklet");
node.setAttribute("style", "background-color: #" + color + ";");
var linkContainer = document.getElementById("linkContainer");
linkContainer.innerHTML = '';
linkContainer.appendChild(node);
}