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

add modify header format support and check url pattern

parent d91fd19d
No related branches found
No related tags found
No related merge requests found
......@@ -148,8 +148,11 @@ function notify(message)
*/
function addListener()
{
var target = config.target_page;
if ((target=="*")||(target=="")||(target==" "))target="<all_urls>";
browser.webRequest.onBeforeSendHeaders.addListener(rewriteHeader,
{urls: [config.target_page]},
{urls: [target]},
["blocking", "requestHeaders"]);
}
......
......@@ -53,7 +53,7 @@ color: #008CBA;
<td width="450">
Url Pattern : <input size="50" id="targetPage" type="text" value=""></input>
Url Pattern* : <input size="50" id="targetPage" type="text" value=""></input>
</td>
<td width="270" align="right">
......@@ -78,12 +78,14 @@ color: #008CBA;
<br>
<input type="button" class="button" style="width:100px" id="add_button" value="Add new line" ></input>
<input type="button" class="button" style="width:100px" id="save_button" value="Save"></input>
<br>
<br>
</center>
</i> * Informations on url pattern can be found <a href="https://developer.chrome.com/extensions/match_patterns" target="_blank"> here </a> </i>
<iframe id="download" width="0" height="0" frameBorder="0">
</iframe>
</center>
<br>
<script type="text/javascript" src="config.js"> </script>
......
......@@ -69,8 +69,23 @@ function create_configuration_data()
return JSON.stringify(to_export);
}
// check if url pattern is valid
function isTargetValid(target)
{
if (target=="") return true;
if (target==" ") return true;
if (target=="*") return true;
return target.match("(http|https):\/\/.[^\*]*\/");
}
function save_data ()
{
if (!isTargetValid(document.getElementById('targetPage').value))
{
alert("Url pattern is invalid");
return;
}
localStorage.setItem("config",create_configuration_data());
browser.runtime.sendMessage("reload");
}
......@@ -113,18 +128,19 @@ function import_data(evt)
function readSingleFile(e)
{
var file = e.target.files[0];
if (!file) {
var file = e.target.files[0];
if (!file) {
return;
}
var reader = new FileReader();
reader.onload = function(e)
var reader = new FileReader();
reader.onload = function(e)
{
var contents = e.target.result;
var config="";
try
{
config = JSON.parse(contents);
// check file format
if (config.format_version && config.target_page)
{
// store the conf in the local storage
......@@ -134,14 +150,36 @@ function readSingleFile(e)
// reload the configuration page with the new conf
document.location.href="config.html";
}
else alert("invalid file format");
else
{
// try modify header add-on file format : array of {action,name,value,comment,enabled}
if (config[0].action)
{
var headers = [];
for (var line_to_load of config)
{
var enabled = "off";
if (line_to_load.enabled) enabled = "on"
if (line_to_load.action=="Filter") line_to_load.action="delete";
headers.push({action:line_to_load.action.toLowerCase(),header_name:line_to_load.name,header_value:line_to_load.value,comment:line_to_load.comment,status:enabled});
}
var to_load = {format_version:"1.0",target_page:"",headers:headers};
// store the conf in the local storage
localStorage.setItem("config",JSON.stringify(to_load));
// load the new conf
browser.runtime.sendMessage("reload");
// reload the configuration page with the new conf
document.location.href="config.html";
}
else alert("invalid file format");
}
}
catch(error)
{
console.log(error);
alert("Invalid file format");
}
alert(contents);
};
reader.readAsText(file);
}
......
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