| OLD | NEW |
| 1 <script> | 1 <!doctype html> |
| 2 // Global accessor that the popup uses. | 2 <html> |
| 3 var addresses = {}; | 3 <head> |
| 4 var selectedAddress = null; | 4 <title>Background Page</title> |
| 5 var selectedId = null; | 5 <script src="background.js"></script> |
| 6 | 6 </head> |
| 7 function updateAddress(tabId) { | 7 <body> |
| 8 chrome.tabs.sendRequest(tabId, {}, function(address) { | 8 </body> |
| 9 addresses[tabId] = address; | 9 </html> |
| 10 if (!address) { | |
| 11 chrome.pageAction.hide(tabId); | |
| 12 } else { | |
| 13 chrome.pageAction.show(tabId); | |
| 14 if (selectedId == tabId) { | |
| 15 updateSelected(tabId); | |
| 16 } | |
| 17 } | |
| 18 }); | |
| 19 } | |
| 20 | |
| 21 function updateSelected(tabId) { | |
| 22 selectedAddress = addresses[tabId]; | |
| 23 if (selectedAddress) | |
| 24 chrome.pageAction.setTitle({tabId:tabId, title:selectedAddress}); | |
| 25 } | |
| 26 | |
| 27 chrome.tabs.onUpdated.addListener(function(tabId, change, tab) { | |
| 28 if (change.status == "complete") { | |
| 29 updateAddress(tabId); | |
| 30 } | |
| 31 }); | |
| 32 | |
| 33 chrome.tabs.onSelectionChanged.addListener(function(tabId, info) { | |
| 34 selectedId = tabId; | |
| 35 updateSelected(tabId); | |
| 36 }); | |
| 37 | |
| 38 // Ensure the current selected tab is set up. | |
| 39 chrome.tabs.getSelected(null, function(tab) { | |
| 40 updateAddress(tab.id); | |
| 41 }); | |
| 42 </script> | |
| OLD | NEW |