Skip to content

Commit 512fb29

Browse files
committed
add random color option
1 parent 6c1d8ff commit 512fb29

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

color.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,38 @@ async function handleMessage(request, sender, sendResponse) {
6060
case "Pink":
6161
themeWindow(currentWindow, "white", pink, lightPink);
6262
break;
63+
case "Random!":
64+
// colorPair will be an array of two colors,
65+
// colorPair[0] = darkColor
66+
// colorPair[1] = lightColor
67+
colorPair = getRandomColorPair();
68+
textColor = "white";
69+
70+
//if colors are Orange or Yellow, textColor will be black
71+
if (colorPair[0] == "#d3a116" || colorPair[0] == "#f5f423"){
72+
textColor = "black";
73+
}
74+
themeWindow(currentWindow, textColor, colorPair[0], colorPair[1]);
75+
break;
6376
default:
6477
themeWindow_default(currentWindow);
6578
}
6679
}
6780

81+
// function to get a random color pair.
82+
// here, I tranformed colors that were set
83+
// as a 2D array where each inner array
84+
// is a pair of a darkColor and a lightColor
85+
// e.g. [#b02300","#df6142"] = [red, lightRed]
86+
function getRandomColorPair() {
87+
colors = [["#b02300","#df6142"],["#d3a116","#dfbb58"],
88+
["#f5f423","#fafa8e"], ["#3f6215", "#5e8231"],
89+
["#5660fc", "#727ae6"],["#8509eb", "#a266cd"],
90+
["#ba4a8e","#cb76a9"]]
91+
var pair = colors[Math.floor(Math.random()*colors.length)];
92+
//returns random pair of colors
93+
return pair;
94+
}
95+
6896
browser.runtime.onMessage.addListener(handleMessage);
6997

popup.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ body {
8383
background-color: #cb76a9;
8484
}
8585

86+
.button8 {
87+
background-color: #808080;
88+
}
89+
90+
.button8:hover {
91+
background-color: #acabab;
92+
}
93+
8694
.button[type="reset"] {
8795
background-color: #555555;
8896
}

popup.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<button class="button button5">Blue</button>
1616
<button class="button button6">Purple</button>
1717
<button class="button button7">Pink</button>
18+
<button class="button button8">Random!</button>
1819
<button type="reset">Reset</button>
1920
</div>
2021
<script src="popup.js"></script>

0 commit comments

Comments
 (0)