OLD | NEW |
1 <html> | 1 <html> |
2 <head> | 2 <head> |
3 <script> | 3 <script> |
4 // Called when the user clicks on the browser action. | 4 // Called when the user clicks on the browser action. |
5 var clicks = 0; | 5 var clicks = 0; |
6 chrome.browserAction.onClicked.addListener(function() { | 6 chrome.browserAction.onClicked.addListener(function() { |
7 chrome.browserAction.setIcon(clicks); | 7 chrome.browserAction.setIcon({iconIndex:clicks}); |
8 clicks++; | 8 clicks++; |
9 // We only have 2 icons, but cycle through 3 icons to test the | 9 // We only have 1 icon, but cycle through 3 icons to test the |
10 // out-of-bounds index bug. | 10 // out-of-bounds index bug. |
11 if (clicks > 3) | 11 if (clicks > 2) |
12 clicks = 0; | 12 clicks = 0; |
13 }); | 13 }); |
14 var i = 0; | 14 var i = 0; |
15 | 15 |
16 window.setInterval(function() { | 16 window.setInterval(function() { |
17 // Don't animate while in "click" mode. | 17 // Don't animate while in "click" mode. |
18 if (clicks > 0) return; | 18 if (clicks > 0) return; |
19 i++; | 19 i++; |
20 chrome.browserAction.setIcon(draw(i*2, i*4)); | 20 chrome.browserAction.setIcon({imageData:draw(i*2, i*4)}); |
21 }, 50); | 21 }, 50); |
22 | 22 |
23 function draw(starty, startx) { | 23 function draw(starty, startx) { |
24 var canvas = document.getElementById('canvas'); | 24 var canvas = document.getElementById('canvas'); |
25 var context = canvas.getContext('2d'); | 25 var context = canvas.getContext('2d'); |
26 context.clearRect(0, 0, canvas.width, canvas.height); | 26 context.clearRect(0, 0, canvas.width, canvas.height); |
27 context.fillStyle = "rgba(0,200,0,255)"; | 27 context.fillStyle = "rgba(0,200,0,255)"; |
28 context.fillRect(startx % 20, starty % 20, 8, 8); | 28 context.fillRect(startx % 20, starty % 20, 8, 8); |
29 context.fillStyle = "rgba(0,0,200,255)"; | 29 context.fillStyle = "rgba(0,0,200,255)"; |
30 context.fillRect((startx + 5) % 20, (starty + 5) % 20, 8, 8); | 30 context.fillRect((startx + 5) % 20, (starty + 5) % 20, 8, 8); |
31 context.fillStyle = "rgba(200,0,0,255)"; | 31 context.fillStyle = "rgba(200,0,0,255)"; |
32 context.fillRect((startx + 10) % 20, (starty + 10) % 20, 8, 8); | 32 context.fillRect((startx + 10) % 20, (starty + 10) % 20, 8, 8); |
33 return context.getImageData(0, 0, 20, 20); | 33 return context.getImageData(0, 0, 20, 20); |
34 } | 34 } |
35 </script> | 35 </script> |
36 </head> | 36 </head> |
37 <body> | 37 <body> |
38 <canvas id="canvas" width="20" height="20"></canvas> | 38 <canvas id="canvas" width="20" height="20"></canvas> |
39 </body> | 39 </body> |
40 </html> | 40 </html> |
41 | 41 |
OLD | NEW |