OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 13 matching lines...) Expand all Loading... |
24 const frameOpacities = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, | 24 const frameOpacities = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, |
25 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, | 25 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, |
26 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1, 0.0]; | 26 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1, 0.0]; |
27 const numberOfFrames = frameOpacities.length; | 27 const numberOfFrames = frameOpacities.length; |
28 | 28 |
29 let stopRequested = false; | 29 let stopRequested = false; |
30 let canUpdateIcon = true; | 30 let canUpdateIcon = true; |
31 let notRunning = Promise.resolve(); | 31 let notRunning = Promise.resolve(); |
32 let whitelistedState = new ext.PageMap(); | 32 let whitelistedState = new ext.PageMap(); |
33 | 33 |
| 34 let icons = [null, null]; |
| 35 |
34 function loadImage(url) | 36 function loadImage(url) |
35 { | 37 { |
36 return new Promise((resolve, reject) => | 38 return new Promise((resolve, reject) => |
37 { | 39 { |
38 let image = new Image(); | 40 let image = new Image(); |
39 image.src = url; | 41 image.src = url; |
40 image.addEventListener("load", () => | 42 image.addEventListener("load", () => |
41 { | 43 { |
42 resolve(image); | 44 resolve(image); |
43 }); | 45 }); |
44 image.addEventListener("error", () => | 46 image.addEventListener("error", () => |
45 { | 47 { |
46 reject("Failed to load image " + url); | 48 reject("Failed to load image " + url); |
47 }); | 49 }); |
48 }); | 50 }); |
49 } | 51 } |
50 | 52 |
| 53 function renderIcons() |
| 54 { |
| 55 Promise.all([ |
| 56 loadImage("icons/abp-16.png"), |
| 57 loadImage("icons/abp-16-whitelisted.png"), |
| 58 loadImage("icons/abp-19.png"), |
| 59 loadImage("icons/abp-19-whitelisted.png"), |
| 60 loadImage("icons/abp-20.png"), |
| 61 loadImage("icons/abp-20-whitelisted.png"), |
| 62 loadImage("icons/abp-32.png"), |
| 63 loadImage("icons/abp-32-whitelisted.png"), |
| 64 loadImage("icons/abp-38.png"), |
| 65 loadImage("icons/abp-38-whitelisted.png"), |
| 66 loadImage("icons/abp-40.png"), |
| 67 loadImage("icons/abp-40-whitelisted.png"), |
| 68 ]) |
| 69 .then(images => |
| 70 { |
| 71 let imageMap = { |
| 72 16: [images[0], images[1]], |
| 73 19: [images[2], images[3]], |
| 74 20: [images[4], images[5]], |
| 75 32: [images[6], images[7]], |
| 76 38: [images[8], images[9]], |
| 77 40: [images[10], images[11]] |
| 78 }; |
| 79 |
| 80 let canvas = document.createElement("canvas"); |
| 81 let context = canvas.getContext("2d"); |
| 82 |
| 83 for (let whitelisted of [false, true]) |
| 84 { |
| 85 let imageData = {}; |
| 86 let sizes = [16, 19, 20, 32, 38, 40]; |
| 87 |
| 88 for (let size of sizes) |
| 89 { |
| 90 canvas.width = size; |
| 91 canvas.height = size; |
| 92 context.globalAlpha = 1; |
| 93 context.drawImage(imageMap[size][whitelisted | 0], 0, 0); |
| 94 imageData[size] = context.getImageData(0, 0, size, size); |
| 95 } |
| 96 |
| 97 icons[whitelisted | 0] = imageData; |
| 98 } |
| 99 }); |
| 100 } |
| 101 |
51 function setIcon(page, notificationType, opacity, frames) | 102 function setIcon(page, notificationType, opacity, frames) |
52 { | 103 { |
53 opacity = opacity || 0; | 104 opacity = opacity || 0; |
54 let whitelisted = !!whitelistedState.get(page); | 105 let whitelisted = !!whitelistedState.get(page); |
55 | 106 |
56 if (!notificationType || !frames) | 107 if (!notificationType || !frames) |
57 { | 108 { |
58 if (opacity > 0.5) | 109 if (opacity > 0.5) |
59 { | 110 { |
60 page.browserAction.setIcon("/icons/abp-$size-notification-" + | 111 page.browserAction.setIcon("/icons/abp-$size-notification-" + |
61 notificationType + ".png"); | 112 notificationType + ".png"); |
62 } | 113 } |
63 else | 114 else |
64 { | 115 { |
65 page.browserAction.setIcon("/icons/abp-$size" + | 116 page.browserAction.setIcon("/icons/abp-$size" + |
66 (whitelisted ? "-whitelisted" : "") + ".png"); | 117 (whitelisted ? "-whitelisted" : "") + ".png", |
| 118 icons[whitelisted | 0]); |
67 } | 119 } |
68 } | 120 } |
69 else | 121 else |
70 { | 122 { |
71 browser.browserAction.setIcon({ | 123 browser.browserAction.setIcon({ |
72 tabId: page.id, | 124 tabId: page.id, |
73 imageData: frames["" + opacity + whitelisted] | 125 imageData: frames["" + opacity + whitelisted] |
74 }); | 126 }); |
75 } | 127 } |
76 } | 128 } |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 clearInterval(interval); | 282 clearInterval(interval); |
231 resolve(); | 283 resolve(); |
232 return; | 284 return; |
233 } | 285 } |
234 | 286 |
235 animateIcon(type, frames); | 287 animateIcon(type, frames); |
236 }, 10000); | 288 }, 10000); |
237 }); | 289 }); |
238 }); | 290 }); |
239 }; | 291 }; |
| 292 |
| 293 renderIcons(); |
OLD | NEW |