Просмотр исходного кода

增加jsonformat功能的可配置性,用户可禁用此功能

Alien 12 лет назад
Родитель
Сommit
d1727ab1e2

+ 2 - 1
chrome/manifest.json

@@ -1,6 +1,6 @@
 { 
 	"name": "WEB前端助手(FeHelper)", 
-	"version": "3.5",
+	"version": "3.6",
     "manifest_version": 2,
 	 
 	"default_locale": "zh_CN", 
@@ -57,6 +57,7 @@
 			
 			"static/js/core/core.js",
 			"static/js/core/fe-const.js",
+            "static/js/fe-option.js",
 			
 			"static/js/fcp/fcp-fl.js",
 			"static/js/fcp/css/fcp-css-analytic.js",

+ 1 - 1
chrome/online.manifest.json

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

+ 4 - 1
chrome/static/js/core/fe-const.js

@@ -67,7 +67,10 @@ const MSG_TYPE = {
     //QR生成器
     QR_CODE : 'qrcode',
     //代码美化
-    CODE_BEAUTIFY : 'codebeautify'
+    CODE_BEAUTIFY : 'codebeautify',
+
+    //页面json代码自动格式化
+    AUTO_FORMART_PAGE_JSON : "opt_item_autojson"
 };
 
 /**

+ 7 - 3
chrome/static/js/fe-option.js

@@ -85,6 +85,7 @@ baidu.feOption = (function(){
 		var items = {};
 		items['opt_item_contextMenus'] = $('#opt_item_contextMenus').attr('checked');
 		items['opt_item_showfdpmenu'] = $('#opt_item_showfdpmenu').attr('checked');
+        items['opt_item_autojson'] = $('#opt_item_autojson').attr('checked');
 		items['opt_item_notification'] = $('#opt_item_notification').val();
 		_goSetOptions(items);
 	};
@@ -93,10 +94,11 @@ baidu.feOption = (function(){
 	 * 显示启动项
 	 */
 	var _show_opt_form_start = function(){
-		var optItems = ['opt_item_contextMenus',"opt_item_showfdpmenu","opt_item_notification"];
+		var optItems = ['opt_item_contextMenus',"opt_item_showfdpmenu",
+            "opt_item_autojson","opt_item_notification"];
 		_goGetOptions(optItems,function(opts){
 			$.each(optItems,function(i,item){
-				if(i == 2) {
+				if(i == 3) {
 					$('#' + item).val(opts[item]);
 				} else if(opts[item] === 'true') {
 					$('#' + item).attr('checked','checked');
@@ -183,7 +185,9 @@ baidu.feOption = (function(){
 		init : _init,
 		doSetOptions : _doSetOptions,
 		doGetOptions : _doGetOptions,
-		getOptionItem : _getOptionItem
+		getOptionItem : _getOptionItem,
+        getOptions : _goGetOptions,
+        setOptions : _goSetOptions
 	};
 })();
 

+ 50 - 30
chrome/static/js/jsonformat/contentscript-jsonformat.js

@@ -8,7 +8,9 @@ baidu.csJsonFormat = (function(){
     var _htmlFragment = [
         '<div class="mod-json mod-contentscript"><div class="rst-item">',
             '<div id="formatTips">本页JSON数据由FeHelper进行自动格式化,若有任何问题,点击这里提交 ',
-                '<a href="http://www.baidufe.com/item/889639af23968ee688b9.html#comment" target="_blank">意见反馈</a></div>',
+                '<a href="http://www.baidufe.com/item/889639af23968ee688b9.html#comment" target="_blank">意见反馈</a>',
+                '&nbsp;&nbsp;或者&nbsp;&nbsp;<a href="#" id="makeAutoJsonFormatOff">禁用此功能</a>',
+            '</div>',
             '<div id="formattingMsg">',
                 '<svg id="spinner" width="16" height="16" viewBox="0 0 300 300" xmlns="http://www.w3.org/2000/svg" version="1.1">',
                     '<path d="M 150,0 a 150,150 0 0,1 106.066,256.066 l -35.355,-35.355 a -100,-100 0 0,0 -70.711,-170.711 z" fill="#3d7fe6"></path>',
@@ -24,40 +26,58 @@ baidu.csJsonFormat = (function(){
         jQuery('<link id="_fehelper_fcp_css_" href="' + fcpCss + '" rel="stylesheet" type="text/css" />').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 _format = 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)();
+
+            // 还要防止下面这种情况:  "{\"ret\":\"0\", \"msg\":\"ok\"}"
+            if(typeof jsonObj == "string") {
+                // 再来一次
+                jsonObj = new Function("return " + jsonObj)();
             }
 
-            var jsonObj = null;
-            try{
-                jsonObj = new Function("return " + source)();
+            if(typeof jsonObj == "object") {
+                $('body').html(_htmlFragment);
+                _loadCss();
+                JsonFormatEntrance.clear();
+                // 要尽量保证格式化的东西一定是一个json,所以需要把内容进行JSON.stringify处理
+                source = JSON.stringify(jsonObj);
+                JsonFormatEntrance.format(source);
 
-                // 还要防止下面这种情况:  "{\"ret\":\"0\", \"msg\":\"ok\"}"
-                if(typeof jsonObj == "string") {
-                    // 再来一次
-                    jsonObj = new Function("return " + jsonObj)();
-                }
+                // 允许禁用
+                $('#makeAutoJsonFormatOff').click(function(e){
+                    baidu.feOption.setOptions({
+                        "opt_item_autojson" : 'false'
+                    });
+                    alert("以后可以从FeHelper的选项页面中重新开启");
+                    window.location.reload(true);
+                });
+            }
+        }catch(ex){
+            return;
+        }
+    };
 
-                if(typeof jsonObj == "object") {
-                    $('body').html(_htmlFragment);
-                    _loadCss();
-                    JsonFormatEntrance.clear();
-                    // 要尽量保证格式化的东西一定是一个json,所以需要把内容进行JSON.stringify处理
-                    source = JSON.stringify(jsonObj);
-                    JsonFormatEntrance.format(source);
+	var _init = function(){
+		$(function(){
+            baidu.feOption.getOptions(["opt_item_autojson"],function(opts){
+                if(opts["opt_item_autojson"] != 'false') {
+                    _format();
                 }
-            }catch(ex){
-                return;
-            }
+            });
 		});
 	};
 

+ 2 - 1
chrome/static/js/mod/mod_manifest.js

@@ -18,7 +18,8 @@
 
 importScript("js/core/core.js");
 importScript("js/core/fe-const.js");
-			
+importScript("js/fe-option.js");
+
 importScript("js/fcp/fcp-fl.js");
 importScript("js/fcp/css/fcp-css-analytic.js");
 importScript("js/fcp/css/fcp-css.js");

Разница между файлами не показана из-за своего большого размера
+ 0 - 0
chrome/template/fehelper_options.html


Некоторые файлы не были показаны из-за большого количества измененных файлов