Skip to content

Commit

Permalink
Merge pull request #28 from inuyasha82/master
Browse files Browse the repository at this point in the history
Milestone 1.1 merge
  • Loading branch information
inuyasha82 committed Dec 12, 2014
2 parents aad1cb0 + a9ca69a commit fb56698
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 41 deletions.
Binary file modified images/add.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/close.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/export.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/parameters.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/update.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{
"manifest_version": 2,
"name": "Parameters Editor",
"version": "1.0",
"version": "1.1",

"description": "Shows parameters used in the URL and allows to update them ",
"description": "Shows parameters used in the URL and allows to update, export and import them ",

"permissions": [
"activeTab",
"tabs",
"webNavigation"
"activeTab",
"tabs", "<all_urls>",
"webNavigation"
],

"background": {
"scripts": ["src/background.js"],
"persistent": false
},

"page_action": {
"default_title": "Show/Edit parameter for this URL",
"default_icon": "images/icon.png",
Expand Down
19 changes: 11 additions & 8 deletions src/background.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
var tag;
/**
* chrome_parameters Extension
*
* background.js
*
* @version 1.1
*
*/

var tag;

/**
* Get the url paramater identified by sParam
Expand All @@ -24,13 +32,8 @@ chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
var i = 0;
console.log(tab.url.length);
var i = tab.url.indexOf('?');
if(i==-1){
console.log("no parameters");
} else {
var parameter_url = tab.url.substring(i++);
console.log(parameter_url);
chrome.pageAction.show(tabId);
}
var parameter_url = tab.url.substring(i++);
chrome.pageAction.show(tabId);
});

function getVersion(){
Expand Down
44 changes: 44 additions & 0 deletions src/content_script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* chrome_parameters Extension
*
* This script contains logic for csv import.
* content_script.js
* @version 1.1
*
*/

var fileChooser = document.createElement("input");
fileChooser.type = 'file';
fileChooser.addEventListener('change', function (evt) {
console.log('inside content script change event');
var f= evt.target.files[0];
if(f){
var reader = new FileReader();
reader.onload = function(e){
var contents = e.target.result;
var parameters = contents.split('\n');
var url_array = document.location.href.split('?', 1)[0] + '?';
for(var i = 0; i <parameters.length-1; i++){
var comma_index = parameters[i].indexOf(",");
if (comma_index == -1) {
alert("Wrong file format");
break;
}
var parameter = parameters[i].substr(0, comma_index) + '=' + parameters[i].substr(comma_index+'='.length);
if (!(parameter.substr(0, comma_index) == "parameter_name")) {
if(i!=1) {
url_array += '&';
}
url_array += parameter;
}
}
console.log(url_array);
url_array = url_array.replace(/"/g, '');
document.location.href= url_array;
}
reader.readAsText(f);
}
});

document.body.appendChild(fileChooser);
fileChooser.click();
45 changes: 29 additions & 16 deletions src/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,32 @@
<head>
<title>Parameters viewer</title>
<style>
body {
min-width: 377px;
overflow-x: hidden;
}
body {
min-width: 377px;
overflow-x: hidden;
}

img2 {
margin: 5px;
border: 2px solid black;
vertical-align: middle;
width: 75px;
height: 75px;
}
img2 {
margin: 5px;
border: 2px solid black;
vertical-align: middle;
width: 75px;
height: 75px;
}

input {
border: 2px solid #C1C4BE;
border-radius: 5px;
padding-left: 5px
}

div#report_bug {
text-align: right;
}

#report_bug a:link { color: #006699; font-weight: bold; text-decoration: none; font-size: smaller}
#report_bug a:visited { color: #006699; font-weight: bold; text-decoration: none; font-size: smaller}

</style>

<!--
Expand All @@ -38,10 +46,15 @@
<div id="container"></div>
<hr />
<div id="other_buttons">
<img id="update" src="../images/update.png"/>
<img id="addnew" src="../images/add.png"/>
<img id="export" src="../images/export.png"/>
<img id="close" src="../images/close.png"/>
<img id="update" src="../images/update.png"/>
<img id="addnew" src="../images/add.png"/>
<img id="export" src="../images/export.png"/>
<img id="import" src="../images/import.png"/>
<img id="close" src="../images/close.png"/>
<input id="myInput" type="file" style="display:none" />
</div>
<div id="report_bug">
<a href="https://github.com/c103/chrome_parameters/issues/new" target="_blank">Report a bug</a>
</div>
</body>
</html>
</html>
70 changes: 61 additions & 9 deletions src/popup.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/**
* chrome_parameters Extension
*
* popup.js
*
* @version 1.1
*
*/
var exporters = {csv: create_csv};

function click(e) {
Expand All @@ -6,21 +14,33 @@ function click(e) {
window.close();
return;
} else if(e.target.id=="update"){
get_current_tab(function(tab){
console.log("Creating new Url");
var updated_url = create_updated_url(tab.url);
console.log(updated_url);
chrome.tabs.update(tab.id, {url: updated_url});
window.close();
});
update_url();
} else if(e.target.id=="addnew") {
console.log("Add new parameter");
add_new_parameter();
} else if(e.target.id=="export"){
export_parameters_list("csv");
} else if(e.target.id=="import"){
get_current_tab(function(tab){
console.log("boh");
chrome.tabs.executeScript(tab.id, {file: "src/content_script.js"}, function(element){
console.log("aaah");
});

});
}
}

function update_url(){
get_current_tab(function(tab){
console.log("Creating new Url");
var updated_url = create_updated_url(tab.url);
console.log(updated_url);
chrome.tabs.update(tab.id, {url: updated_url});
window.close();
});
}

function add_new_parameter(){
var parameter_name_container = document.createElement("input");
var parameter_value_container = document.createElement("input");
Expand Down Expand Up @@ -146,16 +166,35 @@ document.addEventListener('DOMContentLoaded', function () {
});
});

function input_keypress(event){
if (event.keyCode == 13) {
update_url();
}
console.log(event.keyCode);

}

/**
* Append an element to the given element.
*
* @param element to append
*/
function appendElement(element){
var newdiv = document.createElement("div");
newdiv.appendChild(element);
var container_element = document.getElementById("container");
container_element.appendChild(newdiv);
}

/**
* Show a parameter line in extension popup.
*
* @param parameter - The parameter to show. The string format should be: parameter_name=parameter_value
* @param afetr_hash - not used
*/
function showParameter(parameter, after_hash){
var p_element = document.createElement("p");
var parameter_array = parameter.split("=");
var parameter_array = parameter.split(/=(.+)?/);
if(parameter_array.length <2) {
console.log("No parameter");
return;
Expand All @@ -164,6 +203,7 @@ function showParameter(parameter, after_hash){
text_input_element.type = "text";
text_input_element.value = parameter_array[1];
text_input_element.setAttribute("id", parameter_array[0]);
text_input_element.addEventListener("keypress", input_keypress);
var b_element = document.createElement("b");
b_element.appendChild(document.createTextNode(parameter_array[0] + " = "));
p_element.appendChild(b_element);
Expand All @@ -182,6 +222,13 @@ function delete_parameter(){
container.parentNode.removeChild(container);
}

/**
* Export the current parameters_list in the format provided. Currently available formats are: "csv".
* To add support for a format, create an exporter function, and add an entry in exporters variable. in key: value format. Where
* key is the format name, value is the exporter function.
*
* @param format - The selected export format
*/
function export_parameters_list(format){
console.log("Placeholder");
var container_div = document.getElementById("container");
Expand All @@ -199,11 +246,16 @@ function export_parameters_list(format){
link.click();
}

/**
* Create a csv string given a parameters_array.
*
* @param parameters_array Associative array where key is the parameter name.
*/
function create_csv(parameters_array){
//var csv_file = "data:text/csv;charset=utf-8,";
var csv_file = "parameter_name,value\n";
for(var key in parameters_array){
csv_file += key + "," + parameters_array[key]+"\n";
csv_file += key + "," + "\"" + parameters_array[key]+ "\"\n";
}
return csv_file;
}
5 changes: 3 additions & 2 deletions src/post_install.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<h1><img src="../images/icon.png" height="80" width="80">Thank you for installting Parameter Editor.</h1>
<h2>Scope</h2>
The scope of this extension is to show parameters used to get to the page you're showing, and let you update (if needed) values for those parameter.
<h2>Instruction</h2>
<h2>Instructions</h2>
<p>
Just click on EDIT icon you see in the address bar, click and you'll see all parameters used to get to that page.<br/>
You can edit values for those parameters simply typing new value in the text box at the right of parameter key, or if you want you can add new parameters by clicking <b><i>Add new</i></b>.<br/><br />
Expand All @@ -23,9 +23,10 @@ <h2>Instruction</h2>

If you want to export the parameters list as CSV file just press the <b><i>Export</i></b> button
</p>
<b>Starting from version 1.1</b> you can also import parameters list from comma sperated a CSV file.
<b>Starting from version 1.0</b> you can also export parameters list as CSV file.
<h2>Source code</h2>
This extension is Open Source, released under GPLv3. You can download sources from <a href="http://c103.github.io/chrome_parameters/">GitHub</a>
This extension is Open Source, released under GPLv3. You can download sources from <a href="http://c103.github.io/chrome_parameters/">GitHub</a>

</body>
</html>

0 comments on commit fb56698

Please sign in to comment.