| OLD | NEW |
| 1 <html> | 1 <html> |
| 2 <head> | 2 <head> |
| 3 <script> | 3 <script> |
| 4 var lastTabId = 0; | 4 var lastTabId = 0; |
| 5 chrome.tabs.onUpdated.addListener(function(tabId, p) { | 5 chrome.tabs.onUpdated.addListener(function(tabId, p) { |
| 6 lastTabId = tabId; | 6 lastTabId = tabId; |
| 7 }); | 7 }); |
| 8 | 8 |
| 9 // Called when the user clicks on the browser action. | 9 // Called when the user clicks on the browser action. |
| 10 var clicks = 0; | 10 var clicks = 0; |
| 11 chrome.pageAction.onClicked.addListener(function(_, info) { | 11 chrome.pageAction.onClicked.addListener(function(_, info) { |
| 12 chrome.pageAction.setIcon({iconIndex: clicks, tabId: info.tabId}); | 12 chrome.pageAction.setIcon({iconIndex: clicks, tabId: info.tabId}); |
| 13 if (clicks % 2) { | 13 if (clicks % 2) { |
| 14 chrome.pageAction.show(info.tabId); | 14 chrome.pageAction.show(info.tabId); |
| 15 } else { | 15 } else { |
| 16 chrome.pageAction.hide(info.tabId); | 16 chrome.pageAction.hide(info.tabId); |
| 17 setTimeout(function() { chrome.pageAction.show(info.tabId); }, 1000); | 17 setTimeout(function() { chrome.pageAction.show(info.tabId); }, 200); |
| 18 } | 18 } |
| 19 chrome.pageAction.setTitle({title: "click:" + clicks, tabId: info.tabId}); | 19 chrome.pageAction.setTitle({title: "click:" + clicks, tabId: info.tabId}); |
| 20 chrome.pageAction.setBadgeTextColor({ | 20 chrome.pageAction.setBadgeTextColor({ |
| 21 tabId: info.tabId, | 21 tabId: info.tabId, |
| 22 color: [0, 255, clicks * 50, 255] | 22 color: [255, 255, clicks * 50, 255] |
| 23 }); | 23 }); |
| 24 chrome.pageAction.setBadgeBackgroundColor({ | 24 chrome.pageAction.setBadgeBackgroundColor({ |
| 25 tabId: info.tabId, | 25 tabId: info.tabId, |
| 26 color: [255, clicks * 50, 0, 255] | 26 color: [255, clicks * 50, 0, 255] |
| 27 }); | 27 }); |
| 28 chrome.pageAction.setBadgeText({ | 28 chrome.pageAction.setBadgeText({ |
| 29 tabId: info.tabId, | 29 tabId: info.tabId, |
| 30 text: clicks + "" | 30 text: i + "" |
| 31 }); | 31 }); |
| 32 | 32 |
| 33 // We only have 2 icons, but cycle through 3 icons to test the | 33 // We only have 2 icons, but cycle through 3 icons to test the |
| 34 // out-of-bounds index bug. | 34 // out-of-bounds index bug. |
| 35 clicks++; | 35 clicks++; |
| 36 if (clicks > 3) | 36 if (clicks > 3) |
| 37 clicks = 0; | 37 clicks = 0; |
| 38 }); | 38 }); |
| 39 var i = 0; | 39 var i = 0; |
| 40 | 40 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 56 context.fillStyle = "rgba(200,0,0,255)"; | 56 context.fillStyle = "rgba(200,0,0,255)"; |
| 57 context.fillRect((startx + 10) % 19, (starty + 10) % 19, 8, 8); | 57 context.fillRect((startx + 10) % 19, (starty + 10) % 19, 8, 8); |
| 58 return context.getImageData(0, 0, 19, 19); | 58 return context.getImageData(0, 0, 19, 19); |
| 59 } | 59 } |
| 60 </script> | 60 </script> |
| 61 </head> | 61 </head> |
| 62 <body> | 62 <body> |
| 63 <canvas id="canvas" width="19" height="19"></canvas> | 63 <canvas id="canvas" width="19" height="19"></canvas> |
| 64 </body> | 64 </body> |
| 65 </html> | 65 </html> |
| OLD | NEW |