Browse Source

升级json格式化功能

zxlie 9 years ago
parent
commit
3e8fffb9d7

+ 1 - 1
chrome/manifest.json

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

+ 1 - 1
chrome/online.manifest.json

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

+ 4 - 3
chrome/static/js/jsonformat/contentscript-jsonformat.js

@@ -143,9 +143,10 @@ baidu.csJsonFormat = (function () {
                     return ;
                 }
                 // 直接replace掉所有\w之外的字符,再和原内容比较
-                var r_ns = newSource.replace(/[^\w]/gm,'');
-                var r_os = _uniDecode(source).replace(/[^\w]/gm,'');
-                if(r_ns < r_os) {
+                var r_ns = newSource.replace(/[^\w]/gm,'').length;
+                var r_os = _uniDecode(source).replace(/[^\w]/gm,'').length;
+                // 允许内容产生1%的误差
+                if(Math.abs(r_ns - r_os) > (r_ns + r_os) / 200) {
                     return ;
                 }
             } catch (ex) {

+ 1 - 1
chrome/static/js/jsonformat/fe-jsonformat.js

@@ -12,7 +12,7 @@ baidu.jsonformat = (function () {
     var _format = function () {
         $('#errorMsg').html('');
         $('#modJsonResult').hide();
-        var source = $('#jsonSource').val();
+        var source = $('#jsonSource').val().replace(/\n/gm,' ');
         if (!source) {
             return;
         }