1 <script> 2 // Global accessor that the popup uses. 3 var addresses = {}; 4 var selectedAddress = null; 5 var selectedId = null; 6 7 function updateAddress(tabId) { 8 chrome.tabs.sendRequest(tabId, {}, function(address) { 9 addresses[tabId] = address; 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> 43