BlueCat Address Manager Auto-Switch to Tagged Objects

Automatically switch to Tagged Objects if no SubTags exist in BlueCat Address Manager

  1. // ==UserScript==
  2. // @name BlueCat Address Manager Auto-Switch to Tagged Objects
  3. // @namespace *
  4. // @description Automatically switch to Tagged Objects if no SubTags exist in BlueCat Address Manager
  5. // @include */app*
  6. // @exclude */app*sp=ScontextId%3Dtag
  7. // @license MIT
  8. // @version 4
  9. // @grant none
  10. // @copyright 2018, Marius Galm
  11. // @license MIT
  12. // @icon https://www.bluecatnetworks.com/wp-content/uploads/2018/03/cropped-bluecat-favicon-32x32.png
  13. // ==/UserScript==
  14.  
  15.  
  16. // give up after 5 tries = 2,5 sec
  17. var k = 0, howManyTimes = 5;
  18. function getNodes() {
  19. var count = k+1;
  20. console.log(" + looking for nodes "+count+"/"+howManyTimes);
  21. var nodes = document.getElementsByClassName("TreeNode").length;
  22. k++;
  23. if(( k < howManyTimes )&&(nodes === 0)){
  24. setTimeout( getNodes, 500 );
  25. }
  26. else if ((k === howManyTimes)&&(nodes === 0)) {
  27. document.getElementById("contextTabLink_1").click();
  28. } else {
  29. //console.log("nothing to do");
  30. return;
  31. }
  32. };
  33.  
  34.  
  35. // Exclude Pattern will prevent endless loop :-)
  36. if (document.readyState === "interactive" ) {
  37. var page = document.childNodes[2].nodeValue;
  38. if (/ Page: Tags /.test(page)) {
  39. // check subtab, should only be executed on Tags not Tagged Objects
  40. var subtab = document.getElementsByClassName("TabPanelLabelActive")[0];
  41. if (subtab.innerText === "Tags") {
  42. var info = document.getElementById("informal");
  43. if ((info !== undefined)&&(info !== null)) {
  44. //console.log("found informal table - assuming table view");
  45. // Table View
  46. if (document.getElementsByClassName("empty-table").length === 1) {
  47. // empty -> switch to tagged objects
  48. document.getElementById("contextTabLink_1").click();
  49. }
  50. } else {
  51. //console.log("informal id not found or null - assuming tree view");
  52. // checking nodes
  53. if (document.getElementsByClassName("TreeNode").length === 0) {
  54. getNodes();
  55. //console.log(document.getElementsByClassName("TreeNode").length);
  56. //document.getElementById("contextTabLink_1").click();
  57. }
  58. }
  59. }
  60. }
  61. }