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

merge

parents b7b44150 58ef8ce5
No related branches found
No related tags found
No related merge requests found
......@@ -20,7 +20,7 @@
"browser_action": {
"default_icon": "icons/modify-32.png",
"default_title": "Simple Modify Headers",
"default_popup": "popup/config.html"
"default_popup": "popup/menu.html"
}
}
......@@ -37,10 +37,14 @@
<input type="button" id="add_button" value="ADD NEW LINE" ></input>
<input type="button" id="save_button" value="SAVE"></input>
<input type="button" id="export_button" value="EXPORT"></input>
<input type="file" id="import_button" value="IMPORT"></input>
<input type="button" id="import_button" value="IMPORT"></input>
<iframe id="download" width="0" height="0" frameBorder="0">
</iframe>
</center>
<br>
<a href="export_import.html" target="_blank"> Export/Import</a>
<script type="text/javascript" src="config.js"> </script>
</body>
......
......@@ -48,8 +48,6 @@ line_number++;
}
function save_data ()
{
var tr_elements = document.querySelectorAll("#config_tab tr");
......@@ -83,32 +81,74 @@ function export_data()
headers.push({action:action,header_name:header_name,header_value:header_value,status:status});
}
var to_export = {format_version:"1.0",targetPage:document.getElementById('targetPage').value,headers:headers};
var to_export = {format_version:"1.0",target_page:document.getElementById('targetPage').value,headers:headers};
console.log(JSON.stringify(to_export));
// Create file to save
var a = document.createElement('a');
a.href = 'data:attachment/json,' + encodeURIComponent(JSON.stringify(to_export));
a.target = '_blank';
a.target = 'download';
a.download = 'SimpleModifyHeader.conf';
document.body.appendChild(a);
// use iframe "download" to put the link (in order not to be redirect in the parent frame)
var myf = document.getElementById("download");
myf = myf.contentWindow.document || myf.contentDocument;
myf.body.appendChild(a);
a.click();
}
function import_data(evt)
{
var files = evt.target.files;
var reader = new FileReader();
reader.addEventListener('load', function() {
console.log("files[0].name=" + files[0].name);
alert('Contenu du fichier : "' + files[0].name + '" :\n\n' + reader.result);
});
reader.readAsText(files[0]);
// create an input field in the iframe
var input = document.createElement("input");
input.type="file";
input.addEventListener('change', readSingleFile, false);
var myf = document.getElementById("download");
myf = myf.contentWindow.document || myf.contentDocument;
myf.body.appendChild(input);
input.click();
}
function readSingleFile(e)
{
var file = e.target.files[0];
if (!file) {
return;
}
var reader = new FileReader();
reader.onload = function(e)
{
var contents = e.target.result;
var config="";
try
{
config = JSON.parse(contents);
if (config.format_version && config.target_page)
{
alert("ok");
// store the conf in the local storage
localStorage.setItem("config",contents);
// 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);
}
function delete_line(line_number_to_delete)
{
if (line_number_to_delete != line_number)
......
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<input type="button" id="start_stop" value="Start" ></input>
<input type="button" id="config" value="Configure"></input>
</center>
<script type="text/javascript" src="menu.js"> </script>
</body>
</html>
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* @author didierfred@gmail.com
* @version 0.1
*/
var started = "off";
window.onload = function() {
document.getElementById('config').addEventListener('click',function (e) {start_config();});
document.getElementById('start_stop').addEventListener('click',function (e) {start_modify();});
started = localStorage.getItem("started");
if (started=="on") document.getElementById("start_stop").value = "Stop";
} ;
function start_modify()
{
if (started=="off")
{
localStorage.setItem("started","on");
browser.runtime.sendMessage("on");
started = "on";
document.getElementById("start_stop").value = "Stop";
}
else
{
localStorage.setItem("started","off");
browser.runtime.sendMessage("off");
started = "off";
document.getElementById("start_stop").value = "Start";
}
}
function start_config()
{
var strWindowFeatures = "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no,width=800,height=600";
window.open("config.html","Simple Modify Headers",strWindowFeatures);
}
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