-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
301 lines (275 loc) · 14.1 KB
/
index.html
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
<html>
<head>
<title>AWSX</title>
<link rel="stylesheet" href="css/chrome-tabs.css">
<link rel="stylesheet" href="css/chrome-tabs-dark-theme.css">
<!--<link rel="stylesheet" href="node_modules/electron-tabs/electron-tabs.css">
<link rel="stylesheet" href="node_modules/dist/dragula.css">-->
<script>oldModule = module;module = {};</script>
<script src="http://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://unpkg.com/draggabilly@2/dist/draggabilly.pkgd.js"></script>
<script src="js/chrome-tabs.js"></script>
<script>module = oldModule;</script>
<!--<script src="js/draggabillity.js"></script>-->
<style>
html, body { margin:0;padding:0; }
h1, h2, h3, h4, h5, h6, p, button { font-family:'Helvetica-Neue', Arial, sans-serif; }
.sidebar { position:absolute;top:0;left:0;width:64px;bottom:0;background-color:#232f3e;padding:10px 0; }
.sidebar-item { margin:10px 0;font-family:'Helvetica-Neue', Arial, sans-serif;text-align:center;font-size:12px;color:rgba(255,255,255,0.5); }
.sidebar-button { opacity:0.5;width:36px;height:36px;margin:5px auto;cursor:pointer;box-sizing:content-box;border:2px solid transparent;border-radius:10px;color:white;font-size:12px;font-weight:400;line-height:38px; }
.sidebar-item:nth-child(1) .sidebar-button { background-color:#DC965A; }
.sidebar-item:nth-child(2) .sidebar-button { background-color:#A9E4EF; }
.sidebar-item:nth-child(3) .sidebar-button { background-color:#A288E3; }
.sidebar-item:nth-child(4) .sidebar-button { background-color:#7A306C; }
.sidebar-item:nth-child(5) .sidebar-button { background-color:#81F495; }
.sidebar-item:nth-child(6) .sidebar-button { background-color:#FF6978; }
.sidebar-item:nth-child(7) .sidebar-button { background-color:#FFED66; }
.sidebar-item:nth-child(8) .sidebar-button { background-color:#00CECB; }
.sidebar-item .sidebar-button:hover { box-shadow: 0 0 0 4pt rgba(255,255,255,0.5);border-color:transparent; }
.sidebar-item.active .sidebar-button { opacity:1;color:black; }
.sidebar-item.new-session .sidebar-button { background-color:white;color:black;border-color:transparent;box-shadow:none;font-size:28px; }
.sidebar-item.new-session:hover { opacity:0.75; }
.maincontent { position:absolute;top:0;left:64px;right:0;bottom:0; }
.chrome-tab-group { position:absolute;top:0;left:0;right:0;bottom:0; }
.chrome-tab-group.hide { visibility:hidden }
.chrome-tabs { border-radius:0 !important; }
.chrome-tabs-new-tab { position:absolute;top:0;right:0;width:42px;height:42px;cursor:pointer;overflow:hidden;text-align:center;color:white;font-size:22px;line-height:36px; }
.content-container { position:absolute;top:42px;left:0;right:0;bottom:0;background-color:white; }
.content-container>webview { position:absolute;left:0;top:0;right:0;bottom:0;border:none; }
.content-container>webview.hide { visibility:hidden }
.tabinfo { position:absolute;top:0;left:64px;right:0;bottom:0;background-color:#f9fafc;z-index:99;padding:25vh 0 0 33vw; }
.tabinfo.hide { display:none; }
.tabinfo>h1, .tabinfo>h5, .tabinfo>p { margin:0;padding:0;color:#232f3e;opacity:0.25; }
.tabinfo>input { min-width:33%;border:none;background-color:transparent;font-family:'Helvetica-Neue', Arial, sans-serif;font-size:32px;outline:none;border-bottom:2px dashed #232f3e;opacity:0.5; }
.tabinfo>button { opacity:0.75;padding:12px;min-width:148px;min-height:48px;background-color:#DC965A;color:white;border:none;border-radius:8px;font-size:16px;font-weight:600;outline:none; }
.tabinfo>button:hover { opacity:1; }
.colors { max-width:320px;padding:30px 0; }
.colorbox { opacity:0.65;display:inline-block;width:40px;height:40px;margin:15px 15px 0 0;border-radius:8px;border:5px solid transparent; }
.colorbox.active { opacity:1;border-color:rgba(255,255,255,0.5); }
.colorbox:hover { opacity:1 }
.colorbox:nth-child(1) { background-color:#DC965A; }
.colorbox:nth-child(2) { background-color:#A9E4EF; }
.colorbox:nth-child(3) { background-color:#A288E3; }
.colorbox:nth-child(4) { background-color:#7A306C; }
.colorbox:nth-child(5) { background-color:#81F495; }
.colorbox:nth-child(6) { background-color:#FF6978; }
.colorbox:nth-child(7) { background-color:#FFED66; }
.colorbox:nth-child(8) { background-color:#00CECB; }
::placeholder { color: rgba(0,0,0,0.1);opacity: 1; }
:-ms-input-placeholder { color: rgba(0,0,0,0.1); }
::-ms-input-placeholder { color: rgba(0,0,0,0.1); }
</style>
</head>
<body>
<div class="sidebar">
<div class="accounts">
<div class="sidebar-item template"><div class="sidebar-button"></div><span class="sidebar-shortcut">⌘1</span></div>
</div>
<div class="sidebar-item new-session"><div class="sidebar-button">+</div></div>
</div>
<div class="maincontent">
<div class="chrome-tab-group">
<div class="chrome-tabs chrome-tabs-dark-theme">
<div class="chrome-tabs-content"></div>
<div class="chrome-tabs-new-tab">+</div>
<div class="chrome-tabs-bottom-bar"></div>
</div>
<div class="content-container">
</div>
</div>
</div>
<div class="tabinfo">
<h1>Add new account</h1>
<h5>Enter an name for your account. Initials or very short names work best.</h5>
<br/><br/>
<input id="new-account-name" placeholder="NAME" />
<div id="new-account-color" class="colors">
<div class="colorbox active" data-color="#DC965A"></div>
<div class="colorbox" data-color="#A9E4EF"></div>
<div class="colorbox" data-color="#A288E3"></div>
<div class="colorbox" data-color="#7A306C"></div>
<div class="colorbox" data-color="#81F495"></div>
<div class="colorbox" data-color="#FF6978"></div>
<div class="colorbox" data-color="#FFED66"></div>
<div class="colorbox" data-color="#00CECB"></div>
</div>
<button id="new-account-go">ADD</button>
</div>
<script>
const ipc = require('electron').ipcRenderer;
function guid() {
function s4() { return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1); }
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
}
var accounts = {};
window.addEventListener('load', function(){
// Detach chrome tab group template
var tabGroupTemplate = $('.chrome-tab-group').detach();
var sidebarButtonTemplate = $('.sidebar-item.template').detach().removeClass('template');
function createTabGroup(groupid, name, color) {
var groupUid = groupid||guid();
// Initialize group storage
accounts[groupUid] = accounts[groupUid]||{};
var account = accounts[groupUid];
account.name = name;
account.color = color;
// Create the tab group
account.tabGroup = tabGroupTemplate.clone();
var el = account.tabGroup.find('.chrome-tabs')[0];// document.querySelector('.chrome-tabs');
$('.maincontent').children().addClass('hide');
$('.maincontent').append(account.tabGroup);
account.chromeTabs = new ChromeTabs();
account.chromeTabs.init(el, { tabOverlapDistance: 14, minWidth: 45, maxWidth: 243 });
el.account = account;
// Create sidebar button
account.sidebarItem = sidebarButtonTemplate.clone();
$('.accounts').append(account.sidebarItem);
$('.sidebar-item').removeClass('active');
account.sidebarItem.addClass('active');
account.sidebarItem.find('.sidebar-button').text(name);
account.sidebarItem.find('.sidebar-button').css({'background-color': color});
account.sidebarItem.find('.sidebar-shortcut').text( '⌘'+$('.accounts').children().length );
account.sidebarItem.on('click', function() {
$('.maincontent').children().addClass('hide');
$(account.tabGroup).removeClass('hide');
$('.sidebar-item').removeClass('active');
$(account.sidebarItem).addClass('active');
$('.tabinfo').addClass('hide');
});
el.addEventListener('activeTabChange', ({ detail }) => {
console.log('Active tab changed', detail.tabEl)
$(account.tabGroup).find('.content-container').children().addClass('hide');
$(detail.tabEl.webview).removeClass('hide');
});
el.addEventListener('tabAdd', ({ detail }) => {
console.log('Tab added', detail.tabEl)
detail.tabEl.webview = document.createElement('webview');
detail.tabEl.webview.partition = "persist:"+groupUid;
detail.tabEl.webview.disablewebsecurity = true;
detail.tabEl.webview.webpreferences = "allowRunningInsecureContent";
detail.tabEl.webview.setAttribute('src', "https://us-west-2.console.aws.amazon.com/console/home?region=us-west-2#");
detail.tabEl.webview.style.width = '100%';
detail.tabEl.webview.style.height = '100%';
detail.tabEl.webview.addEventListener('page-title-updated', (e) => {
console.log('Guest page title: '+e.title);
detail.tabEl.querySelector('.chrome-tab-title').textContent = e.title;
// Trigger save of account session
window.getAccounts();
});
$(account.tabGroup).find('.content-container').children().addClass('hide');
$(detail.tabEl.webview).removeClass('hide');
$(account.tabGroup).find('.content-container').append(detail.tabEl.webview);
});
el.addEventListener('tabRemove', ({ detail }) => {
console.log('Tab removed', detail.tabEl);
$(account.tabGroup).find('.content-container').children().addClass('hide');
$(detail.tabEl.webview).detach();
delete( detail.tabEl.webview );
detail.tabEl.webview = null;
var newTab = el.querySelector('.chrome-tab-current');
if ( newTab && newTab.webview ) {
account.chromeTabs.setCurrentTab(newTab);
$(newTab.webview).removeClass('hide');
}
// Trigger save of account session
window.getAccounts();
});
$(el).find('.chrome-tabs-new-tab').click(function() {
el.account.chromeTabs.addTab({ title: 'AWS', favicon: 'images/aws.png' });
});
if ( !groupid ) account.chromeTabs.addTab({ title: 'AWS', favicon: 'images/aws.png' });
return account;
}
// Create new tab group on click
$('.sidebar-item.new-session').click(function() {
//createTabGroup(null, 'AWS', '#12ABCD');
$('#new-account-name').val('');
$($('#new-account-color').children().removeClass('active').get(0)).addClass('active');
$('.tabinfo').removeClass('hide');
});
$('#new-account-color').find('.colorbox').on('click', function() {
$('.colorbox').removeClass('active');
$(this).addClass('active');
$('#new-account-name').css({'color':$('.colorbox.active').attr('data-color')});
$('#new-account-go').css({'background-color':$('.colorbox.active').attr('data-color')});
});
$('#new-account-go').on('click', function() {
$('#new-account-name').css({'color':$('.colorbox.active').attr('data-color')});
$('#new-account-go').css({'background-color':$('.colorbox.active').attr('data-color')});
if ( $('#new-account-name').val().length ) {
var account = createTabGroup(null, $('#new-account-name').val(), $('.colorbox.active').attr('data-color'));
$('.maincontent').children().addClass('hide');
$(account.tabGroup).removeClass('hide');
$('.sidebar-item').removeClass('active');
$(account.sidebarItem).addClass('active');
$('.tabinfo').addClass('hide');
}
});
window.getAccounts = function() {
//return JSON.stringify(accounts);
// Update active tabs
for ( var groupId in accounts ) {
var tabs = $(accounts[groupId].tabGroup).find('.content-container').children();
accounts[groupId].tabs = [];
for ( var idx in tabs ) {
if ( tabs[idx].src ) accounts[groupId].tabs.push( tabs[idx].src );
}
}
ipc.send('message', {action: 'getAccounts', accounts: accounts});
// TMP
//window.setAccounts(accounts);
}
window.setAccounts = function(oldAccounts) {
$('.maincontent').empty();
$('.sidebar .accounts').empty();
if ( Object.keys(oldAccounts).length ) $('.tabinfo').addClass('hide');
for ( var groupId in oldAccounts ) {
var account = oldAccounts[groupId];
delete( account.chromeTabs );
delete( account.tabGroup );
delete( account.sidebarItem );
createTabGroup(groupId, account.name, account.color);
var newAccount = accounts[groupId];
// Recreate tabs
for ( var idx in oldAccounts[groupId].tabs ) {
newAccount.chromeTabs.addTab({ title: 'AWS', favicon: 'images/aws.png' });
var tab = $(newAccount.tabGroup).find('.content-container').children().get(idx);
tab.src = oldAccounts[groupId].tabs[idx];
}
}
}
ipc.on('message', (event, message) => {
try {
if ( message && message.action ) {
var currTab = $('.chrome-tab-group:not(.hide) .chrome-tab.chrome-tab-current').closest('.chrome-tabs').get(0);
if ( currTab ) {
var actualTab = currTab.querySelector('.chrome-tab-current');
switch( message.action ) {
case 'newTab': currTab.account.chromeTabs.addTab({ title: 'AWS', favicon: 'images/aws.png', }); break;
case 'closeTab': currTab.account.chromeTabs.removeTab(currTab); break;
case 'reloadTab': if ( actualTab ) actualTab.webview.reload(); break;
case 'addAccount': $('.sidebar-item.new-session').click(); break;
case 'setAccount1': $($('.accounts').children().get(0)).click(); break;
case 'setAccount2': $($('.accounts').children().get(1)).click(); break;
case 'setAccount3': $($('.accounts').children().get(2)).click(); break;
case 'setAccount4': $($('.accounts').children().get(3)).click(); break;
case 'setAccount5': $($('.accounts').children().get(4)).click(); break;
case 'setAccount6': $($('.accounts').children().get(5)).click(); break;
case 'setAccount7': $($('.accounts').children().get(6)).click(); break;
case 'setAccount8': $($('.accounts').children().get(7)).click(); break;
case 'setAccount9': $($('.accounts').children().get(8)).click(); break;
case 'getAccounts': window.getAccounts(); break;
case 'setAccounts': window.setAccounts(message.accounts); break;
default:
break;
}
}
}
} catch(e) {
console.error(e);
}
});
});
</script>
</body>
</html>