Преглед на файлове

配置页面改造:支持所有Menu可开启和关闭

zxlie преди 8 години
родител
ревизия
9c0b0db466

+ 1 - 1
chrome/manifest.json

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

+ 1 - 1
chrome/online.manifest.json

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

+ 50 - 75
chrome/static/css/fe-opt.css

@@ -2,79 +2,40 @@ body {
 	font-family:"MS Sans Serif";
 	font-size:14px;
 }
+.mod-body-inner {
+    width: 500px;
+    margin: 0 auto;
+    border: 1px solid rgba(0, 0, 0, 0.3);
+    box-shadow: 0 0 3px rgba(0, 0, 0, 0.3);
+}
 .fe-opt-header {
-	height:120px;
 	width:100%;
-	position:fixed;
-	top:0;
-	left:0;
-}
-.fe-opt-header .top{
-	padding:10px;
-}
-.fe-opt-header .top img{
-	width:60px;
-}
-.fe-opt-header .top .text{
-	font-size:20pt;
-	position:absolute;
-	top:30px;
-	left:80px;
-}
-.fe-opt-header .top .copy-right{
-	font-size:12px;
-	position:absolute;
-	bottom:35px;
-	right:10px;
-	color:#77C;
+    background: #fff;
 }
 .fe-opt-header .bar{
 	height:30px;
 	width:100%;
-	position:absolute;
-	bottom:0;
-	left:0;
-	border-top:1px solid #78b;
-	background:#def;
+	background:rgba(111, 178, 248, 0.1);
+    border-bottom: 2px solid #ccc;
 	clear:both;
+    line-height: 20px;
 }
 .fe-opt-header .bar:after {
 	content:"\20";
 }
 
 .fe-opt-header .bar .text{
-	float:left;
 	padding:5px;
+    float: left;
 }
