From 4d91686e54c95b371499aeb4e5158d9f00c34ab2 Mon Sep 17 00:00:00 2001 From: Adam Bukowski Date: Fri, 15 Sep 2023 10:52:54 +0200 Subject: [PATCH 1/3] fix: handle chrome's pretty print button --- extension/src/json-viewer/check-if-json.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/extension/src/json-viewer/check-if-json.js b/extension/src/json-viewer/check-if-json.js index 5160fde..7ab8fdf 100644 --- a/extension/src/json-viewer/check-if-json.js +++ b/extension/src/json-viewer/check-if-json.js @@ -23,8 +23,15 @@ function getPreWithSource() { } var childNode = childNodes[0]; - var nodeName = childNode.nodeName - var textContent = childNode.textContent + var nodeName = childNode.nodeName; + var textContent = childNode.textContent; + + // skip chrome's built-in pretty print button + if (nodeName === "DIV" && childNodes.length > 1) { + childNode = childNodes[1]; + nodeName = childNode.nodeName; + textContent = childNode.textContent; + } if (nodeName === "PRE") { return childNode; From 40326cae13c99614804bbd8506df4b6df9f9d1a2 Mon Sep 17 00:00:00 2001 From: Adam Bukowski Date: Fri, 15 Sep 2023 11:17:38 +0200 Subject: [PATCH 2/3] fix: remove chrome's pretty print json --- extension/src/json-viewer/check-if-json.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/extension/src/json-viewer/check-if-json.js b/extension/src/json-viewer/check-if-json.js index 7ab8fdf..12e32ac 100644 --- a/extension/src/json-viewer/check-if-json.js +++ b/extension/src/json-viewer/check-if-json.js @@ -26,11 +26,11 @@ function getPreWithSource() { var nodeName = childNode.nodeName; var textContent = childNode.textContent; - // skip chrome's built-in pretty print button + // handle chrome's built-in pretty print button if (nodeName === "DIV" && childNodes.length > 1) { - childNode = childNodes[1]; - nodeName = childNode.nodeName; - textContent = childNode.textContent; + childNode.remove(); + + return getPreWithSource(); } if (nodeName === "PRE") { From 826ecfb928ba05f096379771e87ac8ca29e9623f Mon Sep 17 00:00:00 2001 From: Adam Bukowski Date: Fri, 15 Sep 2023 14:08:45 +0200 Subject: [PATCH 3/3] Revert "fix: remove chrome's pretty print json" This reverts commit 40326cae13c99614804bbd8506df4b6df9f9d1a2. --- extension/src/json-viewer/check-if-json.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/extension/src/json-viewer/check-if-json.js b/extension/src/json-viewer/check-if-json.js index 12e32ac..7ab8fdf 100644 --- a/extension/src/json-viewer/check-if-json.js +++ b/extension/src/json-viewer/check-if-json.js @@ -26,11 +26,11 @@ function getPreWithSource() { var nodeName = childNode.nodeName; var textContent = childNode.textContent; - // handle chrome's built-in pretty print button + // skip chrome's built-in pretty print button if (nodeName === "DIV" && childNodes.length > 1) { - childNode.remove(); - - return getPreWithSource(); + childNode = childNodes[1]; + nodeName = childNode.nodeName; + textContent = childNode.textContent; } if (nodeName === "PRE") {