-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
27 lines (25 loc) · 797 Bytes
/
background.js
File metadata and controls
27 lines (25 loc) · 797 Bytes
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
/**
* Heuristicaly designed.
* Returns 255 - sqrt(1000 * languages) if > 0, otherwise 0
*
* @param {number} languages number of languages
* @returns color tone calculated from the number of languages
*/
function languagesToTone(languages) {
return Math.round(Math.max(255 - Math.sqrt(1000 * languages), 0));
}
chrome.runtime.onMessage.addListener(
function(request, sender) {
if (request.langNumber) {
chrome.action.setBadgeText({
tabId: sender.tab.id,
text: request.langNumber
});
const tone = languagesToTone(request.langNumber);
chrome.action.setBadgeBackgroundColor({
tabId: sender.tab.id,
color: `rgb(200, ${tone}, 50)`
});
}
}
);