Skip to content

Instantly share code, notes, and snippets.

@elcritch
Last active April 20, 2016 00:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elcritch/034f0ce90433b215b96183e3cd2eab50 to your computer and use it in GitHub Desktop.
Save elcritch/034f0ce90433b215b96183e3cd2eab50 to your computer and use it in GitHub Desktop.
Hacked Json Viewer
function codify() {
$('span.out:contains("{"):not(.json-parsed)').each(function() {
var text = $(this).ignore().text();
var nodes = $(this).find("*").clone();
var res = text.replace(/(\{.+\})/, function (x) {
var s = '</span><code class="lang-json">';
s += "" + x + "";
s += '</code><br><span class="non-code">';
return s ;
});
$(this).html('<span class="non-code">' +res+ '</span>');
$(this).addClass('json-parsed');
});
}
function jsonViewify() {
$('code.lang-json').each(function() {
console.log("jsoncode: ", this);
var code_node = $(this);
var jsStr = code_node.text();
try {
var json = JSON.parse(jsStr);
$(this).JSONView(json, { collapsed: true });
} catch (e) {
console.error("parsing bug", e);
};
});
};
function jsonHackRun() {
if (typeof $.fn.ignore === "undefined") {
$.fn.ignore = function(sel){
return this.clone().find(sel||">*").remove().end();
};
}
codify();
jsonViewify();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment