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

minor modification and comments

parent 26310f92
No related branches found
No related tags found
No related merge requests found
......@@ -10,8 +10,6 @@
"use strict";
//var targetPage = "https://httpbin.org/*";
//var modifyTable = [];
var config ;
var started = "off";
......@@ -23,7 +21,7 @@ if (localStorage.getItem('config'))
}
else
{
// else check if old config exist
// else check if old config exist (Simple Modify headers V1.1)
if (localStorage.getItem('targetPage')&& localStorage.getItem('modifyTable'))
{
console.log("Load old config");
......
......@@ -5,17 +5,19 @@
<meta charset="utf-8">
<title> Simple Modify Headers</title>
<style type="text/css">
.button {
background-color: #008CBA; /* Blue */
border: none;
color: white;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 14px;
background-color: #008CBA; /* Blue */
border: none;
color: white;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 14px;
border-radius: 4px;
height : 20px;
}
.button:hover {
background-color: #0070A0;
}
......@@ -31,12 +33,17 @@
}
.colonne{
background-color: #008CBA; /* Blue */
color: white;
background-color: #008CBA; /* Blue */
color: white;
font-size: 14px;
}
.text {
font-size: 14px;
}
.title{
color: #008CBA;
color: #008CBA;
}
</style>
</head>
......@@ -53,7 +60,7 @@ color: #008CBA;
</h2>
</td></tr>
<tr><td>
<tr><td class="text">
......@@ -66,8 +73,8 @@ color: #008CBA;
</td></tr>
<tr><td>
<br>
<br>
<br>
<br>
<table id="config_tab" id="config">
<tr class="colonne">
<td> Action </td>
......@@ -79,7 +86,7 @@ color: #008CBA;
</table>
</td></tr>
<tr><td>
<tr><td class="text">
<center>
<br>
<input type="button" class="button" style="width:100px" id="add_button" value="Add new line" ></input>
......
......@@ -13,6 +13,7 @@ var line_number = 1;
var started = "off";
window.onload = function() {
// load configuration from local storage
var config = JSON.parse(localStorage.getItem("config"));
for (var to_add of config.headers) appendLine(to_add.action,to_add.header_name,to_add.header_value,to_add.comment,to_add.status);
document.getElementById('save_button').addEventListener('click',function (e) {save_data();});
......@@ -26,7 +27,9 @@ window.onload = function() {
if (started=="on") document.getElementById("start_img").src = "img/stop.png";
} ;
/**
* Add a new configuration line on the UI
**/
function appendLine(action,header_name,header_value,comment,status) {
var html = "<td><select class=\"select_field\" id=\"select_action" + line_number + "\" disable=false><option value=\"add\">add</option><option value=\"modify\">modify</option><option value=\"delete\">delete</option></select></td>";
......@@ -50,6 +53,11 @@ document.getElementById('delete_button'+line_number).addEventListener('click',fu
line_number++;
}
/**
* Create a JSON String representing the configuration data
*
**/
function create_configuration_data()
{
var tr_elements = document.querySelectorAll("#config_tab tr");
......@@ -63,21 +71,23 @@ function create_configuration_data()
var comment = tr_elements[i].childNodes[3].childNodes[0].value;
var status = tr_elements[i].childNodes[4].childNodes[0].value;
headers.push({action:action,header_name:header_name,header_value:header_value,comment:comment,status:status});
}
var to_export = {format_version:"1.0",target_page:document.getElementById('targetPage').value,headers:headers};
console.log(JSON.stringify(to_export));
return JSON.stringify(to_export);
}
// check if url pattern is valid , if not , set the font color to red
/**
* check if url pattern is valid , if not , set the font color to red
**/
function checkTargetPageField()
{
if (isTargetValid(document.getElementById('targetPage').value)) document.getElementById('targetPage').style.color="black";
else document.getElementById('targetPage').style.color="red";
}
// check if url pattern is valid
/**
* check if url pattern is valid
**/
function isTargetValid(target)
{
if (target=="") return true;
......@@ -85,22 +95,32 @@ function isTargetValid(target)
if (target=="*") return true;
return target.match("(http|https|[\*]):\/\/([\*][\.][^\*]*|[^\*]*|[\*])\/");
}
/**
* If url pattern is valid save the data to the local storage and restart modify header
**/
function save_data()
{
if (!isTargetValid(document.getElementById('targetPage').value))
{
alert("Url pattern is invalid");
alert("Can not save : Url pattern is invalid");
return;
}
localStorage.setItem("config",create_configuration_data());
browser.runtime.sendMessage("reload");
}
/**
* If url pattern is valid save the data in a file
**/
function export_data()
{
if (!isTargetValid(document.getElementById('targetPage').value))
{
alert("Can not export : Url pattern is invalid");
return;
}
// Save in local storage
save_data();
// Create file data
var to_export= create_configuration_data();
......@@ -118,6 +138,11 @@ function export_data()
a.click();
}
/**
* Choose a file and import data from the choosen file
*
**/
function import_data(evt)
{
// create an input field in the iframe
......@@ -134,6 +159,13 @@ function import_data(evt)
}
/**
* Import data from a file
*
* If format is not recognized , try modify header add-an file format
*
**/
function readSingleFile(e)
{
var file = e.target.files[0];
......@@ -195,7 +227,9 @@ function readSingleFile(e)
}
/**
* Delete a configuration line on the UI
**/
function delete_line(line_number_to_delete)
{
if (line_number_to_delete != line_number)
......@@ -215,7 +249,9 @@ function delete_line(line_number_to_delete)
line_number--;
}
/**
* Stop or Start modify header
**/
function start_modify()
{
if (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