Skip to content

Commit d5e0ecd

Browse files
committed
Allow force highlight for oversized JSON
Adds a link that when clicked will bypass the oversized JSON check. Fixes #158
1 parent 8097dee commit d5e0ecd

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

extension/src/json-viewer/highlight-content.js

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var renderAlert = require('./viewer/render-alert');
77
var getOptions = require('./viewer/get-options');
88
var loadRequiredCss = require('./viewer/load-required-css');
99

10-
function oversizedJSON(pre, options) {
10+
function oversizedJSON(pre, options, outsideViewer) {
1111
var jsonSize = pre.textContent.length;
1212
var accepted = options.addons.maxJsonSize;
1313

@@ -27,10 +27,26 @@ function oversizedJSON(pre, options) {
2727
"Accepted: " + accepted + " kbytes, received: " + loaded + " kbytes. " +
2828
"It's possible to change this value at options -> Add-ons -> maxJsonSize"
2929
);
30-
renderAlert(pre, options,
31-
"[JSONViewer] Content not highlighted due to oversize. " +
32-
"Take a look at the console log for more information."
33-
);
30+
31+
var container = document.createElement("div");
32+
33+
var message = document.createElement("div");
34+
message.innerHTML = "[JSONViewer] Content not highlighted due to oversize. " +
35+
"Take a look at the console log for more information.";
36+
container.appendChild(message);
37+
38+
var highlightAnyway = document.createElement("a");
39+
highlightAnyway.href = "#";
40+
highlightAnyway.title = "Highlight anyway!";
41+
highlightAnyway.innerHTML = "Highlight anyway!";
42+
highlightAnyway.onclick = function(e) {
43+
e.preventDefault();
44+
pre.hidden = true;
45+
highlightContent(pre, outsideViewer, true);
46+
}
47+
container.appendChild(highlightAnyway);
48+
49+
renderAlert(pre, options, container);
3450
}
3551

3652
return isOversizedJSON;
@@ -46,9 +62,9 @@ function prependHeader(options, outsideViewer, jsonText) {
4662
return jsonText;
4763
}
4864

49-
function highlightContent(pre, outsideViewer) {
65+
function highlightContent(pre, outsideViewer, ignoreLimit) {
5066
getOptions().then(function(options) {
51-
if (oversizedJSON(pre, options)) {
67+
if (!ignoreLimit && oversizedJSON(pre, options, outsideViewer)) {
5268
return pre.hidden = false;
5369
}
5470

extension/src/json-viewer/viewer/render-alert.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
var loadCss = require('../load-css');
22

3-
function renderAlert(pre, options, message) {
3+
function renderAlert(pre, options, content) {
44
var alertContainer = document.createElement("div");
55
alertContainer.className = "json-viewer-alert";
6-
7-
var content = document.createElement("span");
8-
content.innerHTML = message;
96
alertContainer.appendChild(content);
107

118
var closeBtn = document.createElement("a");

0 commit comments

Comments
 (0)