Skip to content

Commit

Permalink
Updated to work with latest Chrome, including background page and sec…
Browse files Browse the repository at this point in the history
…urity differences. Still doesn't show up on the toolbar, though.
  • Loading branch information
bagofarms committed Apr 28, 2013
1 parent d0796ab commit a29ac51
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 79 deletions.
47 changes: 0 additions & 47 deletions bg.html

This file was deleted.

39 changes: 39 additions & 0 deletions bg.js
@@ -0,0 +1,39 @@
// Global accessor that the popup uses.
var items = {};
var selectedItem = null;
var selectedId = null;

function updateItem(tabId) {
chrome.tabs.sendRequest(tabId, {}, function(item) {
items[tabId] = item;
if (!item) {
chrome.pageAction.hide(tabId);
} else {
chrome.pageAction.show(tabId);
if (selectedId == tabId) {
updateSelected(tabId);
}
}
});
}

function updateSelected(tabId) {
selectedItem = items[tabId];
if (selectedItem)
chrome.pageAction.setTitle({tabId:tabId, title:selectedItem});
}
chrome.tabs.onUpdated.addListener(function(tabId, change, tab) {
if (change.status == "complete") {
updateItem(tabId);
}
});

chrome.tabs.onSelectionChanged.addListener(function(tabId, info) {
selectedId = tabId;
updateItem(tabId);
});

// Ensure the current selected tab is set up.
chrome.tabs.getSelected(null, function(tab) {
updateItem(tab.id);
});
6 changes: 5 additions & 1 deletion manifest.json
@@ -1,8 +1,12 @@
{
"name": "Amazon Affiliate Link Generator",
"version": "0.5",
"manifest_version": 2,
"description": "Generate an Amazon affiliate link with one click",
"background_page": "bg.html",
"background": {
"scripts": ["jq.min.js","bg.js"],
"persistent": false
},
"icons": {
"16": "images/icon_16.png",
"48": "images/icon_48.png",
Expand Down
34 changes: 3 additions & 31 deletions options.html
Expand Up @@ -2,35 +2,7 @@
<head>
<title>Options for Amazon Affiliate Link Generator</title>
<script src="jq.min.js"></script>
<script type="text/javascript">
function restoreOptions() {
var trackId = localStorage['trackId'];
if (!trackId)
return;
$('#tracking-id-text').val(trackId);
}

function hideStatus() {
setTimeout(function() {
$('#status').slideUp('slow');
}, 2000);
}

function saveOptions() {
var trackId = $('#tracking-id-text').val();
console.log(trackId);
if (trackId && trackId.length > 0) {
localStorage['trackId'] = trackId;
var successBlock = "<span class='success'>Options Saved</span>";
$('#status').html(successBlock);
$('#status').slideDown('slow', hideStatus());
} else {
var errorBlock = "<span class='error'>UHO, something went wrong</span>";
$('#status').html(errorBlock);
$('#status').slideDown('slow', hideStatus());
}
}
</script>
<script src="options.js"></script>
<style>
body {
font-family: 'Lucida Grande', sans-serif;
Expand Down Expand Up @@ -111,7 +83,7 @@
}
</style>
</head>
<body onload="restoreOptions()">
<body>
<div id="content">
<header>
<h1>Options for Amazon Affiliate Link Generator</h1>
Expand All @@ -122,7 +94,7 @@ <h1>Options for Amazon Affiliate Link Generator</h1>
<label for="tracking-id-text">Your tracking id:</label>
<input id="tracking-id-text" type="text" placeholder="homer-12" />
<br/>
<button onClick="saveOptions()">Save</button>
<button id="saveButton">Save</button>
</div>
</div>

Expand Down
33 changes: 33 additions & 0 deletions options.js
@@ -0,0 +1,33 @@
function restoreOptions() {
var trackId = localStorage['trackId'];
if (!trackId)
return;
$('#tracking-id-text').val(trackId);
}

function hideStatus() {
setTimeout(function() {
$('#status').slideUp('slow');
}, 2000);
}

function saveOptions() {
var trackId = $('#tracking-id-text').val();
console.log(trackId);
if (trackId && trackId.length > 0) {
localStorage['trackId'] = trackId;
var successBlock = "<span class='success'>Options Saved</span>";
$('#status').html(successBlock);
$('#status').slideDown('slow', hideStatus());
} else {
var errorBlock = "<span class='error'>UHO, something went wrong</span>";
$('#status').html(errorBlock);
$('#status').slideDown('slow', hideStatus());
}
}

$(document).ready(function(){
$('#saveButton').click(saveOptions);
restoreOptions();
});

0 comments on commit a29ac51

Please sign in to comment.