-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b4bea99
commit 84767bc
Showing
10 changed files
with
7,271 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<html> | ||
<body> | ||
<script src="script/GreenIT-Analysis.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<!DOCTYPE html> | ||
|
||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<link rel="stylesheet" href="css/bootstrap.min.css"> | ||
|
||
<style type="text/css"> | ||
.grade { | ||
display:inline-block; | ||
width:24px; | ||
height:24px; | ||
text-align:center; | ||
border-radius:50%; | ||
background-color:#f00; | ||
font-size: 18px; | ||
line-height: 22px; | ||
} | ||
|
||
|
||
.grade.A { | ||
background-color:#349A47; | ||
color:#fff; | ||
} | ||
.grade.B { | ||
background-color:#51B84B; | ||
color:#fff; | ||
} | ||
.grade.C { | ||
background-color:#CADB2A | ||
} | ||
.grade.D { | ||
background-color:#F6EB15 | ||
} | ||
.grade.E { | ||
background-color:#FECD06 | ||
} | ||
.grade.F { | ||
background-color:#F99839; | ||
color:#fff; | ||
} | ||
.grade.G { | ||
background-color:#ED2124; | ||
color:#fff; | ||
} | ||
|
||
|
||
|
||
th, td { | ||
// word-break: break-all; | ||
border: 1px solid white; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
white-space: nowrap; | ||
} | ||
|
||
table { | ||
border-collapse: collapse; | ||
table-layout: fixed; | ||
width: 450px; | ||
} | ||
|
||
</style> | ||
|
||
</head> | ||
|
||
<body> | ||
<center> | ||
<div class="container-fluid"> | ||
|
||
|
||
|
||
<input type="button" class="btn btn-primary btn-sm" style="width:100px" id="launchAnalyse" value="Launch analyse"></input> | ||
<input type="button" class="btn btn-primary btn-sm" style="width:100px" id="viewHistory" value="History"></input> | ||
|
||
</div> | ||
|
||
<script type="text/javascript" src="script/greenpanel.js"> </script> | ||
<br> | ||
|
||
<div id="results" hidden> | ||
|
||
<table class="table table-condensed"> | ||
<tbody> | ||
<tr> | ||
<td>Request number </td><td id="requestNumber"></td> | ||
</tr> | ||
<tr> | ||
<td>Size (Kb) </td><td id="responsesSize"></td> | ||
</tr> | ||
<tr> | ||
<td>DOM Size </td> <td id="domSize"></td> | ||
</tr> | ||
<tr> | ||
<td>Eco Index </td><td id="ecoIndex"></td> | ||
</tr> | ||
<tr> | ||
<td>Grade </td><td id="grade"></td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
|
||
</div> | ||
|
||
|
||
</center> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,11 @@ | ||
# GreenIT-Analysis | ||
GreenIT-Analysis | ||
# GreenIT-Analysis | ||
|
||
Extension pour firefox . | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
|
||
|
||
|
||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
* | ||
* @author [email protected] | ||
*/ | ||
|
||
"use strict"; | ||
|
||
var connections = {}; | ||
|
||
var analysis = { | ||
nbRequest:0, | ||
byteTotal:0, | ||
domSize:0, | ||
url:"", | ||
pluginNumber:0 | ||
} | ||
|
||
|
||
chrome.runtime.onMessage.addListener(notify); | ||
|
||
|
||
console.log("start background process"); | ||
|
||
// Listen to message from devTools | ||
chrome.runtime.onConnect.addListener(function(devToolsConnection) { | ||
console.log("received onConnect"); | ||
// assign the listener function to a variable so we can remove it later | ||
var devToolsListener = function(message, sender, sendResponse) { | ||
// Inject a content script into the identified tab | ||
console.log("received script to execute form tabId " + message.tabId); | ||
if (!connections[message.tabId]) connections[message.tabId] = devToolsConnection; | ||
analysis.domSize=0; | ||
chrome.tabs.executeScript(message.tabId, | ||
{ file: message.scriptToInject , allFrames:true}); | ||
} | ||
// add the listener | ||
devToolsConnection.onMessage.addListener(devToolsListener); | ||
|
||
devToolsConnection.onDisconnect.addListener(function(port) { | ||
devToolsConnection.onMessage.removeListener(devToolsListener); | ||
var tabs = Object.keys(connections); | ||
for (var i=0, len=tabs.length; i < len; i++) { | ||
if (connections[tabs[i]] == port) { | ||
delete connections[tabs[i]] | ||
break; | ||
} | ||
} | ||
}); | ||
|
||
|
||
}); | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
/* | ||
* Listen for message form ecoindex.js | ||
* if message is on : start the record | ||
* if message is off : stop the record | ||
* if message is analysis.domSize, calcul eco_index and store results in localstorage | ||
**/ | ||
function notify(request, sender, sendResponse) { | ||
|
||
var json_message = JSON.parse(request); | ||
|
||
if (json_message.url) { | ||
console.log("End analysis for url : "+ json_message.url); | ||
console.log("Dom Size received: "+ json_message.pageAnalysis.domSize); | ||
analysis.domSize+=json_message.pageAnalysis.domSize; | ||
analysis.pluginNumber+=json_message.pageAnalysis.pluginNumber; | ||
console.log("Dom Size total: "+ analysis.domSize); | ||
} | ||
|
||
if (sender.tab) { | ||
var tabId = sender.tab.id; | ||
if (tabId in connections) connections[tabId].postMessage(analysis.domSize); | ||
else console.log("Tab not found in connection list."); | ||
} | ||
else console.log("sender.tab not defined."); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
function computePagesAnalysis() { | ||
console.log("compute analysis"); | ||
var eco_index= calculEcoIndex(analysis.domSize,analysis.nbRequest,Math.round(analysis.byteTotal/1000)); | ||
console.log("ecoindex=" + eco_index); | ||
localStorage.setItem("eco_index",eco_index); | ||
localStorage.setItem("note",getNote(eco_index)); | ||
localStorage.setItem("dom_size",analysis.domSize); | ||
storeInHistory(analysis.url,analysis.nbRequest,Math.round(analysis.byteTotal/1000),analysis.domSize,eco_index,getNote(eco_index)); | ||
} | ||
|
||
/** | ||
Add to the history the result of an analyse | ||
**/ | ||
function storeInHistory(url,req,kbyte,domsize,eco_index,note) | ||
{ | ||
var analyse_history; | ||
var string_analyse_history = localStorage.getItem("analyse_history"); | ||
|
||
if (string_analyse_history) | ||
{ | ||
analyse_history =JSON.parse(string_analyse_history); | ||
analyse_history.reverse(); | ||
analyse_history.push({result_date:new Date(),url:url,req:req,kbyte:kbyte,domsize:domsize,eco_index:eco_index,note:note}); | ||
analyse_history.reverse(); | ||
} | ||
else analyse_history = [{result_date:new Date(),url:url,req:req,kbyte:kbyte,domsize:domsize,eco_index:eco_index,note:note}]; | ||
|
||
localStorage.setItem("analyse_history",JSON.stringify(analyse_history)); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
|
||
"description": "GreenIT-Analysis", | ||
"manifest_version": 2, | ||
"name": "GreenIT-Analysis", | ||
"version": "0.1", | ||
"homepage_url": "https://github.com/didierfred/GreenIT-Analysis", | ||
"icons": { | ||
"48": "icons/ecoindex-48.png" | ||
}, | ||
"permissions": [ | ||
"activeTab","tabs","storage","webRequest", "webRequestBlocking", "<all_urls>" | ||
], | ||
"background": { | ||
"scripts": ["background.js"] | ||
}, | ||
"devtools_page": "GreenIT-Analysis.html" | ||
|
||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
|
||
|
||
chrome.devtools.panels.create("GreenIT", | ||
"../icons/ecoindex-48.png", | ||
"../GreenPanel.html", | ||
function(panel) { | ||
// code invoked on panel creation | ||
} | ||
); |
Oops, something went wrong.