瀏覽代碼

修复bug:当正常页面body>pre存在,会导致json自动格式化出错。此bug已在FeHelper 3.4中修复

Alien 12 年之前
父節點
當前提交
7e7eb7e568
共有 3 個文件被更改,包括 14 次插入12 次删除
  1. 1 1
      chrome/manifest.json
  2. 1 1
      chrome/online.manifest.json
  3. 12 10
      chrome/static/js/jsonformat/contentscript-jsonformat.js

+ 1 - 1
chrome/manifest.json

@@ -1,6 +1,6 @@
 { 
 	"name": "WEB前端助手(FeHelper)", 
-	"version": "3.3",
+	"version": "3.4",
     "manifest_version": 2,
 	 
 	"default_locale": "zh_CN", 

+ 1 - 1
chrome/online.manifest.json

@@ -1,6 +1,6 @@
 {
     "name": "WEB前端助手(FeHelper)",
-    "version": "3.3",
+    "version": "3.4",
     "manifest_version": 2,
 
     "default_locale": "zh_CN",

+ 12 - 10
chrome/static/js/jsonformat/contentscript-jsonformat.js

@@ -26,20 +26,22 @@ baidu.csJsonFormat = (function(){
 
 	var _init = function(){
 		$(function(){
-            var source = $.trim($('body>pre').html()) || $.trim($('body').html());
-            var isJson = true;
+            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 = JSON.parse(source);
+                jsonObj = new Function("return " + source)();
             }catch(ex){
-                isJson = false;
-                try{
-                    jsonObj = new Function("return " + source)();
-                    isJson = true;
-                }catch(ex){
-                }
             }
-            if(isJson && jsonObj) {
+            if(jsonObj) {
                 $('body').html(_htmlFragment);
                 _loadCss();
                 JsonFormatEntrance.clear();