-
-.fe-opt-header .bar .btn{
-	float:right;
-	margin:5px 10px;
-	font-weight:bold;
-	color:#00b;
-	cursor:pointer;
-}
-
-.fe-opt-header .bar .btn.close {
-	margin-left:0;
-	margin-right:20px;
-}
-.fe-opt-header .bar .btn:hover {
-	color:#b00;
+.fe-opt-header .bar img {
+    float: left;
+    margin: 3px 0 0 3px;
 }
 
 .fe-opt-content {
-	position:absolute;
-	top:120px;
-	left:0;
-	bottom:0;
-	right:0;
 }
 .fe-opt-content .left{
-	position:absolute;
-	top:0;
-	left:0;
-	bottom:0;
 	width:200px;
 	border-right:5px solid #def;
 }
@@ -88,23 +49,6 @@ body {
 	margin:4px 0;
 	list-style:none;
 }
-.fe-opt-content .left li:hover{
-	background:#eee;
-	color:#b00;
-}
-.fe-opt-content .left li.selected{
-	background:#eee;
-	color:#b00;
-}
-.fe-opt-content .right{
-	position:absolute;
-	left:210px;
-}
-.fe-opt-content .right .title{
-	margin:20px 0 10px;
-	color:#48b;
-	font-weight:bold;
-}
 .fe-opt-content .right ul{
 	margin:0px;
 	padding:5px;
@@ -112,18 +56,49 @@ body {
 .fe-opt-content .right ul li{
 	margin:0 0 0 20px;
 	padding:5px;
+    line-height: 24px;
+}
+.fe-opt-content .right ul li input {
+    margin-right: 20px;
 }
 .fe-opt-content .right ul.no-list-style li{
 	margin:0;
 	list-style:none;
 }
-.fe-opt-content .right ul li:hover{
-	background:#f8f8f0;
+.fe-opt-content fieldset{
+    border: 1px solid #ccc;
+    border-radius: 5px;
+}
+.fe-opt-content fieldset legend{
+     padding: 0 5px;
+    color:#f00;
 }
 .fe-hide {
 	display:none;
 }
-
-.fe-opt-footer {
-	
+hr {
+    height: 1px ;
+    background: #ccc;
+    border: none;
+}
+.mod-btns {
+    padding: 10px;
 }
+.mod-btns .btn{
+    margin: 5px 10px;
+    cursor: pointer;
+    height: 30px;
+    width: 60px;
+    background: #f9f9f9;
+    border: 1px solid #ddd;
+    border-radius: 4px;
+}
+
+.mod-btns .btn.close {
+    background: #eee;
+    margin-left:0;
+    margin-right:20px;
+}
+.mod-btns .btn:hover {
+    color:#b00;
+}

+ 23 - 3
chrome/static/css/fe-popup.css

@@ -89,20 +89,40 @@ ul.fe-function-list li.-x-ajax-debugger b {
     background-position:-81px -129px;
 }
 ul.fe-function-list li i {
-    color: #f00;
+    color: #aaa;
     font-weight: 700;
+    font-style: normal;
 }
 .fe-feedback {
 	font-size:12px;
 	border-top:1px dotted #ddd;
 	padding:5px 15px 5px 5px;
-	text-align:right;
+    line-height: 20px;
+    color: #888;
 }
 .fe-feedback  a {
+    color:#888;
 	text-decoration:none;
-	color:#888;
+    text-align: left;
 }
 .fe-feedback  a:hover {
 	color:#a00;
 }
+svg:not(:root) {
+    overflow: hidden;
+}
+.fe-feedback .octicon {
+    vertical-align: text-bottom;
+}
+.fe-feedback .octicon {
+    display: inline-block;
+    fill: currentColor;
+}
+.fe-feedback .x-settings {
+    float: right;
+    cursor: pointer;
+}
+.fe-feedback .x-settings:hover {
+    color: #a00;
+}
 

+ 180 - 184
chrome/static/js/fe-option.js

@@ -2,194 +2,190 @@
  * FeHelper配置项
  * @author zhaoxianlie
  */
-baidu.feOption = (function(){
-	/**
-	 * 将这些配置项保存到background-page,这样才能对每个页面生效
-	 * @param {Object} items {key:value}
-	 */
-	var _saveOptionItemByBgPage = function(items){
-		for(var key in items){
-			window.localStorage.setItem(key,items[key]);
-		}
-	};
-	
-	/**
-	 * 从background-page获取配置项
-	 * @param {Object} items ["",""]
-	 * @return {key:value}
-	 */
-	var _getOptionItemByBgPage = function(items){
-		var rst = {};
-		for(var i = 0,len = items.length;i < len;i++){
-			rst[items[i]] = window.localStorage.getItem(items[i]);
+baidu.feOption = (function () {
+
+    // 页面json格式化强制开启
+    var pageJsonMustFormat = true;
+
+    /**
+     * 将这些配置项保存到background-page,这样才能对每个页面生效
+     * @param {Object} items {key:value}
+     */
+    var _saveOptionItemByBgPage = function (items) {
+        for (var key in items) {
+            window.localStorage.setItem(key, items[key]);
+        }
+    };
+
+    /**
+     * 从background-page获取配置项
+     * @param {Object} items ["",""]
+     * @return {key:value}
+     */
+    var _getOptionItemByBgPage = function (items) {
+        var rst = {};
+        for (var i = 0, len = items.length; i < len; i++) {
+            rst[items[i]] = window.localStorage.getItem(items[i]);
         }
         return rst;
     };
-	
-	/**
-	 * 向background-page发送请求,提取配置项
-	 * @param {Object} items
-	 * @param {Function} 回调方法
-	 */
-	var _goGetOptions = function(items,callback){
-		chrome.extension.sendMessage({
-			type : MSG_TYPE.GET_OPTIONS,
-			items : items
-		},callback);
-	};
-	
-	/**
-	 * 向background-page发送请求,保存配置项
-	 * @param {Object} items
-	 * @param {Object} callback
-	 */
-	var _goSetOptions = function(items){
-		chrome.extension.sendMessage({
-			type : MSG_TYPE.SET_OPTIONS,
-			items : items
-		});
-	};
-	
-	/**
-	 * 由background-page触发
-	 * @param {Object} items
-	 * @param {Object} callback
-	 */
-	var _doGetOptions = function(items,callback){
-		if(callback && typeof callback == 'function'){
-			callback.call(null,_getOptionItemByBgPage(items));
-		}
-	};
-	
-	/**
-	 * 由background-page触发
-	 * @param {Object} items
-	 * @param {Object} callback
-	 */
-	var _doSetOptions = function(items){
-		_saveOptionItemByBgPage(items);
-	};
-	
-	/**
-	 * 获取某一项配置
-	 * @param {String} optName 配置参数名
-	 */
-	var _getOptionItem = function(optName){
-		return _getOptionItemByBgPage([optName])[optName];
-	};
-	
-	/**
-	 * 保存启动项
-	 */
-	var _save_opt_form_start = 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);
-	};
-	
-	/**
-	 * 显示启动项
-	 */
-	var _show_opt_form_start = function(){
-		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 == 3) {
-					$('#' + item).val(opts[item]);
-				} else if(opts[item] === 'true') {
-					$('#' + item).attr('checked','checked');
-				}
-			});
-		})
-	};
-	
-	/**
-	 * 保存相应的表单配置
-	 * @param {Object} form_id
-	 */
-	var _save = function(form_id){
-		switch(form_id){
-			case 'opt_form_start':
-				_save_opt_form_start();
-				break;
-			case '':
-				
-				break;
-		}
-	};
-	
-	/**
-	 * 关闭配置页面
-	 */
-	var _closeTab = function(){
-        chrome.tabs.query({active:true, currentWindow:true}, function (tabs) {
+
+    /**
+     * 向background-page发送请求,提取配置项
+     * @param {Object} items
+     * @param {Function} 回调方法
+     */
+    var _goGetOptions = function (items, callback) {
+        chrome.extension.sendMessage({
+            type: MSG_TYPE.GET_OPTIONS,
+            items: items
+        }, callback);
+    };
+
+    /**
+     * 向background-page发送请求,保存配置项
+     * @param {Object} items
+     */
+    var _goSetOptions = function (items) {
+        chrome.extension.sendMessage({
+            type: MSG_TYPE.SET_OPTIONS,
+            items: items
+        });
+    };
+
+    /**
+     * 由background-page触发
+     * @param {Object} items
+     * @param {Object} callback
+     */
+    var _doGetOptions = function (items, callback) {
+        if (callback && typeof callback == 'function') {
+            callback.call(null, _getOptionItemByBgPage(items));
+        }
+    };
+
+    /**
+     * 由background-page触发
+     * @param {Object} items
+     */
+    var _doSetOptions = function (items) {
+        _saveOptionItemByBgPage(items);
+    };
+
+    /**
+     * 获取某一项配置
+     * @param {String} optName 配置参数名
+     */
+    var _getOptionItem = function (optName) {
+        return _getOptionItemByBgPage([optName])[optName];
+    };
+
+    // 所有配置项
+    var optionItems = [
+        'opt_item_contextMenus',
+        'EN_DECODE',
+        'CODE_BEAUTIFY',
+        'JSON_FORMAT',
+        'QR_CODE',
+        'COLOR_PICKER',
+        'REGEXP_TOOL',
+        'TIME_STAMP',
+        'IMAGE_BASE64',
+        'FCP_HELPER_DETECT',
+        'SHOW_PAGE_LOAD_TIME',
+        'AJAX_DEBUGGER'
+    ];
+    if (!pageJsonMustFormat) {
+        optionItems.push('JSON_PAGE_FORMAT');
+    }
+
+    /**
+     * 保存启动项
+     */
+    var _save_opt_form_start = function () {
+        var items = {};
+        $.each(optionItems, function (i, item) {
+            items[item] = $('#' + item).attr('checked');
+        });
+
+        _goSetOptions(items);
+    };
+
+    /**
+     * 显示启动项
+     */
+    var _show_opt_form_start = function () {
+        _goGetOptions(optionItems, function (opts) {
+            $.each(optionItems, function (i, item) {
+                if (opts[item] === 'false') {
+                    $('#' + item).removeAttr('checked');
+                }
+            });
+        })
+    };
+
+    /**
+     * 关闭配置页面
+     */
+    var _closeTab = function () {
+        chrome.tabs.query({active: true, currentWindow: true}, function (tabs) {
             var tab = tabs[0];
-			chrome.tabs.remove(tab.id);
-		});
-	};
-	
-	/**
-	 * 事件绑定
-	 */
-	var _bindEvent = function(){
-		//左边的可选项
-		$('#fe-opt-list-item>li').click(function(e){
-			var $this = $(this).siblings().removeClass('selected').end().addClass('selected');
-			$($this.attr('data-content')).siblings().removeClass('selected').addClass('fe-hide').end().removeClass('fe-hide').addClass('selected');
-		});
-		
-		//为每个表单注册submit事件
-		$('.right form').submit(function(e){
-	
-			//保存各个值
-			_save($(this).attr('id'));
-			
-			//关闭当前tab
-			_closeTab();
-			
-			e.preventDefault();
-			e.stopPropagation();
-		});
-		
-		//给保存按钮注册事件
-		$('#btn_close').click(function(){
-			//关闭当前tab
-			_closeTab();
-		});
-		
-		//给保存按钮注册事件
-		$('#btn_save').click(function(){
-			$('.right div.selected form').submit();				
-		});
-	};
-	
-	/**
-	 * 初始化各个配置项
-	 */
-	var _initOptions = function(){
-		_show_opt_form_start();
-	};
-	
-	/**
-	 * 初始化
-	 */
-	var _init = function(){
-		_bindEvent();
-		_initOptions();
-	};
-	
-	return {
-		init : _init,
-		doSetOptions : _doSetOptions,
-		doGetOptions : _doGetOptions,
-		getOptionItem : _getOptionItem,
-        getOptions : _goGetOptions,
-        setOptions : _goSetOptions
-	};
+            chrome.tabs.remove(tab.id);
+        });
+    };
+
+    /**
+     * 事件绑定
+     */
+    var _bindEvent = function () {
+
+        //给保存按钮注册事件
+        $('#btn_close').click(function () {
+            //关闭当前tab
+            _closeTab();
+        });
+
+        //给保存按钮注册事件
+        $('#btn_save').click(function () {
+
+            //保存各个值
+            _save_opt_form_start();
+
+            alert('恭喜,FeHelper配置修改成功!');
+
+            //关闭当前tab
+            _closeTab();
+
+            e.preventDefault();
+            e.stopPropagation();
+        });
+    };
+
+    /**
+     * 初始化各个配置项
+     */
+    var _initOptions = function () {
+        _show_opt_form_start();
+    };
+
+    /**
+     * 初始化
+     */
+    var _init = function () {
+        _bindEvent();
+        _initOptions();
+    };
+
+    return {
+        pageJsonMustFormat: pageJsonMustFormat,
+        optionItems: optionItems,
+        init: _init,
+        doSetOptions: _doSetOptions,
+        doGetOptions: _doGetOptions,
+        getOptionItem: _getOptionItem,
+        getOptions: _goGetOptions,
+        setOptions: _goSetOptions
+    };
 })();
 
 

+ 17 - 0
chrome/static/js/fe-popup.js

@@ -26,6 +26,23 @@ $(function () {
     bgPage.BgPageInstance.tellMeAjaxDbgSwitch(function (dbgSwitchOn) {
         $('li.-x-ajax-debugger span i').html(dbgSwitchOn ? '已开' : '已关');
     });
+
+    // 设置
+    jQuery('.fe-feedback .x-settings').click(function (e) {
+        chrome.tabs.create({
+            url: "template/fehelper_options.html",
+            active: true
+        });
+    });
+
+    // 根据配置,控制功能菜单的显示与隐藏
+    baidu.feOption.doGetOptions(baidu.feOption.optionItems, function (opts) {
+        opts && Object.keys(opts).forEach(function (item) {
+            if (opts[item] == 'false') {
+                $('li[data-msgtype="' + item + '"]').hide();
+            }
+        });
+    })
 });
 
 

+ 19 - 8
chrome/static/js/jsonformat/contentscript-jsonformat.js

@@ -70,7 +70,7 @@ baidu.csJsonFormat = (function () {
      * @param {Object} text
      */
     var _uniDecode = function (text) {
-        text = text.replace(/\\/g, "%").replace('%U','%u').replace('%u0025', '%25');
+        text = text.replace(/\\/g, "%").replace('%U', '%u').replace('%u0025', '%25');
 
         text = unescape(text.toString().replace(/%2B/g, "+"));
         var matches = text.match(/(%u00([0-9A-F]{2}))/gi);
@@ -139,15 +139,15 @@ baidu.csJsonFormat = (function () {
                 newSource = JSON.stringify(jsonObj);
                 // 如果newSource的长度比原source长度短很多的话,猜测应该是格式化错了,需要撤销操作
                 // 这里一定要unicode decode一下,要不然会出现误判
-                if(newSource.length * 2 < (_uniDecode(source)).length) {
-                    return ;
+                if (newSource.length * 2 < (_uniDecode(source)).length) {
+                    return;
                 }
                 // 直接replace掉所有\w之外的字符,再和原内容比较
-                var r_ns = newSource.replace(/[^\w]/gm,'').length;
-                var r_os = _uniDecode(source).replace(/[^\w]/gm,'').length;
+                var r_ns = newSource.replace(/[^\w]/gm, '').length;
+                var r_os = _uniDecode(source).replace(/[^\w]/gm, '').length;
                 // 允许内容产生1/20的误差
-                if(Math.abs(r_ns - r_os) > (r_ns + r_os) / 20) {
-                    return ;
+                if (Math.abs(r_ns - r_os) > (r_ns + r_os) / 20) {
+                    return;
                 }
             } catch (ex) {
                 // 通过JSON反解不出来的,一定有问题
@@ -187,7 +187,18 @@ baidu.csJsonFormat = (function () {
     var _init = function () {
         $(function () {
             if (!/^filesystem\:/.test(location.href)) {
-                _format();
+                if(baidu.feOption.pageJsonMustFormat) {
+                    _format();
+                }else{
+                    chrome.extension.sendMessage({
+                        type: MSG_TYPE.GET_OPTIONS,
+                        items: ['JSON_PAGE_FORMAT']
+                    }, function (opts) {
+                        if (opts.JSON_PAGE_FORMAT !== 'false') {
+                            _format();
+                        }
+                    });
+                }
             }
         });
     };

+ 1 - 0
chrome/static/js/mod/mod_popup.js

@@ -20,4 +20,5 @@
 
 importScript("js/core/core.js");
 importScript("js/core/fe-const.js");
+importScript("js/fe-option.js");
 importScript("js/fe-popup.js");

Файловите разлики са ограничени, защото са твърде много
+ 0 - 0
chrome/template/fehelper_options.html


Файловите разлики са ограничени, защото са твърде много
+ 0 - 0
chrome/template/fehelper_popup.html


Някои файлове не бяха показани, защото твърде много файлове са промени