Skip to content

Commit

Permalink
init git
Browse files Browse the repository at this point in the history
  • Loading branch information
didierfred committed Dec 27, 2018
1 parent b4bea99 commit 84767bc
Show file tree
Hide file tree
Showing 10 changed files with 7,271 additions and 2 deletions.
5 changes: 5 additions & 0 deletions GreenIT-Analysis.html
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>
110 changes: 110 additions & 0 deletions GreenPanel.html
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>
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
# GreenIT-Analysis
GreenIT-Analysis
# GreenIT-Analysis

Extension pour firefox .








131 changes: 131 additions & 0 deletions background.js
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));
}







6 changes: 6 additions & 0 deletions css/bootstrap.min.css

Large diffs are not rendered by default.

Binary file added icons/ecoindex-48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions manifest.json
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"

}



10 changes: 10 additions & 0 deletions script/GreenIT-Analysis.js
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
}
);
Loading

0 comments on commit 84767bc

Please sign in to comment.