Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated to work with latest Chrome, including background page and sec…
…urity differences. Still doesn't show up on the toolbar, though.
- Loading branch information
Showing
5 changed files
with
80 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
}); | ||
|