Cleaned up code & Added real error parsing/displaying

This commit is contained in:
Avi Ginsberg 2015-02-04 18:53:30 -05:00
parent 3e4b4b7e7d
commit ac1e75cb25
2 changed files with 14 additions and 27 deletions

View File

@ -1,6 +1,6 @@
{
"name": "Fox.ci",
"version": "0.0.1",
"version": "0.0.2",
"manifest_version": 2,
"description": "Fox.ci URL Shortener",
"homepage_url": "http://fox.ci",
@ -13,7 +13,7 @@
"browser_action": {
"default_icon": "icons/icon19.png",
"default_title": "browser action demo",
"default_title": "Fox.ci URL Shortener",
"default_popup": "src/browser_action/browser_action.html"
},
"permissions": [

View File

@ -3,7 +3,7 @@ var currentURL;
window.onload = function () {
// alert('The browser action was clicked! Yay!');
chrome.tabs.query({active: true, currentWindow: true}, function(arrayOfTabs) {
@ -11,14 +11,10 @@ chrome.tabs.query({active: true, currentWindow: true}, function(arrayOfTabs) {
// since only one tab should be active and in the current window at once
// the return variable should only have one entry
var activeTab = arrayOfTabs[0];
var activeTabId = arrayOfTabs[0].id; // or do whatever you need
var activeTabId = arrayOfTabs[0].id;
var activeTabURL = arrayOfTabs[0].url;
//document.write(activeTabURL);
currentURL = activeTabURL;
//$("#content").append("activeTabURL: "+activeTabURL+"<br>");
//$("#content").append("currentURL: "+currentURL+"<br>");
$.get( "http://fox.ci/api/?url="+currentURL )
@ -28,36 +24,27 @@ currentURL = activeTabURL;
var obj = jQuery.parseJSON(data);
if((obj.statuscode==="100")||(obj.statuscode==="101")){
//document.write("Success! Our short URL is: "+obj.shorturl);
//$("#content").append("Short URL: <input type=\"text\" id=\"copyBox\" value=\""+obj.shorturl+"\"><br>");
var copyFrom = $('<textarea/>');
copyFrom.text(obj.shorturl);
$('body').append(copyFrom);
copyFrom.select();
document.execCommand('copy');
//copyFrom.remove();
$("#content").append("Fox.ci ShortURL copied to clipboard!<br>");
var copyFrom = $('<textarea/>');
copyFrom.text(obj.shorturl);
$('body').append(copyFrom);
copyFrom.select();
document.execCommand('copy');
$("#content").append("Fox.ci ShortURL copied to clipboard!<br>");
}else{
document.write("nuuu something went wrong and it failed");
document.write("Error: "+obj.statusdescription);
}
//document.write("<br>"+obj.statuscode);
//document.write(obj.statusdescription);
});
});
//$("#content").append("Current URL: "+currentURL+"<br>");
//$("mainPopup").append('Test');
}