Last active
April 20, 2016 00:58
-
-
Save elcritch/034f0ce90433b215b96183e3cd2eab50 to your computer and use it in GitHub Desktop.
Hacked Json Viewer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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