Skip to content
This repository was archived by the owner on Dec 15, 2020. It is now read-only.

Commit 98a87e6

Browse files
committed
add dark theme option
1 parent 4a0349f commit 98a87e6

3 files changed

Lines changed: 69 additions & 0 deletions

File tree

index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<html>
33
<head>
44
<link rel="stylesheet" type="text/css" href="stylesheets/styles.css">
5+
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
6+
<script src='script.js' type='text/javascript'></script>
57
<title>One PR A Day</title>
68
</head>
79
<body>
@@ -13,5 +15,9 @@ <h1>I will be accepting up to one pull request per day on <a href="https://githu
1315
<li>Find some inspiration for cool ideas on what you can add to the project <a href="https://medium.freecodecamp.com/6-absurd-ideas-for-building-your-first-web-application-24afca35e519#.do2wbrk4s">from this medium post</a></li>
1416
</ul>
1517
</div>
18+
<div class='theme-buttons'>Theme:&nbsp;
19+
<button id='light-button'>Dark</button>
20+
<button id='dark-button'>Light</button>
21+
</div>
1622
</body>
1723
</html>

script.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
$(document).ready(function() {
2+
function setDarkTheme() {
3+
$('body').addClass('dark');
4+
$('#dark-button').hide();
5+
$('#light-button').show();
6+
localStorage.setItem('darkThemeEnabled', 1);
7+
}
8+
9+
function setLightTheme() {
10+
$('body').removeClass('dark');
11+
$('#dark-button').show();
12+
$('#light-button').hide();
13+
localStorage.setItem('darkThemeEnabled', 0);
14+
}
15+
16+
if (localStorage.getItem('darkThemeEnabled')
17+
&& localStorage.getItem('darkThemeEnabled') === '1') {
18+
setDarkTheme();
19+
}
20+
21+
$('#light-button').click(setLightTheme);
22+
$('#dark-button').click(setDarkTheme);
23+
});

stylesheets/styles.css

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,43 @@ div {
1414
margin-left: 25%;
1515
margin-right: 25%;
1616
}
17+
18+
button {
19+
border-style: solid;
20+
border-radius: 2px;
21+
font-size: 14px;
22+
font-weight: bold;
23+
}
24+
25+
.theme-buttons {
26+
position:absolute;
27+
left:10px;
28+
bottom:10px;
29+
margin: 0px;
30+
}
31+
32+
body.dark {
33+
background-color: #333;
34+
}
35+
36+
.dark h1 {
37+
color: #DDD;
38+
}
39+
40+
.dark div {
41+
color: #DDD;
42+
}
43+
44+
.dark a {
45+
color: #AAF;
46+
}
47+
48+
.dark a:visited {
49+
color: #DAC;
50+
}
51+
52+
.dark button {
53+
background-color: #444;
54+
border-color: #444;
55+
color: #DDD;
56+
}

0 commit comments

Comments
 (0)