-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBlueCat Address Manager Hotkeys.user.js
312 lines (302 loc) · 12.3 KB
/
BlueCat Address Manager Hotkeys.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
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
302
303
304
305
306
307
308
309
310
311
312
// ==UserScript==
// @name BlueCat Address Manager Hotkeys
// @namespace *
// @description Add event listener to the UI to call functions on keypress/keydown in BlueCat Address Manager
// @include */app*
// @license MIT
// @version 12
// @grant none
// @author Marius Galm
// @copyright 2018, Marius Galm
// @icon https://www.bluecatnetworks.com/wp-content/uploads/2018/03/cropped-bluecat-favicon-32x32.png
// ==/UserScript==
if (document.readyState === "interactive" ) {
var page = document.childNodes[2].nodeValue;
if (/ Page: ConfigurationPage /.test(page)) {
// No edit or assign in Configuration Page, deploy only
var subtab = document.getElementsByClassName("TabPanelLabelActive")[0];
if (/Servers/.test(subtab.innerHTML.trim())) {
addEventD();
}
} else if (/ Page: ServerPage /.test(page)) {
// Deploy with d in Server Page
addEventD();
} else if (/ Page: IP4NetworkPage /.test(page)) {
// Assign key for ips only in Network Page and Addresses Subtab
// Edit is fine here too
var subtab = document.getElementsByClassName("TabPanelLabelActive")[0];
if (/Addresses/.test(subtab.innerHTML.trim())) {
addEventA();
addEventE();
}
} else {
// selectively activate the edit button
var mainTabs = document.getElementsByClassName("tab-bar active");
if (mainTabs !== undefined) {
var mainTab = mainTabs[0];
if (mainTab !== undefined) {
if (/IP Space/.test(mainTab.innerHTML.trim())) {
addEventE();
} else if (/DNS/.test(mainTab.innerHTML.trim())) {
addEventE();
} else if (/Devices/.test(mainTab.innerHTML.trim())) {
addEventE();
} else if (/Groups/.test(mainTab.innerHTML.trim())) {
addEventE();
}
}
}
}
// check for up to Parent link (everywhere)
var linkButton = document.getElementById("link");
if (linkButton !== undefined) {
if (linkButton.name === "SYSTEMUp_to_Parent") {
addEventU();
}
}
// Tab Hotkeys everywhere
var myIpamTab = document.getElementById("changeCategory");
if (myIpamTab != null && myIpamTab !== undefined) {
// at least MyIPAM is clickable, we're logged in
addEventAlt(1,myIpamTab.href);
var ipSpaceTab = document.getElementById("changeCategory_0");
if (ipSpaceTab != null && ipSpaceTab !== undefined) {
// IP Space Tab Link exists
// Add Alt+2
addEventAlt(2,ipSpaceTab.href);
}
var dnsTab = document.getElementById("changeCategory_1");
if (dnsTab != null && dnsTab !== undefined) {
// DNS Tab Link exists
// Add Alt+3
addEventAlt(3,dnsTab.href);
}
var devicesTab = document.getElementById("changeCategory_2");
if (devicesTab != null && devicesTab !== undefined) {
// Devices Tab Link exists
// Add Alt+4
addEventAlt(4,devicesTab.href);
}
var tftpTab = document.getElementById("changeCategory_3");
if (tftpTab != null && tftpTab !== undefined) {
// TFTP Tab Link exists
// Add Alt+5
addEventAlt(5,tftpTab.href);
}
var serversTab = document.getElementById("changeCategory_4");
if (serversTab != null && serversTab !== undefined) {
// Servers Tab Link exists
// Add Alt+5
addEventAlt(5,serversTab.href);
}
var groupTab = document.getElementById("changeCategory_5");
if (groupTab != null && groupTab !== undefined) {
// Group Tab Link exists
// Add Alt+6
addEventAlt(6,groupTab.href);
}
var adminTab = document.getElementById("changeCategory_6");
if (adminTab != null && adminTab !== undefined) {
// Admin Tab Link exists
// Add Alt+7
addEventAlt(7,adminTab.href);
}
}
// check for Pagination and register left right arrow for navigation
// next
var nextPageButton = document.getElementById("linkNextText");
if (nextPageButton != null && nextPageButton !== undefined) {
addEventNext();
}
// previous
var prevPageButton = document.getElementById("linkPrevText");
if (prevPageButton != null && prevPageButton !== undefined) {
addEventPrev();
}
}
//-----------------------
// Functions
//-----------------------
// Asssign/Allocate IP Event via a or A key
function addEventA() {
document.addEventListener('keypress', function(e) {
var x = e.key;
// If the pressed keyboard button is "a" or "A" (using caps lock or shift)
if (x == "a" || x == "A") {
var el = document.activeElement;
if (el.type !== "text") {
if (el.type !== "textarea") {
if (el.type !== "search") {
if (el.type !== "input") {
if (el.type !== "password"){
if (el.type !== "select-one") {
//console.log("User pressed 'A' key in 'IPNetwork'");
var selected = document.getElementsByClassName("value-table-selected");
if (selected.length > 0) {
//console.log("call assign on "+selected.length+" addresses");
window.location = "javascript:remoteSubmitLink( document.getElementById( 'form' ), 'SAllocateIP4Address' );";
}
}
}
}
}
}
}
}
});
}
// Edit Event via e or E key
function addEventE() {
document.addEventListener('keypress', function(e) {
var x = e.key;
// If the pressed keyboard button is "e" or "E" (using caps lock or shift)
if (x == "e" || x == "E") {
var el = document.activeElement;
if (el.type !== "text") {
if (el.type !== "textarea") {
if (el.type !== "search") {
if (el.type !== "input") {
if (el.type !== "password"){
if (el.type !== "select-one") {
//console.log("User pressed 'E' key in 'Groups' - calling edit function via 'direct' Object Id");
var editButton = document.getElementById('direct');
var link = editButton.href;
window.location = link;
}
}
}
}
}
}
}
});
}
// Deploy Event via d or D key
function addEventD() {
document.addEventListener('keypress', function(e) {
var x = e.key;
// If the pressed keyboard button is "d" or "D" (using caps lock or shift)
if (x == "d" || x == "D") {
var el = document.activeElement;
if (el.type !== "text") {
if (el.type !== "textarea") {
if (el.type !== "search") {
if (el.type !== "input") {
if (el.type !== "password"){
if (el.type !== "select-one") {
//console.log("User pressed 'D' key in 'Servers'");
var selected = document.getElementsByClassName("value-table-selected");
if (selected.length > 0) {
//console.log("call assign on "+selected.length+" addresses");
window.location = "javascript:remoteSubmitLink( document.getElementById( 'form' ), 'SDeploy' );";
} else if (/ Page: ServerPage /.test(page)) {
window.location = "javascript:remoteSubmitLink( document.getElementById( 'form' ), 'SDeploy' );";
}
}
}
}
}
}
}
}
});
}
// Up to Parent Event via u or U key
function addEventU() {
document.addEventListener('keypress', function(e) {
var x = e.key;
// If the pressed keyboard button is "u" or "U" (using caps lock or shift)
if (x == "u" || x == "U") {
var el = document.activeElement;
if (el.type !== "text") {
if (el.type !== "textarea") {
if (el.type !== "search") {
if (el.type !== "input") {
if (el.type !== "password"){
if (el.type !== "select-one") {
//console.log("User pressed 'D' key in 'Servers'");
var selected = document.getElementById("link");
if (selected !== undefined) {
selected.click();
}
}
}
}
}
}
}
}
});
}
// Navigation Button Right for Next Page via right arrow key
function addEventNext() {
document.addEventListener('keydown', function(e) {
var x = e.keyCode;
// If the pressed keyboard button is "right arrow"
if (x == "39") {
var el = document.activeElement;
if (el.type !== "text") {
if (el.type !== "textarea") {
if (el.type !== "search") {
if (el.type !== "input") {
if (el.type !== "password"){
if (el.type !== "select-one") {
//console.log("User pressed 'right arrow' key while paging is active;
window.location = "javascript:tapestry.form.submit('form', 'linkNextText');";
}
}
}
}
}
}
}
});
}
// Navigation Button Left for Previous Page via left arrow key
function addEventPrev() {
document.addEventListener('keydown', function(e) {
var x = e.keyCode;
// If the pressed keyboard button is "left arrow"
if (x == "37") {
var el = document.activeElement;
if (el.type !== "text") {
if (el.type !== "textarea") {
if (el.type !== "search") {
if (el.type !== "input") {
if (el.type !== "password"){
if (el.type !== "select-one") {
//console.log("User pressed 'left arrow' key while paging is active;
window.location = "javascript:tapestry.form.submit('form', 'linkPrevText');";
}
}
}
}
}
}
}
});
}
// Hotkey for each Alt+Number comination
function addEventAlt(tabIndex,link) {
document.addEventListener('keydown', function(e) {
var x = e.key;
// If the pressed keyboard button is both alt and a number 1-7
if (x == tabIndex && e.altKey) {
var el = document.activeElement;
if (el.type !== "text") {
if (el.type !== "textarea") {
if (el.type !== "search") {
if (el.type !== "input") {
if (el.type !== "password"){
if (el.type !== "select-one") {
//console.log(link);
window.location = link;
}
}
}
}
}
}
}
});
}