Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
Version 1.3
  • Loading branch information
inuyasha82 committed Dec 5, 2015
2 parents 49d14f1 + c6693a9 commit 7129ca5
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 116 deletions.
8 changes: 4 additions & 4 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Parameters Editor",
"version": "1.2",
"version": "1.3",

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

Expand All @@ -15,11 +15,11 @@
"scripts": ["src/background.js"],
"persistent": false
},

"page_action": {
"default_title": "Show/Edit parameter for this URL",
"default_icon": "images/icon.png",
"default_popup": "src/popup.html"
}
}

}
148 changes: 77 additions & 71 deletions src/background.js
Original file line number Diff line number Diff line change
@@ -1,71 +1,77 @@
/**
* chrome_parameters Extension
*
* background.js
*
* @version 1.1
*
*/

var tag;

/**
* Get the url paramater identified by sParam
* @param {String} sParam The parameter that we want to read from url.
* @return The parameter value if available, null otherwise
*/
function getURLParameter(sParam) {
var sPageURL = window.location.search.substring(1);
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++) {
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == sParam) {
return sParameterName[1];
}
}
return null;
}

chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
//var url_url = processUrl(tab.url);
console.log("Parameter: " + tab.url);
var i = 0;
console.log(tab.url.length);
var i = tab.url.indexOf('?');
var parameter_url = tab.url.substring(i++);
chrome.pageAction.show(tabId);
});

function getVersion(){
var extension_version = chrome.app.getDetails();
return extension_version.version;
}

function onInstall(){
console.log("Extension Installed");
chrome.tabs.create({'url': chrome.extension.getURL('src/post_install.html')}, function(tab){
});
}

function onUpdate(){
console.log("Extension Updated");
chrome.tabs.create({'url': chrome.extension.getURL('src/post_update.html')}, function(tab){
});
}

chrome.runtime.onInstalled.addListener(function(details){
var current_version = getVersion();
var old_version = localStorage['version']
if (current_version != old_version) {
console.log(old_version);
if (old_version == undefined) {
console.log("OnInstall Call");
localStorage['version'] = current_version;
onInstall();
} else {
localStorage['version'] = current_version;
onUpdate();
}
}
console.log("Reason: " + details.reason);
});
/**
* chrome_parameters Extension
*
* background.js
*
* @version 1.2
*
*/

var tag;

/**
* Get the url paramater identified by sParam
* @param {String} sParam The parameter that we want to read from url.
* @return The parameter value if available, null otherwise
*/
function getURLParameter(sParam) {
var sPageURL = window.location.search.substring(1);
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++) {
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == sParam) {
return sParameterName[1];
}
}
return null;
}

chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
//var url_url = processUrl(tab.url);
console.log("Parameter: " + tab.url);
var i = 0;
console.log(tab.url.length);
var i = tab.url.indexOf('?');
var parameter_url = tab.url.substring(i++);
chrome.pageAction.show(tabId);
});

function getVersion(){
var extension_version = chrome.app.getDetails();
return extension_version.version;
}

function onInstall(){
console.log("Extension Installed");
chrome.tabs.create({'url': chrome.extension.getURL('src/post_install.html')}, function(tab){
});
}

function onUpdate(){
console.log("Extension Updated");
chrome.tabs.create({'url': chrome.extension.getURL('src/post_update.html')}, function(tab){
});
}

chrome.runtime.onInstalled.addListener(function(details){
var current_version = getVersion();
var old_version = localStorage['version']
if (current_version != old_version) {
console.log(old_version);
if (old_version == undefined) {
console.log("OnInstall Call");
localStorage['version'] = current_version;
onInstall();
} else {
localStorage['version'] = current_version;
onUpdate();
}
}
console.log("Reason: " + details.reason);
});

function lastError(){
if(chrome.runtime.lastError){
console.log(chrome.runtime.lastError.message);
}
}
45 changes: 26 additions & 19 deletions src/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
*
* popup.js
*
* @version 1.1
* @version 1.3
*
*/
var exporters = {csv: create_csv};

function click(e) {
console.log(e.target.id);
if(e.target.id=="close") {
if(e.target.id=="close") {
window.close();
return;
} else if(e.target.id=="update"){
Expand All @@ -22,11 +22,9 @@ function click(e) {
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");
chrome.tabs.executeScript(tab.id, {file: "src/content_script.js"}, function(element){
});

});
} else if(e.target.id=="social_button"){
console.log("Show social bar");
Expand All @@ -42,7 +40,7 @@ function update_url(){
console.log(updated_url);
chrome.tabs.update(tab.id, {url: updated_url});
window.close();
});
});
}

