/**
* content_scripts中如果被检测到当前页面内容为json数据,则自动进行JSON格式化
*/
baidu.csJsonFormat = (function(){
"use strict";
var _htmlFragment = [
'
'
].join('');
var _loadCss = function(){
var fcpCss = chrome.extension.getURL('static/css/fe-jsonformat.css');
jQuery('').appendTo('head');
};
var _init = function(){
$(function(){
var source ;
if($('body').children().length == 1) {
source = $.trim($('body>pre').html()) ;
}
if(!source) {
source = $.trim($('body').html())
}
if(!source) {
return;
}
var jsonObj = null;
try{
jsonObj = new Function("return " + source)();
}catch(ex){
}
if(jsonObj && typeof jsonObj == "object") {
$('body').html(_htmlFragment);
_loadCss();
JsonFormatEntrance.clear();
JsonFormatEntrance.format(source);
}
});
};
return {
init : _init
};
})();
baidu.csJsonFormat.init();