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.

150 lines
5.6 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 year 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. } else if (typeof data === "string") {
  61. // i.e. a string but not a JSON stringified string
  62. data = $("<div>").text(data).html();
  63. }
  64. $el.html(data);
  65. element.replaceWith($el);
  66. }
  67. };
  68. })
  69. .directive("resizableColumns", function ($parse) {
  70. return {
  71. link: function (scope, element, attrs) {
  72. const options = { minWidth: 5 };
  73. if ($(element).data("resizable-columns-sync")) {
  74. var $target = $($(element).data("resizable-columns-sync"));
  75. $(element).on("column:resize", function (
  76. event,
  77. resizable,
  78. $leftColumn,
  79. $rightColumn,
  80. widthLeft,
  81. widthRight
  82. ) {
  83. var leftColumnIndex = resizable.$table
  84. .find(".rc-column-resizing")
  85. .parent()
  86. .find("td, th")
  87. .index($leftColumn);
  88. var $targetFirstRow = $target.find("tr:first");
  89. $($targetFirstRow.find("td, th").get(leftColumnIndex)).css("width", widthLeft + "%");
  90. $($targetFirstRow.find("td, th").get(leftColumnIndex + 1)).css("width", widthRight + "%");
  91. $target.data("resizableColumns").syncHandleWidths();
  92. $target.data("resizableColumns").saveColumnWidths();
  93. });
  94. // $(window).on("resize", function () {
  95. // // console.log('resize event');
  96. // // var $target = $($(element).data("resizable-columns-sync"));
  97. // // $target.data("resizableColumns").refreshHeaders();
  98. // // $(element).resizableColumns(options);
  99. // })
  100. }
  101. $(element).resizableColumns(options);
  102. }
  103. };
  104. })
  105. .directive("scrollToNew", function ($parse) {
  106. return function (scope, element, attrs) {
  107. if (scope.scrollToNew && scope.$last) {
  108. const $container = $(element).parents(".data-container").first();
  109. const $parent = $(element).parent();
  110. $container.scrollTop($parent.height());
  111. }
  112. };
  113. }).directive('onSearch', function () {
  114. return function (scope, element, attrs) {
  115. element.bind("keypress", function (event) {
  116. if((event.shiftKey && event.which === 220) || event.which === 13 || event.which === 44 || event.which === 124) {
  117. scope.$apply(function (){
  118. scope.$eval(attrs.onSearch);
  119. });
  120. event.preventDefault();
  121. }
  122. });
  123. };
  124. }).directive('ngRightClick', function($parse) {
  125. return function(scope, element, attrs) {
  126. element.bind('contextmenu', function(event) {
  127. scope.$apply(function() {
  128. scope.$eval(attrs.ngRightClick);
  129. });
  130. event.preventDefault();
  131. });
  132. };
  133. });