BlueCat Address Manager Hotkeys

Add event listener to the UI to call functions on keypress/keydown in BlueCat Address Manager

  1. // ==UserScript==
  2. // @name BlueCat Address Manager Hotkeys
  3. // @namespace *
  4. // @description Add event listener to the UI to call functions on keypress/keydown in BlueCat Address Manager
  5. // @include */app*
  6. // @license MIT
  7. // @version 12
  8. // @grant none
  9. // @author Marius Galm
  10. // @copyright 2018, Marius Galm
  11. // @icon https://www.bluecatnetworks.com/wp-content/uploads/2018/03/cropped-bluecat-favicon-32x32.png
  12. // ==/UserScript==
  13. if (document.readyState === "interactive" ) {
  14. var page = document.childNodes[2].nodeValue;
  15. if (/ Page: ConfigurationPage /.test(page)) {
  16. // No edit or assign in Configuration Page, deploy only
  17. var subtab = document.getElementsByClassName("TabPanelLabelActive")[0];
  18. if (/Servers/.test(subtab.innerHTML.trim())) {
  19. addEventD();
  20. }
  21. } else if (/ Page: ServerPage /.test(page)) {
  22. // Deploy with d in Server Page
  23. addEventD();
  24. } else if (/ Page: IP4NetworkPage /.test(page)) {
  25. // Assign key for ips only in Network Page and Addresses Subtab
  26. // Edit is fine here too
  27. var subtab = document.getElementsByClassName("TabPanelLabelActive")[0];
  28. if (/Addresses/.test(subtab.innerHTML.trim())) {
  29. addEventA();
  30. addEventE();
  31. }
  32. } else {
  33. // selectively activate the edit button
  34. var mainTabs = document.getElementsByClassName("tab-bar active");
  35. if (mainTabs !== undefined) {
  36. var mainTab = mainTabs[0];
  37. if (mainTab !== undefined) {
  38. if (/IP Space/.test(mainTab.innerHTML.trim())) {
  39. addEventE();
  40. } else if (/DNS/.test(mainTab.innerHTML.trim())) {
  41. addEventE();
  42. } else if (/Devices/.test(mainTab.innerHTML.trim())) {
  43. addEventE();
  44. } else if (/Groups/.test(mainTab.innerHTML.trim())) {
  45. addEventE();
  46. }
  47. }
  48. }
  49. }
  50. // check for up to Parent link (everywhere)
  51. var linkButton = document.getElementById("link");
  52. if (linkButton !== undefined) {
  53. if (linkButton.name === "SYSTEMUp_to_Parent") {
  54. addEventU();
  55. }
  56. }
  57. // Tab Hotkeys everywhere
  58. var myIpamTab = document.getElementById("changeCategory");
  59. if (myIpamTab != null && myIpamTab !== undefined) {
  60. // at least MyIPAM is clickable, we're logged in
  61. addEventAlt(1,myIpamTab.href);
  62. var ipSpaceTab = document.getElementById("changeCategory_0");
  63. if (ipSpaceTab != null && ipSpaceTab !== undefined) {
  64. // IP Space Tab Link exists
  65. // Add Alt+2
  66. addEventAlt(2,ipSpaceTab.href);
  67. }
  68. var dnsTab = document.getElementById("changeCategory_1");
  69. if (dnsTab != null && dnsTab !== undefined) {
  70. // DNS Tab Link exists
  71. // Add Alt+3
  72. addEventAlt(3,dnsTab.href);
  73. }
  74. var devicesTab = document.getElementById("changeCategory_2");
  75. if (devicesTab != null && devicesTab !== undefined) {
  76. // Devices Tab Link exists
  77. // Add Alt+4
  78. addEventAlt(4,devicesTab.href);
  79. }
  80. var tftpTab = document.getElementById("changeCategory_3");
  81. if (tftpTab != null && tftpTab !== undefined) {
  82. // TFTP Tab Link exists
  83. // Add Alt+5
  84. addEventAlt(5,tftpTab.href);
  85. }
  86. var serversTab = document.getElementById("changeCategory_4");
  87. if (serversTab != null && serversTab !== undefined) {
  88. // Servers Tab Link exists
  89. // Add Alt+5
  90. addEventAlt(5,serversTab.href);
  91. }
  92. var groupTab = document.getElementById("changeCategory_5");
  93. if (groupTab != null && groupTab !== undefined) {
  94. // Group Tab Link exists
  95. // Add Alt+6
  96. addEventAlt(6,groupTab.href);
  97. }
  98. var adminTab = document.getElementById("changeCategory_6");
  99. if (adminTab != null && adminTab !== undefined) {
  100. // Admin Tab Link exists
  101. // Add Alt+7
  102. addEventAlt(7,adminTab.href);
  103. }
  104. }
  105. // check for Pagination and register left right arrow for navigation
  106. // next
  107. var nextPageButton = document.getElementById("linkNextText");
  108. if (nextPageButton != null && nextPageButton !== undefined) {
  109. addEventNext();
  110. }
  111. // previous
  112. var prevPageButton = document.getElementById("linkPrevText");
  113. if (prevPageButton != null && prevPageButton !== undefined) {
  114. addEventPrev();
  115. }
  116. }
  117.  
  118. //-----------------------
  119. // Functions
  120. //-----------------------
  121.  
  122. // Asssign/Allocate IP Event via a or A key
  123. function addEventA() {
  124. document.addEventListener('keypress', function(e) {
  125. var x = e.key;
  126. // If the pressed keyboard button is "a" or "A" (using caps lock or shift)
  127. if (x == "a" || x == "A") {
  128. var el = document.activeElement;
  129. if (el.type !== "text") {
  130. if (el.type !== "textarea") {
  131. if (el.type !== "search") {
  132. if (el.type !== "input") {
  133. if (el.type !== "password"){
  134. if (el.type !== "select-one") {
  135. //console.log("User pressed 'A' key in 'IPNetwork'");
  136. var selected = document.getElementsByClassName("value-table-selected");
  137. if (selected.length > 0) {
  138. //console.log("call assign on "+selected.length+" addresses");
  139. window.location = "javascript:remoteSubmitLink( document.getElementById( 'form' ), 'SAllocateIP4Address' );";
  140. }
  141. }
  142. }
  143. }
  144. }
  145. }
  146. }
  147. }
  148. });
  149. }
  150.  
  151. // Edit Event via e or E key
  152. function addEventE() {
  153. document.addEventListener('keypress', function(e) {
  154. var x = e.key;
  155. // If the pressed keyboard button is "e" or "E" (using caps lock or shift)
  156. if (x == "e" || x == "E") {
  157. var el = document.activeElement;
  158. if (el.type !== "text") {
  159. if (el.type !== "textarea") {
  160. if (el.type !== "search") {
  161. if (el.type !== "input") {
  162. if (el.type !== "password"){
  163. if (el.type !== "select-one") {
  164. //console.log("User pressed 'E' key in 'Groups' - calling edit function via 'direct' Object Id");
  165. var editButton = document.getElementById('direct');
  166. var link = editButton.href;
  167. window.location = link;
  168. }
  169. }
  170. }
  171. }
  172. }
  173. }
  174. }
  175. });
  176. }
  177.  
  178. // Deploy Event via d or D key
  179. function addEventD() {
  180. document.addEventListener('keypress', function(e) {
  181. var x = e.key;
  182. // If the pressed keyboard button is "d" or "D" (using caps lock or shift)
  183. if (x == "d" || x == "D") {
  184. var el = document.activeElement;
  185. if (el.type !== "text") {
  186. if (el.type !== "textarea") {
  187. if (el.type !== "search") {
  188. if (el.type !== "input") {
  189. if (el.type !== "password"){
  190. if (el.type !== "select-one") {
  191. //console.log("User pressed 'D' key in 'Servers'");
  192. var selected = document.getElementsByClassName("value-table-selected");
  193. if (selected.length > 0) {
  194. //console.log("call assign on "+selected.length+" addresses");
  195. window.location = "javascript:remoteSubmitLink( document.getElementById( 'form' ), 'SDeploy' );";
  196. } else if (/ Page: ServerPage /.test(page)) {
  197. window.location = "javascript:remoteSubmitLink( document.getElementById( 'form' ), 'SDeploy' );";
  198. }
  199. }
  200. }
  201. }
  202. }
  203. }
  204. }
  205. }
  206. });
  207. }
  208.  
  209. // Up to Parent Event via u or U key
  210. function addEventU() {
  211. document.addEventListener('keypress', function(e) {
  212. var x = e.key;
  213. // If the pressed keyboard button is "u" or "U" (using caps lock or shift)
  214. if (x == "u" || x == "U") {
  215. var el = document.activeElement;
  216. if (el.type !== "text") {
  217. if (el.type !== "textarea") {
  218. if (el.type !== "search") {
  219. if (el.type !== "input") {
  220. if (el.type !== "password"){
  221. if (el.type !== "select-one") {
  222. //console.log("User pressed 'D' key in 'Servers'");
  223. var selected = document.getElementById("link");
  224. if (selected !== undefined) {
  225. selected.click();
  226. }
  227. }
  228. }
  229. }
  230. }
  231. }
  232. }
  233. }
  234. });
  235. }
  236.  
  237.  
  238. // Navigation Button Right for Next Page via right arrow key
  239. function addEventNext() {
  240. document.addEventListener('keydown', function(e) {
  241. var x = e.keyCode;
  242. // If the pressed keyboard button is "right arrow"
  243. if (x == "39") {
  244. var el = document.activeElement;
  245. if (el.type !== "text") {
  246. if (el.type !== "textarea") {
  247. if (el.type !== "search") {
  248. if (el.type !== "input") {
  249. if (el.type !== "password"){
  250. if (el.type !== "select-one") {
  251. //console.log("User pressed 'right arrow' key while paging is active;
  252. window.location = "javascript:tapestry.form.submit('form', 'linkNextText');";
  253. }
  254. }
  255. }
  256. }
  257. }
  258. }
  259. }
  260. });
  261. }
  262.  
  263. // Navigation Button Left for Previous Page via left arrow key
  264. function addEventPrev() {
  265. document.addEventListener('keydown', function(e) {
  266. var x = e.keyCode;
  267. // If the pressed keyboard button is "left arrow"
  268. if (x == "37") {
  269. var el = document.activeElement;
  270. if (el.type !== "text") {
  271. if (el.type !== "textarea") {
  272. if (el.type !== "search") {
  273. if (el.type !== "input") {
  274. if (el.type !== "password"){
  275. if (el.type !== "select-one") {
  276. //console.log("User pressed 'left arrow' key while paging is active;
  277. window.location = "javascript:tapestry.form.submit('form', 'linkPrevText');";
  278. }
  279. }
  280. }
  281. }
  282. }
  283. }
  284. }
  285. });
  286. }
  287.  
  288. // Hotkey for each Alt+Number comination
  289. function addEventAlt(tabIndex,link) {
  290. document.addEventListener('keydown', function(e) {
  291. var x = e.key;
  292. // If the pressed keyboard button is both alt and a number 1-7
  293. if (x == tabIndex && e.altKey) {
  294. var el = document.activeElement;
  295. if (el.type !== "text") {
  296. if (el.type !== "textarea") {
  297. if (el.type !== "search") {
  298. if (el.type !== "input") {
  299. if (el.type !== "password"){
  300. if (el.type !== "select-one") {
  301. //console.log(link);
  302. window.location = link;
  303. }
  304. }
  305. }
  306. }
  307. }
  308. }
  309. }
  310.  
  311. });
  312. }