-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrainbow.js
36 lines (32 loc) · 918 Bytes
/
rainbow.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
var tagMap = new Object();
//initialize with the user's interested tags and with a default bgcolor
$('#interestingTags > a').each(function() {
var tag = $(this).text();
if(!tagMap[tag]) tagMap[tag] = '#e0eaf1';
});
//send tagMap to the background.js script to save
chrome.extension.sendRequest({
"tagMap": tagMap
}, function(response) {
sprinkle(response.tagMap);
});
//listen for requests from the popup window
chrome.extension.onMessage.addListener(function(request, sender, sendResponse) {
if(request.method == "resprinkle") {
sprinkle(request.tagMap);
// Send JSON data back to Popup.
sendResponse({
data: "roger that"
});
} else {
sendResponse({}); // snub them.
}
});
//sprinkle magic dust
function sprinkle(tagMap) {
$.each(tagMap, function(i, t) {
$('a.post-tag').filter(function() {
return $(this).text() == i;
}).css('background-color', t);
})
}