forked from ossd-s23/TabColor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolor.js
97 lines (88 loc) · 2.97 KB
/
color.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
function themeWindow(window, textColor, darkColor, lightColor) {
browser.theme.update(window.id, {
images: {
theme_frame: "",
},
colors: {
frame: darkColor,
tab_background_text: textColor,
accentcolor: lightColor,
toolbar: lightColor,
toolbar_text: textColor,
tab_line: darkColor
}
});
}
function themeWindow_default(window) {
browser.theme.reset(window.id)
}
async function handleMessage(request, sender, sendResponse) {
let currentWindow = await browser.windows.getLastFocused();
// set colors
red = "#b02300";
lightRed = "#df6142";
orange = "#d3a116";
lightOrange = "#dfbb58"
yellow = "#f5f423";
lightYellow = "#fafa8e";
green = "#3f6215";
lightGreen = "#5e8231";
blue = "#5660fc";
lightBlue = "#727ae6";
purple = "#8509eb";
lightPurple = "#a266cd";
pink = "#ba4a8e";
lightPink = "#cb76a9";
switch (request.greeting) {
case "Red":
themeWindow(currentWindow, "white", red, lightRed);
break;
case "Orange":
themeWindow(currentWindow, "black", orange, lightOrange);
break;
case "Yellow":
themeWindow(currentWindow, "black", yellow, lightYellow);
break;
case "Green":
themeWindow(currentWindow, "white", green, lightGreen);
break;
case "Blue":
themeWindow(currentWindow, "white", blue, lightBlue);
break;
case "Purple":
themeWindow(currentWindow, "white", purple, lightPurple);
break;
case "Pink":
themeWindow(currentWindow, "white", pink, lightPink);
break;
case "Random!":
// colorPair will be an array of two colors,
// colorPair[0] = darkColor
// colorPair[1] = lightColor
colorPair = getRandomColorPair();
textColor = "white";
//if colors are Orange or Yellow, textColor will be black
if (colorPair[0] == "#d3a116" || colorPair[0] == "#f5f423"){
textColor = "black";
}
themeWindow(currentWindow, textColor, colorPair[0], colorPair[1]);
break;
default:
themeWindow_default(currentWindow);
}
}
// function to get a random color pair.
// here, I tranformed colors that were set
// as a 2D array where each inner array
// is a pair of a darkColor and a lightColor
// e.g. [#b02300","#df6142"] = [red, lightRed]
function getRandomColorPair() {
colors = [["#b02300","#df6142"],["#d3a116","#dfbb58"],
["#f5f423","#fafa8e"], ["#3f6215", "#5e8231"],
["#5660fc", "#727ae6"],["#8509eb", "#a266cd"],
["#ba4a8e","#cb76a9"]]
var pair = colors[Math.floor(Math.random()*colors.length)];
//returns random pair of colors
return pair;
}
browser.runtime.onMessage.addListener(handleMessage);