This commit is contained in:
Marc Beninca 2023-06-30 22:07:10 +02:00
parent eec7f6adc0
commit 7decae3625
3 changed files with 14 additions and 3 deletions

View file

@ -29,3 +29,12 @@ padding: 10px;
.tabs > div { .tabs > div {
padding: 10px; padding: 10px;
} }
body {
background-color: white;
color: black;
}
body.dark {
background-color: black;
color: white;
}

View file

@ -12,6 +12,7 @@
<!-----------------------------------------------------------------------------> <!----------------------------------------------------------------------------->
<h1>Tabs</h1> <h1>Tabs</h1>
<input type="checkbox" id="theme" onclick="swap()">Dark</input>
<ul> <ul>
<li><a href="test.html">test.html</a></li> <li><a href="test.html">test.html</a></li>
<li><a href="test.html?tab=2/3">test.html?tab=2/3</a></li> <li><a href="test.html?tab=2/3">test.html?tab=2/3</a></li>

View file

@ -6,16 +6,13 @@ function check(tab) {
document.getElementById(path).checked = true document.getElementById(path).checked = true
} }
} }
function push(tab) { function push(tab) {
window.history.pushState(null, null, `?tab=${tab}`) window.history.pushState(null, null, `?tab=${tab}`)
} }
function update(id) { function update(id) {
const tab = id.split('/').slice(1).join('/') const tab = id.split('/').slice(1).join('/')
push(tab) push(tab)
} }
function main() { function main() {
let tab = (new URL(document.location)).searchParams.get('tab') let tab = (new URL(document.location)).searchParams.get('tab')
if (tab) { if (tab) {
@ -26,3 +23,7 @@ function main() {
push(tab) push(tab)
} }
} }
function swap() {
document.body.classList.toggle('dark')
}