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.

77 lines
2.3 KiB

4 years ago
  1. var BNPChrome = angular.module('BNPChrome', [])
  2. .directive('prettyPrint', function ($parse) {
  3. return {
  4. restrict: 'E',
  5. replace: true,
  6. transclude: false,
  7. scope: { data: '=data' },
  8. link: function (scope, element, attrs) {
  9. let data = scope.data;
  10. let $el = $('<div></div>');
  11. if (data === true) {
  12. data = '<i>true</i>';
  13. } else if (data === false) {
  14. data = '<i>false</i>';
  15. } else if (data === undefined) {
  16. data = '<i>undefined</i>';
  17. } else if (data === null) {
  18. data = '<i>null</i>';
  19. } else if (typeof data === 'number') {
  20. // skip (i.e. do default)
  21. } else if (typeof data === 'string' && (data[0] === '{' || data[0] === '[')) {
  22. $el = $('<pre></pre>');
  23. try {
  24. data = JSON.stringify(JSON.parse(data), null, 4);
  25. // $el.text()
  26. } catch (e) {
  27. console.debug('Error parsing', data);
  28. }
  29. } else if (typeof data === 'string') {
  30. // i.e. a string but not a JSON stringified string
  31. data = $('<div>').text(data).html();
  32. }
  33. $el.html(data);
  34. element.replaceWith($el);
  35. }
  36. };
  37. })
  38. .directive('resizableColumns', function ($parse) {
  39. return {
  40. link: function (scope, element, attrs) {
  41. const options = {minWidth: 5};
  42. if ($(element).data('resizable-columns-sync')) {
  43. var $target = $($(element).data('resizable-columns-sync'));
  44. $(element).on('column:resize', function(event, resizable, $leftColumn, $rightColumn, widthLeft, widthRight)
  45. {
  46. var leftColumnIndex = resizable.$table.find('.rc-column-resizing').parent().find('td, th').index($leftColumn);
  47. var $targetFirstRow = $target.find('tr:first');
  48. $($targetFirstRow.find('td, th').get(leftColumnIndex)).css('width', widthLeft + '%');
  49. $($targetFirstRow.find('td, th').get(leftColumnIndex + 1)).css('width', widthRight + '%');
  50. $target.data('resizableColumns').syncHandleWidths();
  51. $target.data('resizableColumns').saveColumnWidths();
  52. });
  53. }
  54. $(element).resizableColumns(options);
  55. }
  56. };
  57. })
  58. .directive('scrollToNew', function ($parse) {
  59. return function(scope, element, attrs) {
  60. if (scope.showIncomingRequests && scope.$last) {
  61. const $container = $(element).parents('.data-container').first();
  62. const $parent = $(element).parent();
  63. $container.scrollTop($parent.height());
  64. }
  65. };
  66. });