Skip to content
Snippets Groups Projects
Commit 90201fe7 authored by didierfred's avatar didierfred
Browse files

modify save behavior

parent 9b42428b
No related branches found
No related tags found
No related merge requests found
...@@ -36,7 +36,7 @@ window.onload = function() { ...@@ -36,7 +36,7 @@ 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) {saveDataWithWarning();}); document.getElementById('save_button').addEventListener('click',function (e) {saveData();});
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();});
...@@ -66,7 +66,6 @@ function showParametersScreen() { ...@@ -66,7 +66,6 @@ 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() {
...@@ -234,16 +233,13 @@ function isTargetValid(target) { ...@@ -234,16 +233,13 @@ function isTargetValid(target) {
} }
/** /**
* If url patterns are valid save the data to the local storage and restart modify header * save the data to the local storage and restart modify header
* show a warning if url patterns are invalid
**/ **/
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("Warning: Url patterns are invalid");
localStorage.setItem("config",create_configuration_data()); localStorage.setItem("config",create_configuration_data());
browser.runtime.sendMessage("reload"); browser.runtime.sendMessage("reload");
return true; return true;
...@@ -254,13 +250,6 @@ function saveData() { ...@@ -254,13 +250,6 @@ function saveData() {
**/ **/
function exportData() { function exportData() {
if (!isTargetValid(document.getElementById('targetPage').value)) {
alert("Can not export : Url pattern is invalid");
return;
}
// Save in local storage
saveData();
// Create file data // Create file data
let to_export= create_configuration_data(); let to_export= create_configuration_data();
...@@ -314,8 +303,6 @@ function readSingleFile(e) { ...@@ -314,8 +303,6 @@ function readSingleFile(e) {
config = JSON.parse(contents); config = JSON.parse(contents);
// check file format // check file format
if (config.format_version) { if (config.format_version) {
// if url pattern invalid , set to ""
if (!isTargetValid(config.target_page)) config.target_page="";
// if format file is 1.0 , need to add the apply_on and url_contains value to translate in format 1.2 // if format file is 1.0 , need to add the apply_on and url_contains value to translate in format 1.2
if (config.format_version==="1.0") { if (config.format_version==="1.0") {
...@@ -325,16 +312,16 @@ function readSingleFile(e) { ...@@ -325,16 +312,16 @@ function readSingleFile(e) {
line.url_contains=""; line.url_contains="";
} }
config.debug_mode=false; config.debug_mode=false;
config.show_comments=true; config.show_comments=true;
config.use_url_contains=false; config.use_url_contains=false;
} }
// if format file is 1.1 , need to add url_contains value to translate in format 1.2 // if format file is 1.1 , need to add url_contains value to translate in format 1.2
if (config.format_version==="1.1") { if (config.format_version==="1.1") {
config.format_version="1.2"; config.format_version="1.2";
for (let line of config.headers) line.url_contains=""; for (let line of config.headers) line.url_contains="";
config.show_comments=true; config.show_comments=true;
config.use_url_contains=false; config.use_url_contains=false;
} }
// store the conf in the local storage // store the conf in the local storage
...@@ -438,12 +425,11 @@ function invertLine(line1, line2) { ...@@ -438,12 +425,11 @@ function invertLine(line1, line2) {
**/ **/
function startModify() { function startModify() {
if (started==="off") { if (started==="off") {
if (saveData()) { saveData();
localStorage.setItem("started","on"); localStorage.setItem("started","on");
browser.runtime.sendMessage("on"); browser.runtime.sendMessage("on");
started = "on"; started = "on";
document.getElementById("start_img").src = "img/stop.png"; document.getElementById("start_img").src = "img/stop.png";
}
} }
else { else {
localStorage.setItem("started","off"); localStorage.setItem("started","off");
......
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