diff --git a/background.js b/background.js index 32e72cb08830ac90d56f6db7ac8d2693467046a3..c4b361d6ecd38ae9a8f7120defe149a7c3ef98a8 100644 --- a/background.js +++ b/background.js @@ -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); diff --git a/popup/config.html b/popup/config.html index c65651fa758e6e26977a9ba9f10edf232677d9db..7d63a5b7e4ac8c4cb60842824792db3e3b142213 100644 --- a/popup/config.html +++ b/popup/config.html @@ -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> diff --git a/popup/config.js b/popup/config.js index 806ca57547a1af4beca448a6e63f8a23a12963a0..43a20a43cb261e07ecc74ad3b7f4a8799250d2f0 100644 --- a/popup/config.js +++ b/popup/config.js @@ -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;