Extends the Chrome Developer Tools, adding a new Network Panel in the Developer Tools window with better searching and response previews. https://leviolson.com/posts/chrome-ext-better-network-panel
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
4.7 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. var BNPChrome = angular
  2. .module("BNPChrome", [])
  3. .factory("parse", function () {
  4. const parser = function (input, level, depthOverride) {
  5. const depth = depthOverride || 3;
  6. if (level > depth) return input;
  7. if (!input || typeof input === "number" || typeof input === "boolean") {
  8. return input;
  9. }
  10. if (Array.isArray(input)) {
  11. // loop and parse each node
  12. for (var i = 0; i < input.length; i++) {
  13. input[i] = parser(input[i], level ? level + 1 : 1, depth);
  14. }
  15. return input;
  16. }
  17. if (typeof input === "string") {
  18. try {
  19. input = parser(JSON.parse(input), level ? level + 1 : 1, depth);
  20. return input;
  21. } catch (e) {
  22. // not a stringified node
  23. return input;
  24. }
  25. } else if (typeof input === "object") {
  26. Object.keys(input).forEach(function (item) {
  27. input[item] = parser(input[item], level ? level + 1 : 1, depth);
  28. return item;
  29. });
  30. } else {
  31. // unless there is a datatype I'm not checking for....
  32. // console.log('shouldnt get here')
  33. }
  34. return input;
  35. };
  36. return parser;
  37. })
  38. .directive("prettyPrint", function (parse) {
  39. return {
  40. restrict: "E",
  41. replace: true,
  42. transclude: false,
  43. scope: { data: "=data" },
  44. link: function (scope, element, attrs) {
  45. let data = scope.data;
  46. let $el = $("<div></div>");
  47. if (data === true) {
  48. data = "<i>true</i>";
  49. } else if (data === false) {
  50. data = "<i>false</i>";
  51. } else if (data === undefined) {
  52. data = "<i>undefined</i>";
  53. } else if (data === null) {
  54. data = "<i>null</i>";
  55. } else if (typeof data === "number") {
  56. // skip (i.e. do default)
  57. } else if (typeof data === "string" && (data[0] === "{" || data[0] === "[")) {
  58. $el = $("<pre></pre>");
  59. data = JSON.stringify(parse(data, 0), null, 4);
  60. // try {
  61. // data = JSON.stringify(JSON.parse(data), null, 4);
  62. // // $el.text()
  63. // } catch (e) {
  64. // console.debug("Error parsing", data);
  65. // }
  66. } else if (typeof data === "string") {
  67. // i.e. a string but not a JSON stringified string
  68. data = $("<div>").text(data).html();
  69. }
  70. $el.html(data);
  71. element.replaceWith($el);
  72. }
  73. };
  74. })
  75. .directive("resizableColumns", function ($parse) {
  76. return {
  77. link: function (scope, element, attrs) {
  78. const options = { minWidth: 5 };
  79. if ($(element).data("resizable-columns-sync")) {
  80. var $target = $($(element).data("resizable-columns-sync"));
  81. $(element).on("column:resize", function (
  82. event,
  83. resizable,
  84. $leftColumn,
  85. $rightColumn,
  86. widthLeft,
  87. widthRight
  88. ) {
  89. var leftColumnIndex = resizable.$table
  90. .find(".rc-column-resizing")
  91. .parent()
  92. .find("td, th")
  93. .index($leftColumn);
  94. var $targetFirstRow = $target.find("tr:first");
  95. $($targetFirstRow.find("td, th").get(leftColumnIndex)).css("width", widthLeft + "%");
  96. $($targetFirstRow.find("td, th").get(leftColumnIndex + 1)).css("width", widthRight + "%");
  97. $target.data("resizableColumns").syncHandleWidths();
  98. $target.data("resizableColumns").saveColumnWidths();
  99. });
  100. }
  101. $(element).resizableColumns(options);
  102. }
  103. };
  104. })
  105. .directive("scrollToNew", function ($parse) {
  106. return function (scope, element, attrs) {
  107. if (scope.showIncomingRequests && scope.$last) {
  108. const $container = $(element).parents(".data-container").first();
  109. const $parent = $(element).parent();
  110. $container.scrollTop($parent.height());
  111. }
  112. };
  113. });