OLD | NEW |
(Empty) | |
| 1 <html> |
| 2 <head> |
| 3 <script> |
| 4 var lastTabId = 0; |
| 5 chrome.tabs.onUpdated.addListener(function(tabId, p) { |
| 6 lastTabId = tabId; |
| 7 }); |
| 8 |
| 9 // Called when the user clicks on the browser action. |
| 10 var clicks = 0; |
| 11 chrome.pageAction.onClicked.addListener(function(_, info) { |
| 12 chrome.pageAction.setIcon({iconIndex: clicks, tabId: info.tabId}); |
| 13 if (clicks % 2) { |
| 14 chrome.pageAction.show(info.tabId); |
| 15 } else { |
| 16 chrome.pageAction.hide(info.tabId); |
| 17 setTimeout(function() { chrome.pageAction.show(info.tabId); }, 1000); |
| 18 } |
| 19 chrome.pageAction.setTitle({title: "click:" + clicks, tabId: info.tabId}); |
| 20 chrome.pageAction.setBadgeTextColor({ |
| 21 tabId: info.tabId, |
| 22 color: [0, 255, clicks * 50, 255] |
| 23 }); |
| 24 chrome.pageAction.setBadgeBackgroundColor({ |
| 25 tabId: info.tabId, |
| 26 color: [255, clicks * 50, 0, 255] |
| 27 }); |
| 28 chrome.pageAction.setBadgeText({ |
| 29 tabId: info.tabId, |
| 30 text: clicks + "" |
| 31 }); |
| 32 |
| 33 // We only have 2 icons, but cycle through 3 icons to test the |
| 34 // out-of-bounds index bug. |
| 35 clicks++; |
| 36 if (clicks > 3) |
| 37 clicks = 0; |
| 38 }); |
| 39 var i = 0; |
| 40 |
| 41 window.setInterval(function() { |
| 42 // Don't animate while in "click" mode. |
| 43 if (clicks > 0) return; |
| 44 i++; |
| 45 chrome.pageAction.setIcon({imageData: draw(i*2, i*4), tabId: lastTabId}); |
| 46 }, 50); |
| 47 |
| 48 function draw(starty, startx) { |
| 49 var canvas = document.getElementById('canvas'); |
| 50 var context = canvas.getContext('2d'); |
| 51 context.clearRect(0, 0, canvas.width, canvas.height); |
| 52 context.fillStyle = "rgba(0,200,0,255)"; |
| 53 context.fillRect(startx % 19, starty % 19, 8, 8); |
| 54 context.fillStyle = "rgba(0,0,200,255)"; |
| 55 context.fillRect((startx + 5) % 19, (starty + 5) % 19, 8, 8); |
| 56 context.fillStyle = "rgba(200,0,0,255)"; |
| 57 context.fillRect((startx + 10) % 19, (starty + 10) % 19, 8, 8); |
| 58 return context.getImageData(0, 0, 19, 19); |
| 59 } |
| 60 </script> |
| 61 </head> |
| 62 <body> |
| 63 <canvas id="canvas" width="19" height="19"></canvas> |
| 64 </body> |
| 65 </html> |
OLD | NEW |