Created
October 2, 2008 16:53
-
-
Save danilopopeye/14394 to your computer and use it in GitHub Desktop.
Parse and check your JSON
This file contains hidden or 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
CmdUtils.CreateCommand({ | |
name: "json-lint", | |
homepage: "http://ubiquity.danilosousa.net/", | |
author: { name: "Danilo Sousa", email: "[email protected]" }, | |
takes: { "json code": noun_arb_text }, | |
icon: "chrome://ubiquity/content/icons/page_code.png", | |
description: "Parse and check your JSON.", | |
preview: function( previewBlock, directObject ) { | |
var code = directObject.text; | |
var url = "http://www.jsonlint.com/ajax/validate"; | |
var params = { | |
json: code, | |
reformat: "yes" | |
}; | |
jQuery.post( url, params, function( data ) { | |
context.focusedWindow.dataJSONLint = data; | |
previewBlock.innerHTML = ""; | |
if( data.responseCode ){ | |
var bg = "#FBE3E4"; | |
var font = "#D12F19"; | |
var border = "#FBC2C4"; | |
} else { | |
var bg = "#E6EFC2"; | |
var font = "#529214"; | |
var border = "#C6D880"; | |
} | |
var doc = context.focusedWindow.document; | |
var div = doc.createElement( "div" ); | |
div.style.background = bg + " none repeat scroll 0 0"; | |
div.style.border = "2px solid " + border; | |
div.style.color = font; | |
div.style.padding = "5px"; | |
div.style.lineHeight = "1.5"; | |
div.innerHTML = data.result; | |
previewBlock.appendChild( div ); | |
},"json"); | |
}, | |
execute:function(directObj) { | |
var data = context.focusedWindow.dataJSONLint; | |
if( !data.responseCode ){ | |
CmdUtils.setSelection( "<pre>" + data.prettyJSON + "</pre>" ) | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment