From 51ba6a87fdfd48a62b155b31f01516d40a619da2 Mon Sep 17 00:00:00 2001 From: Nguansak Date: Fri, 19 Feb 2021 17:55:30 +0700 Subject: [PATCH 1/5] Export CSV --- manifest.json | 2 +- src/content.js | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index fec197e..4501afa 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "JSON-As-Table Viewer", - "version": "1.0.5", + "version": "1.0.6", "description": "*** View JSON response from a URL as HTML table ***", "icons": { "16": "images/icon16.png", diff --git a/src/content.js b/src/content.js index 7f87793..8bf7bbb 100644 --- a/src/content.js +++ b/src/content.js @@ -97,6 +97,26 @@ function renderTable() { tr.addClass('shown'); } }); + + $('#exportCsv').on('click', function () { + const arrayOfJson = contentArray + const replacer = (key, value) => value === null ? '' : value // specify how you want to handle null values here + const header = Object.keys(arrayOfJson[0]) + let csv = arrayOfJson.map(row => header.map(fieldName => + JSON.stringify(row[fieldName], replacer)).join(',')) + csv.unshift(header.join(',')) + csv = csv.join('\r\n') + const filename = "json.csv" + + // Create link and download + var link = document.createElement('a'); + link.setAttribute('href', 'data:text/csv;charset=utf-8,%EF%BB%BF' + encodeURIComponent(csv)); + link.setAttribute('download', filename); + link.style.visibility = 'hidden'; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + }) }); } @@ -119,6 +139,7 @@ function tableHTML() { "
" + "" + "
" + + "\n" + "
" + "
" + "\n" + From d42c3fcc9361a1fc9c2f6dcea733ca7f52069015 Mon Sep 17 00:00:00 2001 From: Nguansak Date: Fri, 19 Feb 2021 18:38:47 +0700 Subject: [PATCH 2/5] Minimal UI --- manifest.json | 2 +- src/content.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/manifest.json b/manifest.json index 4501afa..721b5b2 100644 --- a/manifest.json +++ b/manifest.json @@ -29,4 +29,4 @@ "libs/DataTables-1.10.21/images/*", "images/*" ] -} +} \ No newline at end of file diff --git a/src/content.js b/src/content.js index 8bf7bbb..a34dfc3 100644 --- a/src/content.js +++ b/src/content.js @@ -79,7 +79,8 @@ function renderTable() { responsive: true, data: dataArray, columns: dataColumns, - order: [[1, 'asc']] + order: [[1, 'asc']], + "lengthMenu": [[20, 30, 50, 100, -1], [20, 30, 50, 100, "All"]] }); //Expandable panel below each row to show original JSON of the row @@ -135,7 +136,6 @@ function tableHTML() { "" + "" + "
" + - "
" + "
" + "" + "
" + From 45cd6f8f00a72296cc311188849a0e0937c8509c Mon Sep 17 00:00:00 2001 From: nguansak Date: Wed, 24 Feb 2021 20:21:13 +0700 Subject: [PATCH 3/5] All lenght menu first --- src/content.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content.js b/src/content.js index a34dfc3..8a28a94 100644 --- a/src/content.js +++ b/src/content.js @@ -80,7 +80,7 @@ function renderTable() { data: dataArray, columns: dataColumns, order: [[1, 'asc']], - "lengthMenu": [[20, 30, 50, 100, -1], [20, 30, 50, 100, "All"]] + "lengthMenu": [[-1, 20, 30, 50, 100], ["All", 20, 30, 50, 100]] }); //Expandable panel below each row to show original JSON of the row From 9c70b6c3d7d30448a50270f193b5d1da35ed5923 Mon Sep 17 00:00:00 2001 From: Nguansak Date: Sun, 16 Oct 2022 22:33:17 +0700 Subject: [PATCH 4/5] Fix menifest 3 --- manifest.json | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/manifest.json b/manifest.json index 721b5b2..1febfc0 100644 --- a/manifest.json +++ b/manifest.json @@ -1,5 +1,5 @@ { - "manifest_version": 2, + "manifest_version": 3, "name": "JSON-As-Table Viewer", "version": "1.0.6", "description": "*** View JSON response from a URL as HTML table ***", @@ -26,7 +26,12 @@ } ], "web_accessible_resources": [ - "libs/DataTables-1.10.21/images/*", - "images/*" + { + "resources": [ + "libs/DataTables-1.10.21/images/*", + "images/*" + ], + "matches": [ "" ] + } ] } \ No newline at end of file From 390c5c93027f9abd51730886f8c3d74c5ba0501e Mon Sep 17 00:00:00 2001 From: Nguansak Date: Sun, 16 Oct 2022 22:33:30 +0700 Subject: [PATCH 5/5] Fix bug isJsonOnlyPage --- src/content.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content.js b/src/content.js index 8a28a94..5fdc3f0 100644 --- a/src/content.js +++ b/src/content.js @@ -237,7 +237,7 @@ function errorMessage() { */ function isJsonOnlyPage() { return document.body !== undefined - && document.body.getElementsByTagName("*").length === 1 + && document.body.getElementsByTagName("*").length === 2 && document.getElementsByTagName("pre").length === 1; }