Explorar el Código

升级页面检测功能,并且使得插件支持本地网页,即file://开头的url

Alien hace 12 años
padre
commit
cfac4361eb

+ 2 - 2
chrome/manifest.json

@@ -1,6 +1,6 @@
 { 
 	"name": "WEB前端助手(FeHelper)", 
-	"version": "3.0",
+	"version": "3.1",
     "manifest_version": 2,
 	 
 	"default_locale": "zh_CN", 
@@ -48,7 +48,7 @@
     ],
 
 	"content_scripts": [{	
-		"matches":["http://*/*","https://*/*"],
+		"matches":["http://*/*","https://*/*","file://*/*"],
 		"js":[
 			"static/js/core/jquery-1.5.min.js",
 			"static/vendor/jquery-ui-1.8/js/jquery-ui-1.8.11.custom.min.js",

+ 2 - 2
chrome/online.manifest.json

@@ -1,6 +1,6 @@
 {
     "name": "WEB前端助手(FeHelper)",
-    "version": "3.0",
+    "version": "3.1",
     "manifest_version": 2,
 
     "default_locale": "zh_CN",
@@ -48,7 +48,7 @@
     ],
 
 	"content_scripts": [{	
-		"matches":["http://*/*","https://*/*"],
+		"matches":["http://*/*","https://*/*","file://*/*"],
 		"js":[
 			"static/js/core/jquery-1.5.min.js",
 			"static/vendor/jquery-ui-1.8/js/jquery-ui-1.8.11.custom.min.js",

+ 7 - 7
chrome/static/js/fe-background.js

@@ -40,7 +40,7 @@ var BgPageInstance = (function(){
 			//正在准备数据,请稍等...
 			//显示桌面提醒
 			baidu.feNotification.notifyText({
-				message : "\u6B63\u5728\u51C6\u5907\u6570\u636E\uFF0C\u8BF7\u7A0D\u7B49..."
+				message : "正在准备数据,请稍等..."
 			});	
 		}
 	};
@@ -70,7 +70,7 @@ var BgPageInstance = (function(){
 			_notificationCache[tab.id].cancel();	
 			if(!wpoInfo) {
 				baidu.feNotification.notifyText({
-					message : "\u5BF9\u4E0D\u8D77\uFF0C\u68C0\u6D4B\u5931\u8D25"
+					message : "对不起,检测失败"
 				});	
 			}else{
                 if(webkitNotifications.createHTMLNotification) {
@@ -93,7 +93,7 @@ var BgPageInstance = (function(){
 		chrome.tabs.getSelected(null,function(tab){	
 			//显示桌面提醒
 			_notificationCache[tab.id] = baidu.feNotification.notifyText({
-					message : "\u6B63\u5728\u7EDF\u8BA1\uFF0C\u8BF7\u7A0D\u540E...",
+					message : "正在统计,请稍后...",
 					autoClose : false
 				});	
 	        chrome.tabs.sendMessage(tab.id,{
@@ -185,10 +185,10 @@ var BgPageInstance = (function(){
 	var _createContextMenu = function(){
 		_removeContextMenu();
 		baidu.contextMenuId = chrome.contextMenus.create({
-			title : "FeHelper-FE\u52A9\u624B"
+			title : "FeHelper-FE助手"
 		});
 		chrome.contextMenus.create({
-			title : "\u7F16\u7801\u68C0\u6D4B",
+			title : "编码检测",
 			parentId : baidu.contextMenuId,
 			onclick : function(info,tab) {
 				//编码检测
@@ -196,7 +196,7 @@ var BgPageInstance = (function(){
 			}
 		});
 		chrome.contextMenus.create({
-			title : "\u6805\u683C\u68C0\u6D4B",
+			title : "栅格检测",
 			parentId : baidu.contextMenuId,
 			onclick : function(info,tab) {
 				//执行栅格检测
@@ -204,7 +204,7 @@ var BgPageInstance = (function(){
 			}
 		});
 		chrome.contextMenus.create({
-			title : "\u7F51\u9875\u52A0\u8F7D\u8017\u65F6",
+			title : "网页加载耗时",
 			parentId : baidu.contextMenuId,
 			onclick : function(info,tab) {
 				//网页加载耗时

+ 30 - 2
chrome/static/js/wpo/fe-calc-wpo.js

@@ -10,7 +10,7 @@ baidu.calcPageLoadTime = (function(){
 	 * @return {[type]}
 	 */
 	var getHttpHeaders = function(){
-		if(wpoInfo.header && wpoInfo.time) {
+		if(wpoInfo.header && wpoInfo.time && wpoInfo.pageInfo) {
 	    	sendWpoInfo();
 		}else{
 			$.ajax({
@@ -30,6 +30,8 @@ baidu.calcPageLoadTime = (function(){
 			    		"exprires" : xhr.getResponseHeader('Exprires'),
 			    		"lastModified" : xhr.getResponseHeader('Last-Modified')
 			    	};
+
+                    getPageInfo();
 			    	getPageLoadTime();
 			    	sendWpoInfo();
 			 	}
@@ -37,6 +39,16 @@ baidu.calcPageLoadTime = (function(){
 		}
 	};
 
+    /**
+     * 页面相关信息
+     */
+    var getPageInfo = function(){
+        wpoInfo.pageInfo = {
+            title : document.title,
+            url : location.href
+        };
+    };
+
 	/**
 	 * 获取网页的加载时间
 	 */
@@ -54,13 +66,29 @@ baidu.calcPageLoadTime = (function(){
 			wpo : wpoInfo
 		});
 	};
+
+    /**
+     * 提取wpo信息
+     */
+    var getWpoInfo = function(){
+        // 如果是网络地址,才去获取header
+        if(/^((http)|(https))\:\/\//.test(location.href)) {
+            getHttpHeaders();
+        }
+        // 否则只提取performance信息
+        else{
+            getPageInfo();
+            getPageLoadTime();
+            sendWpoInfo();
+        }
+    };
 	
 	var init = function(){
 		chrome.extension.onMessage.addListener(function(request,sender,callback){
 			// 获取页面相关性能数据
 			if(request.type == MSG_TYPE.GET_PAGE_WPO_INFO) {
 				(function check() {
-			        (document.readyState == "complete") ? getHttpHeaders() : setTimeout(check, 1000);
+			        (document.readyState == "complete") ? getWpoInfo() : setTimeout(check, 1000);
 			    })();
 			}
 		});

+ 18 - 6
chrome/static/js/wpo/fe-wpo.js

@@ -12,13 +12,20 @@ baidu.pageLoadTime = (function(){
 	 * 获取网页的加载时间
 	 */
 	var init = function(){
+        // 获得wpo信息
+        var wpoStr = decodeURIComponent(location.search.substring(1));
+        var wpo = JSON.parse(wpoStr);
+
+        // 页面信息
+        document.getElementById("pageTitle").innerHTML = wpo.pageInfo.title || "无";
+        document.getElementById("pageUrl").innerHTML = wpo.pageInfo.url || "无";
+
+        // 各阶段加载时间
 		 function set(id, value) {
             try{
 	           document.getElementById(id).innerHTML = value + ' ms';
             }catch(e){}
 	     }
-		 var wpoStr = decodeURIComponent(location.search.substring(1));
-         var wpo = JSON.parse(wpoStr);
          var t = wpo.time;
          var start = t.redirectStart == 0 ? t.fetchStart : t.redirectStart;
          set('dns', t.domainLookupEnd - t.domainLookupStart);
@@ -35,11 +42,16 @@ baidu.pageLoadTime = (function(){
          set('domCompleteTotal' , t.domComplete - start);
          set('loadTotal' , t.loadEventEnd - start);
 
+        // HTTP Header
          var h = wpo.header;
-         for(var key in h) {
-            try{
-              document.getElementById(key).innerHTML = h[key] || ' - ';
-            }catch(e){}
+         if(!h) {
+             document.getElementById("pageHeaderInfo").style.display = "none";
+         }else{
+             for(var key in h) {
+                 try{
+                     document.getElementById(key).innerHTML = h[key] || ' - ';
+                 }catch(e){}
+             }
          }
 	};
 	return {

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 0 - 0
chrome/template/fehelper_wpo.html


Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio