Skip to content

Commit 0cd5af9

Browse files
authored
feat: add button to switch between incremental and absolute coverage (#45)
1 parent c0f2d29 commit 0cd5af9

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

assets/index.css

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
:root {
2+
--nav-gap: 15px;
23
--covered: green;
34
--uncovered: #bf616a;
45
--background: #ffffff;
56
--topbar-background: #f6f8fa;
67
--topbar-border: #d0d7de;
78
--topbar-color: #2e3440;
9+
--topbar-hover-color: #afb8c133;
810
--select-background: #d8dee9;
911
--select-border: #d0d7de;
1012
--select-color: #2e3440;
@@ -58,11 +60,12 @@ body {
5860
#legend {
5961
display: flex;
6062
align-items: center;
63+
margin-right: auto;
6164
}
6265

6366
#nav,
6467
#legend span {
65-
margin-left: 15px;
68+
margin-left: var(--nav-gap);
6669
color: var(--topbar-color) !important;
6770
}
6871

@@ -93,16 +96,36 @@ select {
9396
padding: 4px 24px 4px 8px;
9497
}
9598

96-
#legend span {
99+
#legend > span {
100+
padding: 2px 4px;
101+
border-radius: 2px;
102+
}
103+
104+
a.incremental {
105+
display: flex;
106+
background: var(--topbar-hover-color);
97107
padding: 2px 4px;
98108
border-radius: 2px;
109+
box-shadow: inset 0 0 0 1px var(--topbar-hover-color);
110+
color: var(--topbar-color);
111+
text-decoration: none;
112+
align-items: center;
113+
}
114+
115+
a.incremental:hover {
116+
background: transparent;
117+
box-shadow: inset 0 0 0 1px var(--topbar-hover-color);
118+
}
119+
120+
a.incremental:active {
121+
transform: translateY(1px);
99122
}
100123

101124
input[type="checkbox"] {
102125
height: 0;
103126
width: 0;
104127
visibility: hidden;
105-
margin-left: auto;
128+
margin-left: var(--nav-gap);
106129
}
107130

108131
label {
@@ -114,6 +137,7 @@ label {
114137
display: block;
115138
position: relative;
116139
margin-right: 15px;
140+
margin-right: var(--nav-gap);
117141
}
118142

119143
label:after {

assets/index.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function main() {
2929
return
3030
}
3131

32-
32+
configureIncrementalButton()
3333
configureSelectFix()
3434
configureTheme()
3535
configureCodeBlocks()
@@ -40,6 +40,31 @@ function main() {
4040
document.documentElement.style.setProperty('opacity', '1')
4141
}
4242

43+
function configureIncrementalButton() {
44+
let url = window.location.href
45+
let isInc = url.includes('-inc.html')
46+
47+
let link = document.createElement('a')
48+
link.classList = 'incremental'
49+
link.classList.add('hljs-selector-id')
50+
51+
if (isInc) {
52+
link.title = 'Toggle to absolute coverage'
53+
link.href = url.replace('-inc.html', '.html')
54+
} else {
55+
link.title = 'Toggle to incremental coverage'
56+
link.href = url.replace('.html', '-inc.html')
57+
}
58+
59+
link.innerHTML = `
60+
<span style="color: var(--covered);">↑</span>
61+
<span style="color: var(--uncovered);">↓</span>
62+
<span style="margin-left: 2px;">${isInc ? 'inc' : 'abs'}</span>
63+
`
64+
65+
document.querySelector('#topbar').appendChild(link)
66+
}
67+
4368
function configureSelectFix() {
4469
document.getElementById('files').addEventListener('change', (e) => {
4570
document.querySelectorAll('.file').forEach((el) => el.style.display = 'none')

0 commit comments

Comments
 (0)