@@ -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+
6896browser . runtime . onMessage . addListener ( handleMessage ) ;
6997
0 commit comments