From bfe4eed04e7f86ad76e281b075190c69cfdd446c Mon Sep 17 00:00:00 2001
From: didierfred <didierfred@gmail.com>
Date: Tue, 9 Jan 2018 15:22:49 +0100
Subject: [PATCH] Comments, clean code and documentation

---
 README.md         | 16 +++++++++++++---
 background.js     | 42 +++++++++++++++++++++++++++++-------------
 manifest.json     | 12 ++++++------
 popup/config.html | 11 ++++++-----
 popup/config.js   |  8 ++++++--
 5 files changed, 60 insertions(+), 29 deletions(-)

diff --git a/README.md b/README.md
index 520d989..81b2130 100644
--- a/README.md
+++ b/README.md
@@ -1,12 +1,22 @@
 # SimpleModifyHeader
 
-## What it does
+Extension for firefox . 
 
-This extension rewrite the header. 
+The extension rewrite the header based on a rules table. 
 
-You can configure rules to add,modify or remove headers.
+The rules table contains lines with the following parameters :
+- action : add, modify or delete a header field
+- header field name
+- header field value 
+- status : on if the modification is active , off otherwise 
 
+We can choose the urls on which the modifications applies by modifying the url pattern.
 
+To save and apply the modification , you need to click on the save button
+
+The extension can be start and stop via the button on the top right.
+
+The code is opensource under Mozilla Public License 2.0 
 
 
 
diff --git a/background.js b/background.js
index c3fbf05..3b2f135 100644
--- a/background.js
+++ b/background.js
@@ -1,7 +1,11 @@
 
 /* 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/. */
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. 
+ *
+ * @author didierfred@gmail.com
+ * @version 0.1
+ */
 
 
 "use strict";
@@ -31,18 +35,24 @@ else targetPage = localStorage.getItem('targetPage');
 if (!localStorage.getItem('started')) localStorage.setItem('started',started);
 else started = localStorage.getItem('started');
 
-if (started=="on") addListener();
+if (started=="on") 
+		{
+		addListener();
+		browser.browserAction.setIcon({ path: "icons/modify-green-32.png"});
+		}
 
 
 // listen for change in configuration or start/stop 
 browser.runtime.onMessage.addListener(notify);
 
-/**
-Rewrite the header
-**/
-function rewriteHeader(e) {
-  
-  window.console.info("IT Works");
+/*
+* Rewrite the header (add , modify or delete)
+*
+* 
+*/
+function rewriteHeader(e) 
+{
+
   for (var to_modify of modifyTable)
 	{
 		if (to_modify[3]=="on")
@@ -81,7 +91,13 @@ function rewriteHeader(e) {
 
 
 
-
+/*
+* Listen for message form config.js
+* if message is reload : reload the configuration 
+* if message is on : start the modify header 
+* if message is off : stop the modify header
+*
+**/
 function notify(message) 
 	{
 	if (message=="reload") 
@@ -98,21 +114,21 @@ function notify(message)
 	else if (message=="off")
 		{
 		browser.webRequest.onBeforeSendHeaders.removeListener(rewriteHeader);
+		browser.browserAction.setIcon({ path: "icons/modify-32.png"});
 		started="off";
 		}
 
 	else if (message=="on")
 		{
 		addListener();
+		browser.browserAction.setIcon({ path: "icons/modify-green-32.png"});
 		started="on";
 		}
   	}
 
 /*
-Add rewriteHeader as a listener to onBeforeSendHeaders,
-only for the target page.
-
-Make it "blocking" so we can modify the headers.
+* Add rewriteHeader as a listener to onBeforeSendHeaders, only for the target page.
+* Make it "blocking" so we can modify the headers.
 */
 function addListener()
 	{
diff --git a/manifest.json b/manifest.json
index 04adf0f..b34aec7 100644
--- a/manifest.json
+++ b/manifest.json
@@ -1,16 +1,16 @@
 {
 
-  "description": "Modify header nouvelle version ",
+  "description": "Simple Modify header ",
   "manifest_version": 2,
-  "name": "modify-header-2",
-  "version": "0.1",
+  "name": "simple-modify-header",
+  "version": "1",
   "homepage_url": "https://a_defenirnir",
   "icons": {
-    "48": "icons/person-48.png"
+    "48": "icons/modify-48.png"
   },
 
   "permissions": [
-    "activeTab","storage","webRequest", "webRequestBlocking", "https://httpbin.org/*" 
+    "activeTab","storage","webRequest", "webRequestBlocking", "<all_urls>" 
   ],
   
   "background": {
@@ -18,7 +18,7 @@
   },
 
   "browser_action": {
-    "default_icon": "icons/person-32.png",
+    "default_icon": "icons/modify-32.png",
     "default_title": "Modify a header",
     "default_popup": "popup/config.html"
   }
diff --git a/popup/config.html b/popup/config.html
index d74d0da..3a1ca87 100644
--- a/popup/config.html
+++ b/popup/config.html
@@ -10,12 +10,13 @@
 
 <table>
 <tr>
-<td width="530">
-  <h1> SIMPLE MODIFY HEADER   </h1> 
+<td width="450">
+  <h2> SIMPLE MODIFY HEADER   </h2> 
 
   Url Pattern : <input id="targetPage"  type="text" value=""></input>
 </td>
-<td width="200">
+<td width="50">
+<br>
 <img id="start_img" src="img/start.png" align="right" valign="center"> </img> 
 </td>
 </tr>
@@ -26,8 +27,8 @@
   <table id="config_tab" id="config"> 
 	<tr> 
 		<td> Action </td>		
-		<td> Header Name </td>
-		<td> Header Value </td>
+		<td> Header Field Name </td>
+		<td> Header Field Value </td>
 		<td> Status </td>
 	</tr>
   </table>
diff --git a/popup/config.js b/popup/config.js
index e7096e0..d5ed638 100644
--- a/popup/config.js
+++ b/popup/config.js
@@ -2,7 +2,11 @@
 
 /* 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/. */
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. 
+ *
+ * @author didierfred@gmail.com
+ * @version 0.1
+ */
 
 
 var line_number = 1;
@@ -25,7 +29,7 @@ function appendLine(action,header_name,header_value,status) {
 var html = "<td><select id=\"select_action" + line_number + "\" disable=false><option value=\"add\">add</option><option value=\"modify\">modify</option><option value=\"delete\">delete</option></select></td>";
 html = html + "<td><input id=\"header_name"+ line_number +"\" value=\"" + header_name + "\"></input></td>";
 html = html + "<td><input id=\"header_value"+ line_number +"\" value=\"" + header_value + "\"></input></td>";
-html = html + "<td><select id=\"select_status" + line_number + "\"><option value=\"on\"> ON </option><option value=\"off\">OFF</option></select></td>";
+html = html + "<td><select id=\"select_status" + line_number + "\"><option value=\"on\"> on </option><option value=\"off\">off</option></select></td>";
 html = html + "<td><input type=\"button\" value=\"DELETE\" id=\"delete_button" + line_number + "\"></input> </td>";
 
 var newTR = document.createElement("tr");
-- 
GitLab