Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 }); | 46 }); |
47 image.addEventListener("error", () => | 47 image.addEventListener("error", () => |
48 { | 48 { |
49 reject("Failed to load image " + url); | 49 reject("Failed to load image " + url); |
50 }); | 50 }); |
51 }); | 51 }); |
52 } | 52 } |
53 | 53 |
54 function renderIcons() | 54 function renderIcons() |
55 { | 55 { |
56 Promise.all([ | 56 let paths = [ |
57 loadImage("icons/abp-16.png"), | 57 "icons/abp-16.png", "icons/abp-16-whitelisted.png", |
58 loadImage("icons/abp-16-whitelisted.png"), | 58 "icons/abp-32.png", "icons/abp-32-whitelisted.png" |
59 loadImage("icons/abp-32.png"), | 59 ]; |
60 loadImage("icons/abp-32-whitelisted.png") | 60 |
61 ]) | 61 for (let path of paths) |
62 .then(images => | 62 { |
63 { | 63 loadImage(path).then(image => |
64 let imageMap = { | 64 { |
65 16: [images[0], images[1]], | 65 let [, size, whitelisted] = /\/abp-(16|32)(-whitelisted)?\./.exec(path); |
Manish Jethani
2019/02/03 09:47:55
Note: size is a string, not a number, but that's f
| |
66 32: [images[2], images[3]] | 66 |
67 }; | 67 let canvas = document.createElement("canvas"); |
68 | 68 let context = canvas.getContext("2d"); |
69 let canvas = document.createElement("canvas"); | 69 let imageData = icons[!!whitelisted | 0] || {}; |
Sebastian Noack
2019/02/03 10:07:54
Nit: Isn't coercing to boolean (through !!) redund
Manish Jethani
2019/02/03 10:37:55
`"-whitelisted" | 0` is 0. Because "-whitelisted"
| |
70 let context = canvas.getContext("2d"); | 70 |
71 | 71 canvas.width = size; |
72 for (let whitelisted = 0; whitelisted <= 1; whitelisted++) | 72 canvas.height = size; |
73 { | 73 context.globalAlpha = 1; |
74 let imageData = {}; | 74 context.drawImage(image, 0, 0); |
75 let sizes = [16, 32]; | 75 imageData[size] = context.getImageData(0, 0, size, size); |
76 | 76 |
77 for (let size of sizes) | 77 icons[!!whitelisted | 0] = imageData; |
78 { | 78 }); |
79 canvas.width = size; | 79 } |
80 canvas.height = size; | |
81 context.globalAlpha = 1; | |
82 context.drawImage(imageMap[size][whitelisted], 0, 0); | |
83 imageData[size] = context.getImageData(0, 0, size, size); | |
84 } | |
85 | |
86 icons[whitelisted] = imageData; | |
87 } | |
88 }); | |
89 } | 80 } |
90 | 81 |
91 function setIcon(page, notificationType, opacity, frames) | 82 function setIcon(page, notificationType, opacity, frames) |
92 { | 83 { |
93 opacity = opacity || 0; | 84 opacity = opacity || 0; |
94 let whitelisted = !!whitelistedState.get(page); | 85 let whitelisted = !!whitelistedState.get(page); |
95 | 86 |
96 if (!notificationType || !frames) | 87 if (!notificationType || !frames) |
97 { | 88 { |
98 if (opacity > 0.5) | 89 if (opacity > 0.5) |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
270 | 261 |
271 animateIcon(type, frames); | 262 animateIcon(type, frames); |
272 }, 10000); | 263 }, 10000); |
273 }); | 264 }); |
274 }); | 265 }); |
275 }; | 266 }; |
276 | 267 |
277 // Pre-render icons on Chromium (#7253). | 268 // Pre-render icons on Chromium (#7253). |
278 if (info.platform == "chromium") | 269 if (info.platform == "chromium") |
279 renderIcons(); | 270 renderIcons(); |
LEFT | RIGHT |