Skip to content
Snippets Groups Projects
Commit 5f31b7ef authored by didierfred's avatar didierfred
Browse files

add filter per rules

parent 904fa3a2
No related branches found
No related tags found
No related merge requests found
...@@ -54,7 +54,7 @@ else { ...@@ -54,7 +54,7 @@ else {
else { else {
console.log("Load default config"); console.log("Load default config");
let headers = []; let headers = [];
headers.push({action:"add",header_name:"test-header-name",header_value:"test-header-value",comment:"test",apply_on:"req",status:"on"}); headers.push({url_contains:"",action:"add",header_name:"test-header-name",header_value:"test-header-value",comment:"test",apply_on:"req",status:"on"});
config = {format_version:"1.1",target_page:"https://httpbin.org/*",headers:headers,debug_mode:false}; config = {format_version:"1.1",target_page:"https://httpbin.org/*",headers:headers,debug_mode:false};
// save configuration // save configuration
localStorage.setItem("config",JSON.stringify(config)); localStorage.setItem("config",JSON.stringify(config));
...@@ -92,7 +92,7 @@ function log(message) { ...@@ -92,7 +92,7 @@ function log(message) {
function rewriteRequestHeader(e) { function rewriteRequestHeader(e) {
if (config.debug_mode) log("Start modify request headers for url " + e.url); if (config.debug_mode) log("Start modify request headers for url " + e.url);
for (let to_modify of config.headers) { for (let to_modify of config.headers) {
if ((to_modify.status==="on")&&(to_modify.apply_on==="req")) { if ((to_modify.status==="on")&&(to_modify.apply_on==="req")&& (!config.use_url_contains || (config.use_url_contains && e.url.includes(to_modify.url_contains)))) {
if (to_modify.action==="add"){ if (to_modify.action==="add"){
let new_header = {"name" :to_modify.header_name,"value":to_modify.header_value}; let new_header = {"name" :to_modify.header_name,"value":to_modify.header_value};
e.requestHeaders.push(new_header); e.requestHeaders.push(new_header);
...@@ -130,7 +130,7 @@ function rewriteRequestHeader(e) { ...@@ -130,7 +130,7 @@ function rewriteRequestHeader(e) {
function rewriteResponseHeader(e) { function rewriteResponseHeader(e) {
if (config.debug_mode) log("Start modify response headers for url " + e.url); if (config.debug_mode) log("Start modify response headers for url " + e.url);
for (let to_modify of config.headers) { for (let to_modify of config.headers) {
if ((to_modify.status==="on")&&(to_modify.apply_on==="res")) { if ((to_modify.status==="on")&&(to_modify.apply_on==="res")&& (!config.use_url_contains || (config.use_url_contains && e.url.includes(to_modify.url_contains)))) {
if (to_modify.action==="add") { if (to_modify.action==="add") {
let new_header = {"name" :to_modify.header_name,"value":to_modify.header_value}; let new_header = {"name" :to_modify.header_name,"value":to_modify.header_value};
e.responseHeaders.push(new_header); e.responseHeaders.push(new_header);
......
...@@ -59,8 +59,8 @@ ...@@ -59,8 +59,8 @@
<a href="#" id="import_button" class="btn btn-primary btn-sm" > <a href="#" id="import_button" class="btn btn-primary btn-sm" >
<span class="glyphicon glyphicon-import"></span> Import <span class="glyphicon glyphicon-import"></span> Import
</a> </a>
<a href="#" id="parameters_button" class="btn btn-primary btn-sm"> <a href="#" id="parameters_button" class="btn btn-primary btn-sm">
<span class="glyphicon glyphicon-cog"></span> <span class="glyphicon glyphicon-cog"></span> Parameters
</a> </a>
</div> </div>
</div> </div>
......
...@@ -33,13 +33,14 @@ window.onload = function() { ...@@ -33,13 +33,14 @@ window.onload = function() {
} }
for (let to_add of config.headers) appendLine(to_add.url_contains,to_add.action,to_add.header_name,to_add.header_value,to_add.comment,to_add.apply_on,to_add.status); for (let to_add of config.headers) appendLine(to_add.url_contains,to_add.action,to_add.header_name,to_add.header_value,to_add.comment,to_add.apply_on,to_add.status);
document.getElementById('save_button').addEventListener('click',function (e) {saveData();}); document.getElementById('save_button').addEventListener('click',function (e) {saveDataWithWarning();});
document.getElementById('export_button').addEventListener('click',function (e) {exportData();}); document.getElementById('export_button').addEventListener('click',function (e) {exportData();});
document.getElementById('import_button').addEventListener('click',function (e) {importData(e);}); document.getElementById('import_button').addEventListener('click',function (e) {importData(e);});
document.getElementById('parameters_button').addEventListener('click',function (e) {showParametersScreen();}); document.getElementById('parameters_button').addEventListener('click',function (e) {showParametersScreen();});
document.getElementById('add_button').addEventListener('click',function (e) {appendLine("","add","-","-","","req","on");}); document.getElementById('add_button').addEventListener('click',function (e) {appendLine("","add","-","-","","req","on");});
document.getElementById('start_img').addEventListener('click',function (e) {startModify();}); document.getElementById('start_img').addEventListener('click',function (e) {startModify();});
document.getElementById('targetPage').value=config.target_page; document.getElementById('targetPage').value=config.target_page;
checkTargetPageField();
document.getElementById('targetPage').addEventListener('keyup',function (e) {checkTargetPageField();}); document.getElementById('targetPage').addEventListener('keyup',function (e) {checkTargetPageField();});
document.getElementById('exit_parameters_screen_button').addEventListener('click',function (e) {hideParametersScreen();}); document.getElementById('exit_parameters_screen_button').addEventListener('click',function (e) {hideParametersScreen();});
...@@ -62,6 +63,7 @@ function showParametersScreen() { ...@@ -62,6 +63,7 @@ function showParametersScreen() {
function hideParametersScreen() { function hideParametersScreen() {
document.getElementById('main_screen').hidden=false; document.getElementById('main_screen').hidden=false;
document.getElementById('parameters_screen').hidden=true; document.getElementById('parameters_screen').hidden=true;
saveData();
} }
function showCommentsClick() { function showCommentsClick() {
...@@ -245,11 +247,13 @@ function isTargetValid(target) { ...@@ -245,11 +247,13 @@ function isTargetValid(target) {
* If url patterns are valid save the data to the local storage and restart modify header * If url patterns are valid save the data to the local storage and restart modify header
**/ **/
function saveDataWithWarning() {
if (!isTargetValid(document.getElementById('targetPage').value)) alert("Warning: Url patterns are invalid");
saveData();
}
function saveData() { function saveData() {
if (!isTargetValid(document.getElementById('targetPage').value)) {
alert("Can not save configuration: Url patterns are invalid");
return false;
}
localStorage.setItem("config",create_configuration_data()); localStorage.setItem("config",create_configuration_data());
browser.runtime.sendMessage("reload"); browser.runtime.sendMessage("reload");
return true; return true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment