| OLD | NEW |
| 1 <html> | 1 <html> |
| 2 <head> | 2 <head> |
| 3 <script> | 3 <script> |
| 4 // The Page Action ID. | |
| 5 var pageActionId = "RssPageAction"; | |
| 6 | |
| 7 // The icon to use. This corresponds to the icon listed in the manifest. | |
| 8 var subscribeId = 0; | |
| 9 | |
| 10 // A dictionary keyed off of tabId that keeps track of data per tab (for | 4 // A dictionary keyed off of tabId that keeps track of data per tab (for |
| 11 // example what feedUrl was detected in the tab). | 5 // example what feedUrl was detected in the tab). |
| 12 var feedData = {}; | 6 var feedData = {}; |
| 13 | 7 |
| 14 chrome.extension.onConnect.addListener(function(port) { | 8 chrome.extension.onConnect.addListener(function(port) { |
| 9 var tab = port.sender.tab; |
| 10 |
| 15 // This will get called from the content script using PostMessage. | 11 // This will get called from the content script using PostMessage. |
| 16 // |feedUrls| is a list of URL feeds found on the page. We only need 1 to | 12 // |feedUrls| is a list of URL feeds found on the page. We only need 1 to |
| 17 // enable the PageAction icon in the Omnibox. | 13 // enable the PageAction icon in the Omnibox. |
| 18 port.onMessage.addListener(function(feedUrls) { | 14 port.onMessage.addListener(function(feedUrls) { |
| 19 feedUrl = feedUrls[0]; | 15 feedUrl = feedUrls[0]; |
| 20 // Let Chrome know that the PageAction needs to be enabled for this tabId | 16 // Let Chrome know that the PageAction needs to be enabled for this tabId |
| 21 // and for the url of this page. | 17 // and for the url of this page. |
| 22 if (feedUrl) { | 18 if (feedUrl) { |
| 23 feedData[port.tab.id] = {pageUrl: port.tab.url, | 19 feedData[tab.id] = { pageUrl: tab.url, |
| 24 feedUrl: feedUrl}; | 20 feedUrl: feedUrl }; |
| 25 | 21 |
| 26 chrome.pageActions.enableForTab( | 22 chrome.pageAction.setTitle({ tabId: tab.id, |
| 27 pageActionId, {tabId: port.tab.id, | 23 title: "Click to subscribe..." }); |
| 28 url: port.tab.url, | 24 chrome.pageAction.show(tab.id); |
| 29 title: "Click to subscribe...", | |
| 30 iconId: subscribeId}); | |
| 31 } | 25 } |
| 32 }); | 26 }); |
| 33 }); | 27 }); |
| 34 | 28 |
| 35 // Chrome will call into us when the user clicks on the icon in the OmniBox. | 29 // Chrome will call into us when the user clicks on the icon in the OmniBox. |
| 36 chrome.pageActions["RssPageAction"].addListener(function(pageActionId, | 30 chrome.pageAction.onClicked.addListener(function(tab) { |
| 37 pageActionInfo) { | 31 chrome.windows.get(tab.windowId, function(window) { |
| 38 chrome.windows.getCurrent(function(window) { | 32 // We need to know if we are the active window, because the tab may |
| 39 chrome.tabs.get(pageActionInfo.tabId, function(tab) { | 33 // have moved to another window and we don't want to execute this |
| 40 // We need to know if we are the active window, because the tab may | 34 // action multiple times. |
| 41 // have moved to another window and we don't want to execute this | 35 if (window.focused) { |
| 42 // action multiple times. | 36 // Create a new tab showing the subscription page with the right |
| 43 if (window.focused) { | 37 // feed URL. |
| 44 // Create a new tab showing the subscription page with the right | 38 var url = "subscribe.html?" + |
| 45 // feed URL. | 39 encodeURIComponent(feedData[tab.id].feedUrl); |
| 46 var url = "subscribe.html?" + | 40 chrome.tabs.create({url: url, windowId: window.id}); |
| 47 encodeURIComponent(feedData[pageActionInfo.tabId].feedUrl); | 41 } |
| 48 chrome.tabs.create({url: url, windowId: window.windowId}); | |
| 49 } | |
| 50 }); | |
| 51 }); | 42 }); |
| 52 }); | 43 }); |
| 53 | 44 |
| 54 chrome.tabs.onRemoved.addListener(function(reply) { | 45 chrome.tabs.onRemoved.addListener(function(reply) { |
| 55 feedData[reply.tabId] = null; | 46 feedData[reply.tabId] = null; |
| 56 }); | 47 }); |
| 57 </script> | 48 </script> |
| 58 </head> | 49 </head> |
| 59 </html> | 50 </html> |
| OLD | NEW |