瀏覽代碼

JSON格式化增加自动decode的配置项

zxlie 7 年之前
父節點
當前提交
b443c96ff5

+ 4 - 1
apps/background/index.js

@@ -555,7 +555,10 @@ var BgPageInstance = (function () {
             opts.JSON_PAGE_FORMAT && chrome.tabs.query({active: true, currentWindow: true}, function (tabs) {
                 chrome.tabs.sendMessage(tabs[0].id, {
                     type: MSG_TYPE.JSON_PAGE_FORMAT,
-                    options: {MAX_JSON_KEYS_NUMBER: opts.MAX_JSON_KEYS_NUMBER}
+                    options: {
+                        MAX_JSON_KEYS_NUMBER: opts.MAX_JSON_KEYS_NUMBER,
+                        AUTO_TEXT_DECODE:opts.AUTO_TEXT_DECODE === 'true'
+                    }
                 });
             });
         });

+ 3 - 1
apps/json-format/automatic.js

@@ -152,7 +152,9 @@ module.exports = (() => {
             return;
         }
 
-        source = _uniDecode(source);
+        if (options && options['AUTO_TEXT_DECODE']) {
+            source = _uniDecode(source);
+        }
 
         // JSONP形式下的callback name
         let funcName = null;

+ 0 - 29
apps/json-format/index.js

@@ -78,8 +78,6 @@ new Vue({
                 return false;
             }
 
-            source = this._uniDecode(source);
-
             // JSONP形式下的callback name
             let funcName = null;
             // json对象
@@ -228,33 +226,6 @@ new Vue({
         setDemo: function () {
             let demo = '{"BigIntSupported":995815895020119788889,"date":"20180322","message":"Success !","status":200,"city":"北京","count":632,"data":{"shidu":"34%","pm25":73,"pm10":91,"quality":"良","wendu":"5","ganmao":"极少数敏感人群应减少户外活动","yesterday":{"date":"21日星期三","sunrise":"06:19","high":"高温 11.0℃","low":"低温 1.0℃","sunset":"18:26","aqi":85,"fx":"南风","fl":"<3级","type":"多云","notice":"阴晴之间,谨防紫外线侵扰"},"forecast":[{"date":"22日星期四","sunrise":"06:17","high":"高温 17.0℃","low":"低温 1.0℃","sunset":"18:27","aqi":98,"fx":"西南风","fl":"<3级","type":"晴","notice":"愿你拥有比阳光明媚的心情"},{"date":"23日星期五","sunrise":"06:16","high":"高温 18.0℃","low":"低温 5.0℃","sunset":"18:28","aqi":118,"fx":"无持续风向","fl":"<3级","type":"多云","notice":"阴晴之间,谨防紫外线侵扰"},{"date":"24日星期六","sunrise":"06:14","high":"高温 21.0℃","low":"低温 7.0℃","sunset":"18:29","aqi":52,"fx":"西南风","fl":"<3级","type":"晴","notice":"愿你拥有比阳光明媚的心情"},{"date":"25日星期日","sunrise":"06:13","high":"高温 22.0℃","low":"低温 7.0℃","sunset":"18:30","aqi":71,"fx":"西南风","fl":"<3级","type":"晴","notice":"愿你拥有比阳光明媚的心情"},{"date":"26日星期一","sunrise":"06:11","high":"高温 21.0℃","low":"低温 8.0℃","sunset":"18:31","aqi":97,"fx":"西南风","fl":"<3级","type":"多云","notice":"阴晴之间,谨防紫外线侵扰"}]}}';
             editor.setValue(demo);
-        },
-
-
-        /**
-         * 此方法用于将Unicode码解码为正常字符串
-         * @param {Object} text
-         */
-        _uniDecode : function (text) {
-            try{
-                text = decodeURIComponent(text);
-            }catch(e){}
-            text = text.replace(/(\\)?\\u/gi, "%u").replace('%u0025', '%25');
-
-            text = unescape(text.toString().replace(/%2B/g, "+"));
-            let matches = text.match(/(%u00([0-9A-F]{2}))/gi);
-            if (matches) {
-                for (let matchid = 0; matchid < matches.length; matchid++) {
-                    let code = matches[matchid].substring(1, 3);
-                    let x = Number("0x" + code);
-                    if (x >= 128) {
-                        text = text.replace(matches[matchid], code);
-                    }
-                }
-            }
-            text = unescape(text.toString().replace(/%2B/g, "+"));
-
-            return text;
         }
     }
 });

+ 1 - 1
apps/manifest.json

@@ -1,6 +1,6 @@
 {
   "name": "WEB前端助手(FeHelper)",
-  "version": "2018.10.2214",
+  "version": "2018.10.2512",
   "manifest_version": 2,
   "default_locale": "zh_CN",
   "description": "FE助手:包括JSON格式化、二维码生成与解码、信息编解码、代码压缩、美化、页面取色、Markdown与HTML互转、网页滚动截屏、正则表达式、时间转换工具、编码规范检测、页面性能检测、Ajax接口调试、密码生成器、JSON比对工具",

+ 3 - 0
apps/options/index.css

@@ -51,4 +51,7 @@ h5,h4 {
 }
 .box-inner.x-disabled {
     opacity: 0.2;
+}
+.row-line {
+    line-height: 24px;
 }

文件差異過大導致無法顯示
+ 0 - 0
apps/options/index.html


+ 7 - 2
apps/options/index.js

@@ -9,6 +9,7 @@ new Vue({
     data: {
         selectedOpts: [],
         maxJsonKeysNumber: 0,
+        auto_text_decode:false,
         manifest: {}
     },
 
@@ -16,9 +17,10 @@ new Vue({
 
         Settings.getOptions((opts) => {
             this.selectedOpts = Object.keys(opts).filter(k => {
-                return typeof(opts[k]) === 'string' && k !== 'MAX_JSON_KEYS_NUMBER'
+                return typeof(opts[k]) === 'string' && !['MAX_JSON_KEYS_NUMBER','AUTO_TEXT_DECODE'].includes(k)
             });
             this.maxJsonKeysNumber = opts['MAX_JSON_KEYS_NUMBER'];
+            this.auto_text_decode = opts['AUTO_TEXT_DECODE'] === 'true';
         });
         this.manifest = chrome.runtime.getManifest();
     },
@@ -37,7 +39,10 @@ new Vue({
 
         save: function () {
 
-            Settings.setOptions(this.selectedOpts.concat({MAX_JSON_KEYS_NUMBER: parseInt(this.maxJsonKeysNumber, 10)}));
+            Settings.setOptions(this.selectedOpts.concat([
+                {MAX_JSON_KEYS_NUMBER: parseInt(this.maxJsonKeysNumber, 10)},
+                {AUTO_TEXT_DECODE: String(this.auto_text_decode)},
+            ]));
 
             setTimeout(() => {
                 this.close();

+ 2 - 1
apps/options/settings.js

@@ -31,7 +31,8 @@ module.exports = (() => {
         'PAGE_CAPTURE',
         'RANDOM_PASSWORD',
         'FORBID_OPEN_IN_NEW_TAB',
-        'MAX_JSON_KEYS_NUMBER'
+        'MAX_JSON_KEYS_NUMBER',
+        'AUTO_TEXT_DECODE'
     ];
 
     /**

部分文件因文件數量過多而無法顯示