diff --git a/README.md b/README.md index 520d98930c348ef5b19530633a7c2189b4a12655..81b2130d4262dbbfb65bbcea920b9e99808fca9f 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 c3fbf05a1787d79fde1a86b0c75bab3c41f8ef86..3b2f1356ba470cc6ca739fa2cb4d6d953fbc0bee 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 04adf0f9342c20a3d31fc2ee5dfa60c9bc4e0b30..b34aec70df383f43e34049ec512a60c0925c80f0 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 d74d0da76d63f4461b2d13944cf872a6aea7fae0..3a1ca8718078fe39899c53273dabf1e7e0266473 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 e7096e04cd592af0297c3a321991b5aa53ce1163..d5ed63867a17f68496a0ad123deecef1c935f947 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");