Skip to content

Commit e707cf1

Browse files
committed
public: support darkmode
Fixes #14
1 parent 7047a52 commit e707cf1

File tree

3 files changed

+70
-70
lines changed

3 files changed

+70
-70
lines changed

public/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@
3737
</div>
3838
<div id="about">
3939
<p><b>About the Go SSA Playground</b></p>
40-
40+
4141
<p>
4242
The Go SSA Playground is a web service that compiles a Go program and demonstrates the SSA intermediate representation of given function name.
4343
</p>
44-
44+
4545
<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>
4646

4747
<ul>

public/main.js

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,80 @@ function ping() {
1010
ping(); // inject version info
1111

1212

13-
13+
let darkMode = false
1414
let msgbox = document.getElementById('outputMsg')
1515
let ssabox = document.getElementById('ssa')
1616
ssabox.addEventListener('load', () => {
17+
if (darkMode) {
18+
ssabox.contentWindow.document.getElementById('dark-mode-button').click()
19+
}
20+
1721
// inject ssa style
1822
$("iframe").contents().find("head").append($("<link/>", { rel: 'stylesheet', href: '/gossa/scrollbar.css', type: 'text/css'}));
1923
setMessageBox('', true)
24+
ssabox.contentWindow.document
25+
.getElementById('dark-mode-button')
26+
.addEventListener('click', function() {
27+
const banner = document.getElementById('banner')
28+
const snippet = document.getElementById('snippet')
29+
const about = document.getElementById('about')
30+
const funcname = document.getElementById('funcname')
31+
const gcflags = document.getElementById('gcflags')
32+
const horiz = document.querySelectorAll('.gutter.gutter-horizontal')
33+
const btns = document.querySelectorAll('input[type=button]')
34+
const code = document.getElementById('code')
35+
const links = document.querySelectorAll('#about a')
36+
37+
if (darkMode) {
38+
banner.style.backgroundColor = '#E0EBF5'
39+
snippet.style.backgroundColor = 'rgba(255, 252, 221, 0.81)'
40+
about.style.backgroundColor = '#FFD'
41+
funcname.style.backgroundColor = '#fff'
42+
funcname.style.border = '1px solid #ccc'
43+
funcname.style.color = ''
44+
gcflags.style.backgroundColor = '#fff'
45+
gcflags.style.border = '1px solid #ccc'
46+
gcflags.style.color = ''
47+
horiz.forEach((v) => {
48+
v.style.filter = ''
49+
})
50+
btns.forEach((v) => {
51+
v.style.backgroundColor = '#375EAB'
52+
v.style.color = '#fff'
53+
})
54+
code.style.color = 'black'
55+
links.forEach(v => {
56+
v.style.color = ''
57+
})
58+
document.body.style.color = 'black'
59+
60+
darkMode = false
61+
} else {
62+
banner.style.backgroundColor = '#566'
63+
snippet.style.backgroundColor = '#665'
64+
about.style.backgroundColor = '#665'
65+
funcname.style.backgroundColor = '#343'
66+
funcname.style.border = '1px solid #454'
67+
funcname.style.color = 'lightgray'
68+
gcflags.style.backgroundColor = '#343'
69+
gcflags.style.border = '1px solid #454'
70+
gcflags.style.color = 'lightgray'
71+
horiz.forEach((v) => {
72+
v.style.filter = 'invert(.7)'
73+
})
74+
btns.forEach((v) => {
75+
v.style.backgroundColor = '#0044cb'
76+
v.style.color = 'lightgray'
77+
})
78+
code.style.color = 'rgb(230, 255, 255)'
79+
links.forEach(v => {
80+
v.style.color = '#809fff'
81+
})
82+
document.body.style.color = 'lightgray'
83+
84+
darkMode = true
85+
}
86+
})
2087
});
2188

2289
let lastFuncName, lastCode, lastGcflags;

public/style.css

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -148,70 +148,3 @@ input[type=button]:focus {
148148
background-image: url('/gossa/vertical.png');
149149
cursor: col-resize;
150150
}
151-
152-
/* Dark Mode Toggle */
153-
154-
/* The switch - the box around the slider */
155-
.switch {
156-
position: relative;
157-
margin-right: 20px;
158-
width: 60px;
159-
height: 32px;
160-
}
161-
162-
/* Hide default HTML checkbox */
163-
.switch input {
164-
opacity: 0;
165-
width: 0;
166-
height: 0;
167-
}
168-
169-
/* The slider */
170-
.slider {
171-
position: absolute;
172-
cursor: pointer;
173-
top: 0;
174-
left: 0;
175-
right: 0;
176-
bottom: 0;
177-
border-radius: 4px;
178-
background-color: #ccc;
179-
-webkit-transition: .4s;
180-
transition: .4s;
181-
}
182-
183-
.slider:before {
184-
position: absolute;
185-
content: "";
186-
border-radius: 4px;
187-
height: 24px;
188-
width: 26px;
189-
left: 4px;
190-
bottom: 4px;
191-
background-color: white;
192-
-webkit-transition: .4s;
193-
transition: .4s;
194-
}
195-
196-
input:checked + .slider {
197-
background-color: #375EAB;
198-
}
199-
200-
input:focus + .slider {
201-
box-shadow: 0 0 1px #375EAB;
202-
}
203-
204-
input:checked + .slider:before {
205-
-webkit-transform: translateX(26px);
206-
-ms-transform: translateX(26px);
207-
transform: translateX(26px);
208-
}
209-
210-
/* Rounded sliders */
211-
.slider.round {
212-
border-radius: 34px;
213-
}
214-
215-
.slider.round:before {
216-
border-radius: 50%;
217-
}

0 commit comments

Comments
 (0)