function add_new_parameter(){
Expand All @@ -55,12 +53,18 @@ function add_new_parameter(){
parameter_name_container.setAttribute("type", "text");
parameter_value_container.addEventListener("keypress", input_keypress);
parameter_name_container.onblur = function(){
console.log(this);
if(this.value!=""){
var element = this.nextElementSibling;
//var element = this.nextElementSibling;
var element = this.parentElement.parentElement.childNodes[1].childNodes[0];
element.setAttribute("id", this.value);
var new_label = document.createElement("b");
new_label.appendChild(document.createTextNode(this.value));
element.parentElement.replaceChild(new_label, this);
var new_label = document.createElement("input");
//new_label.appendChild(document.createTextNode(this.value));
new_label.className = "parameter_name";
new_label.disabled = true;
new_label.value = this.value;
//element.parentElement.replaceChild(new_label, this);
element.parentElement.childNodes[0].replaceChild(new_label, this);
}
};
parameter_value_container.setAttribute("type", "text");
Expand All @@ -74,7 +78,6 @@ function add_new_row() {
td.appendChild(arguments[i]);
tr_element.appendChild(td);
}

appendElement(tr_element);
}

Expand All @@ -98,14 +101,15 @@ function create_updated_url(url){
if(url_split!=null){
var new_url = url_split[0] + "?";
}
debugger;
for(i=0; i<parameters.length; i++){
if (parameters[i].getAttribute("id") == "hash") {
new_url = new_url+"#";
continue;
} else if(parameters[i].getAttribute("id") == "new_parameter" || parameters[i].getAttribute("id") == undefined ) {
continue;
}

new_url = new_url + parameters[i].id + "=" + parameters[i].value;
if(i<parameters.length-1){
new_url = new_url + "&";
Expand All @@ -119,7 +123,7 @@ function get_current_tab(callback){
active: true, // Select active tabs
lastFocusedWindow: true // In the current window
}, function(array_of_Tabs) {
// Since there can only be one active tab in one active window,
// Since there can only be one active tab in one active window,
// the array has only one element
/*var tab = array_of_Tabs[0];
// Example:
Expand Down Expand Up @@ -184,12 +188,12 @@ function input_keypress(event){
update_url();
}
console.log(event.keyCode);

}

/**
* Append an element to the given element.
*
*
* @param element to append
*/
function appendElement(element){
Expand All @@ -198,7 +202,7 @@ function appendElement(element){
}

/**
* Show a parameter line in extension popup.
* 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
Expand All @@ -211,7 +215,10 @@ function showParameter(parameter, after_hash){
}
var text_input_element = document.createElement("input");
text_input_element.type = "text";
text_input_element.value = parameter_array[1];
if(parameter_array[1] !== undefined) {
text_input_element.value = parameter_array[1];
}

text_input_element.setAttribute("id", parameter_array[0]);
text_input_element.setAttribute("class", "parameter_value");
text_input_element.addEventListener("keypress", input_keypress);
Expand Down Expand Up @@ -245,7 +252,7 @@ function export_parameters_list(format){
var container_div = document.getElementById("container");
var parameters = container_div.getElementsByTagName("input");
var parameters_array = new Array();
for(i=0; i<parameters.length; i++){
for(i=0; i<parameters.length; i++){
console.log(parameters[i].getAttribute("id"));
parameters_array[parameters[i].getAttribute("id")] = parameters[i].value;
}
Expand Down
25 changes: 15 additions & 10 deletions src/post_install.html
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
<html>
<head>
<title>Parameter Editor</title>
<style type="text/css">
body {
padding: 20;
background-color: #eaeaea;
}
<style type="text/css">
body {
padding: 20;
background-color: #eaeaea;
}
</style>
</head>
<body >

<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>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 />

When you've finished editing parameters, just click on <b><i>Update Parameters</i></b> and you'll get to another page with updated parameters. <br />
<br />

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>

<h2>Credits:</h2>
<ul>
<li>Ivan Gualandri (inuyasha82) - Creator and maind developer</li>
<li>Davide Fiorentino - Graphic Content</li>
<li>Jader Dias - Contributor</li>
</ul>
</body>
</html>
</html>
Loading

0 comments on commit 7129ca5

Please sign in to comment.