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.

162 lines
6.5 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. chrome.extension.getBackgroundPage().console.debug(`In parser: Attempting Parse %s/%s`, level, depthOverride);
  6. const depth = depthOverride || 3;
  7. if (level > depth) return input;
  8. if (!input || typeof input === "number" || typeof input === "boolean") {
  9. return input;
  10. }
  11. if (Array.isArray(input)) {
  12. // loop and parse each node
  13. for (var i = 0; i < input.length; i++) {
  14. input[i] = parser(input[i], level ? level + 1 : 1, depth);
  15. }
  16. return input;
  17. }
  18. if (typeof input === "string") {
  19. try {
  20. chrome.extension.getBackgroundPage().console.debug("In parser: Attempting String Parse");
  21. input = parser(JSON.parse(input), level ? level + 1 : 1, depth);
  22. return input;
  23. } catch (e) {
  24. // not a stringified node
  25. // could be URL Encoded
  26. try {
  27. chrome.extension.getBackgroundPage().console.debug("In parser: Attempting URL Decode", decodeURI(input), level, depth);
  28. input = parser(decodeURI(input), level ? level + 1 : 1, depth);
  29. return input;
  30. } catch(e) {
  31. // not url encoded
  32. chrome.extension.getBackgroundPage().console.debug("In parser: Could Not Decode");
  33. return input;
  34. }
  35. return input;
  36. }
  37. } else if (typeof input === "object") {
  38. Object.keys(input).forEach(function (item) {
  39. input[item] = parser(input[item], level ? level + 1 : 1, depth);
  40. return item;
  41. });
  42. } else {
  43. // unless there is a datatype I'm not checking for....
  44. chrome.extension.getBackgroundPage().console.debug('In parser: Data Type Unaccounted For');
  45. }
  46. return input;
  47. };
  48. return parser;
  49. })
  50. .directive("prettyPrint", function (parse) {
  51. return {
  52. restrict: "E",
  53. replace: true,
  54. transclude: false,
  55. scope: { data: "=data" },
  56. link: function (scope, element, attrs) {
  57. let data = scope.data;
  58. let $el = $("<div></div>");
  59. if (data === true) {
  60. data = "<i>true</i>";
  61. } else if (data === false) {
  62. data = "<i>false</i>";
  63. } else if (data === undefined) {
  64. data = "<i>undefined</i>";
  65. } else if (data === null) {
  66. data = "<i>null</i>";
  67. } else if (typeof data === "number") {
  68. // skip (i.e. do default)
  69. } else if (typeof data === "string" && (data[0] === "{" || data[0] === "[")) {
  70. $el = $("<pre></pre>");
  71. data = JSON.stringify(parse(data, 0), null, 4);
  72. } else if (typeof data === "string") {
  73. // i.e. a string but not a JSON stringified string
  74. data = $("<div>").text(data).html();
  75. }
  76. $el.html(data);
  77. element.replaceWith($el);
  78. }
  79. };
  80. })
  81. .directive("resizableColumns", function () {
  82. return {
  83. link: function (scope, element, attrs) {
  84. const options = { minWidth: 5 };
  85. if ($(element).data("resizable-columns-sync")) {
  86. var $target = $($(element).data("resizable-columns-sync"));
  87. $(element).on("column:resize", function (
  88. event,
  89. resizable,
  90. $leftColumn,
  91. $rightColumn,
  92. widthLeft,
  93. widthRight
  94. ) {
  95. var leftColumnIndex = resizable.$table
  96. .find(".rc-column-resizing")
  97. .parent()
  98. .find("td, th")
  99. .index($leftColumn);
  100. var $targetFirstRow = $target.find("tr:first");
  101. $($targetFirstRow.find("td, th").get(leftColumnIndex)).css("width", widthLeft + "%");
  102. $($targetFirstRow.find("td, th").get(leftColumnIndex + 1)).css("width", widthRight + "%");
  103. $target.data("resizableColumns").syncHandleWidths();
  104. $target.data("resizableColumns").saveColumnWidths();
  105. });
  106. // $(window).on("resize", function () {
  107. // // console.log('resize event');
  108. // // var $target = $($(element).data("resizable-columns-sync"));
  109. // // $target.data("resizableColumns").refreshHeaders();
  110. // // $(element).resizableColumns(options);
  111. // })
  112. }
  113. $(element).resizableColumns(options);
  114. }
  115. };
  116. })
  117. .directive("scrollToNew", function () {
  118. return function (scope, element, attrs) {
  119. if (scope.scrollToNew && scope.$last) {
  120. const $container = $(element).parents(".data-container").first();
  121. const $parent = $(element).parent();
  122. $container.scrollTop($parent.height());
  123. }
  124. };
  125. }).directive('onSearch', function () {
  126. return function (scope, element, attrs) {
  127. element.bind("keypress", function (event) {
  128. if((event.shiftKey && event.which === 220) || event.which === 13 || event.which === 44 || event.which === 124) {
  129. scope.$apply(function (){
  130. scope.$eval(attrs.onSearch);
  131. });
  132. event.preventDefault();
  133. }
  134. });
  135. };
  136. }).directive('ngRightClick', function() {
  137. return function(scope, element, attrs) {
  138. element.bind('contextmenu', function(event) {
  139. scope.$apply(function() {
  140. scope.$eval(attrs.ngRightClick);
  141. });
  142. event.preventDefault();
  143. });
  144. };
  145. });