-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
39 lines (32 loc) · 999 Bytes
/
content.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
31
32
33
34
35
36
37
38
39
function getColours() {
var colours = {};
var properties = ['background-color', 'color'];
var nodes = document.querySelectorAll('*');
$(nodes).each(function (key, node) {
$(properties).each(function (i, property) {
var colour = window.getComputedStyle(node)[property];
if (colour != 'rgb(255, 255, 255)' && colour != 'rgb(0, 0, 0)' && colour.indexOf('rgba') === -1) {
colours[colour] = colour;
}
});
});
var distinctColours = [];
Object.getOwnPropertyNames(colours).forEach(function (val) {
var colour = Color(val);
distinctColours.push({
rgb: colour.rgbString(),
hex: colour.hexString(),
hsl: colour.hslString()
})
});
if (distinctColours.length > 0) {
chrome.runtime.sendMessage({type: 'colours', data: distinctColours});
}
}
chrome.extension.onMessage.addListener(function (message, sender, sendResponse) {
switch (message.type) {
case "request-colours":
getColours();
break;
}
});