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 {
else {
console.log("Load default config");
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};
// save configuration
localStorage.setItem("config",JSON.stringify(config));
......@@ -92,7 +92,7 @@ function log(message) {
function rewriteRequestHeader(e) {
if (config.debug_mode) log("Start modify request headers for url " + e.url);
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"){
let new_header = {"name" :to_modify.header_name,"value":to_modify.header_value};
e.requestHeaders.push(new_header);
......@@ -130,7 +130,7 @@ function rewriteRequestHeader(e) {
function rewriteResponseHeader(e) {
if (config.debug_mode) log("Start modify response headers for url " + e.url);
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") {
let new_header = {"name" :to_modify.header_name,"value":to_modify.header_value};
e.responseHeaders.push(new_header);
......
......@@ -59,8 +59,8 @@
<a href="#" id="import_button" class="btn btn-primary btn-sm" >
<span class="glyphicon glyphicon-import"></span> Import
</a>
<a href="#" id="parameters_button" class="btn btn-primary btn-sm">
<span class="glyphicon glyphicon-cog"></span>
<a href="#" id="parameters_button" class="btn btn-primary btn-sm">
<span class="glyphicon glyphicon-cog"></span> Parameters
</a>
</div>
</div>
......
......@@ -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);
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('import_button').addEventListener('click',function (e) {importData(e);});
document.getElementById('parameters_button').addEventListener('click',function (e) {showParametersScreen();});
document.getElementById('add_button').addEventListener('click',function (e) {appendLine("","add","-","-","","req","on");});
document.getElementById('start_img').addEventListener('click',function (e) {startModify();});
document.getElementById('targetPage').value=config.target_page;
checkTargetPageField();
document.getElementById('targetPage').addEventListener('keyup',function (e) {checkTargetPageField();});
document.getElementById('exit_parameters_screen_button').addEventListener('click',function (e) {hideParametersScreen();});
......@@ -62,6 +63,7 @@ function showParametersScreen() {
function hideParametersScreen() {
document.getElementById('main_screen').hidden=false;
document.getElementById('parameters_screen').hidden=true;
saveData();
}
function showCommentsClick() {
......@@ -245,11 +247,13 @@ function isTargetValid(target) {
* 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() {
if (!isTargetValid(document.getElementById('targetPage').value)) {
alert("Can not save configuration: Url patterns are invalid");
return false;
}
localStorage.setItem("config",create_configuration_data());
browser.runtime.sendMessage("reload");
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