-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
30 lines (29 loc) · 944 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
var size = 1;
var canvas = document.createElement('canvas');
if (typeof canvas.getContext === 'function') {
var ctx = canvas.getContext('2d');
canvas.width = size;
canvas.height = size;
}
module.exports = function(el, red, green, blue) {
if (!ctx) { return false; }
if (typeof red === 'string') {
ctx.fillStyle = red;
} else {
if (Array.isArray(red)) {
blue = red[2];
green = red[1];
red = red[0];
}
ctx.fillStyle = 'rgb(' + red + ',' + green + ',' + blue + ')';
}
ctx.fillRect(0, 0, size, size);
// FF apparently doesn't listen to changes made to a
// favicon's href attribute if the value is a data URI.
// Remove and replace element to work around this.
var parent = el.parentNode;
if (parent) { parent.removeChild(el); }
el.href = canvas.toDataURL();
if (parent) { parent.appendChild(el); }
return true;
};