Skip to content

Added dark mode toggle button #127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<div class="before"></div>
<div class="content">

<div id="dark-mode-toggle">
<button id="toggle-dark-mode">Toggle Theme</button>
<span id="dark-mode-status">Light Mode</span>
</div>

<div id="toggle-wrapper">
<a id="toggle" class="neutral" href="" title="Switch between HTTP and HTTPS.">
<span class="http">HTTP</span>
Expand Down
12 changes: 12 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@

window.addEventListener("load", function() {

const toggleDarkModeButton = document.getElementById('toggle-dark-mode');
const darkModeStatus = document.getElementById('dark-mode-status');

toggleDarkModeButton.addEventListener('click', function() {
document.body.classList.toggle('dark-mode');
if (document.body.classList.contains('dark-mode')) {
darkModeStatus.textContent = 'Dark Mode';
} else {
darkModeStatus.textContent = 'Light Mode';
}
});

var toggle = document.querySelector("#toggle");
toggle.classList.add("instant");
if (window.location.protocol == "https:") {
Expand Down
33 changes: 33 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,36 @@ permission {
display: block;
z-index: 99999; /* github-fork-ribbon-wrapper uses 9999 */
}


/* Dark Mode Styles */
body.dark-mode {
background: #333;
color: #FFF;
}

body.dark-mode button {
background: #444;
color: #FFF;
}

body.dark-mode .content {
background: #444;
}

body.dark-mode .permission-status > span,
body.dark-mode .access-status > span {
color: #FFF;
}

/* Dark Mode Toggle Button Styles */
#dark-mode-toggle {
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 1em;
}

#toggle-dark-mode {
margin-right: 1em;
}