Skip to content

Commit 7e316ee

Browse files
committed
public: dark mode support
1 parent cc61996 commit 7e316ee

File tree

5 files changed

+115
-10
lines changed

5 files changed

+115
-10
lines changed

TODO.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
- [x] Test package support
44
- [x] Auto format && import
5+
- [x] Dark mode
56
- [ ] Message: waiting for SSA response
67
- [ ] Better Editor: Monaco Editor
78
- [ ] Dragable SSA

public/dark.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
var enabled = localStorage.getItem('dark-mode')
2+
if (enabled === null) {
3+
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
4+
enable(); document.getElementById("dark-mode-checkbox").checked = true;
5+
}
6+
} else if (enabled === 'true') {
7+
enable(); document.getElementById("dark-mode-checkbox").checked = true;
8+
}
9+
function enable() {
10+
DarkReader.enable({brightness: 100, contrast: 85, sepia: 10});
11+
localStorage.setItem('dark-mode', 'true');
12+
}
13+
function disable() {
14+
DarkReader.disable();
15+
localStorage.setItem('dark-mode', 'false')
16+
}
17+
function darkmode() {
18+
console
19+
if (localStorage.getItem('dark-mode') === 'false') { enable(); } else { disable();}
20+
}

public/index.html

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
<input class="btn btn-primary" type="button" value="Build" id="build">
2020
</div>
2121
<div id="aboutControls">
22+
<label class="switch">
23+
<input id="dark-mode-checkbox" type="checkbox" onchange="darkmode()">
24+
<span class="slider"></span>
25+
</label>
2226
<input class="btn btn-primary" type="button" value="About" id="aboutbtn">
2327
</div>
2428
</div>
@@ -40,11 +44,15 @@
4044

4145
<p>The Go SSA Playground uses the latest stable release of Go. The current version is <a id="version" href="https://golang.org/dl/"></a>.</p>
4246

43-
<p>GitHub: <a href="https://github.com/changkun/ssaplayground">github.com/changkun/ssaplayground</a></p>
44-
47+
<ul>
48+
<li>Website: <a href="https://changkun.de/gossa">changkun.de/gossa</a></li>
49+
<li>GitHub: <a href="https://github.com/changkun/ssaplayground">github.com/changkun/ssaplayground</a></li>
50+
</ul>
4551
<p>The author of the Go SSA Playground is <a href="https://changkun.de">Changkun Ou</a>.</p>
4652
</div>
4753
</div>
4854
<script src="/gossa/main.js"></script>
55+
<script src="/gossa/magic.js"></script>
56+
<script src="/gossa/dark.js"></script>
4957
</body>
5058
</html>

public/magic.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/style.css

Lines changed: 81 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ body {
2121
min-width: 245px;
2222
}
2323
#aboutControls {
24+
display: flex;
2425
float: right;
2526
padding: 10px 15px;
2627
}
@@ -65,14 +66,23 @@ body {
6566
input[type=button] {
6667
background: #375EAB;
6768
color: white;
68-
text-align: center;
69-
cursor: pointer;
70-
border: 1px solid transparent;
71-
padding: 5.3px 12px;
69+
text-align: center;
70+
cursor: pointer;
71+
border: 1px solid transparent;
72+
padding: 5.3px 12px;
7273
font-size: 14px;
7374
border-radius: 4px;
7475
user-select: none;
7576
}
77+
input[type=button]:hover {
78+
background: rgb(36, 75, 152);
79+
}
80+
input[type=button]:active {
81+
background: rgb(13, 43, 104);
82+
}
83+
input[type=button]:focus {
84+
outline: 0;
85+
}
7686
#main {
7787
padding-top: 50px;
7888
display: flex;
@@ -83,7 +93,7 @@ input[type=button] {
8393
#snippet {
8494
flex: 30%;
8595
padding: 10px;
86-
background: #FFD;
96+
background: rgba(255, 252, 221, 0.81);
8797
}
8898
#code, #output, pre, .lines {
8999
font-family: Menlo, monospace;
@@ -119,7 +129,70 @@ input[type=button] {
119129
padding-right: 5px;
120130
color: lightgray;
121131
}
122-
.lineerror {
123-
color: red;
124-
background: #FDD;
132+
133+
/* Dark Mode Toggle */
134+
135+
/* The switch - the box around the slider */
136+
.switch {
137+
position: relative;
138+
margin-right: 20px;
139+
width: 60px;
140+
height: 32px;
141+
}
142+
143+
/* Hide default HTML checkbox */
144+
.switch input {
145+
opacity: 0;
146+
width: 0;
147+
height: 0;
148+
}
149+
150+
/* The slider */
151+
.slider {
152+
position: absolute;
153+
cursor: pointer;
154+
top: 0;
155+
left: 0;
156+
right: 0;
157+
bottom: 0;
158+
border-radius: 4px;
159+
background-color: #ccc;
160+
-webkit-transition: .4s;
161+
transition: .4s;
162+
}
163+
164+
.slider:before {
165+
position: absolute;
166+
content: "";
167+
border-radius: 4px;
168+
height: 24px;
169+
width: 26px;
170+
left: 4px;
171+
bottom: 4px;
172+
background-color: white;
173+
-webkit-transition: .4s;
174+
transition: .4s;
175+
}
176+
177+
input:checked + .slider {
178+
background-color: #375EAB;
179+
}
180+
181+
input:focus + .slider {
182+
box-shadow: 0 0 1px #375EAB;
125183
}
184+
185+
input:checked + .slider:before {
186+
-webkit-transform: translateX(26px);
187+
-ms-transform: translateX(26px);
188+
transform: translateX(26px);
189+
}
190+
191+
/* Rounded sliders */
192+
.slider.round {
193+
border-radius: 34px;
194+
}
195+
196+
.slider.round:before {
197+
border-radius: 50%;
198+
}

0 commit comments

Comments
 (0)