Skip to content

Commit

Permalink
Dark Mode (smogon#525)
Browse files Browse the repository at this point in the history
* Finished dark theme

* Fixing code for tests; I miss es6

* Reduced FOIT, but is still there

* Added dark theme to Dynamax buttons

* Removed duplicate classes

* Added dark mode to Randoms calc

* Removed unnecessary dark-theme class

* Added Dark Mode for Honkalculator
Has small styling issues that I couldn't figure out how to fix

* Styled secret "Search" label
  • Loading branch information
shrianshChari authored and thejetou committed Apr 29, 2023
1 parent b4b3062 commit c3af31f
Show file tree
Hide file tree
Showing 5 changed files with 223 additions and 26 deletions.
116 changes: 116 additions & 0 deletions src/css/dark-theme.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/* Dark mode styles */

body {
color: white;
background-color: black;
}

.btn {
background-color: #161616;
color: #B7B7B7;
}

.btn:hover {
z-index: 10;
border-color: #888888;
background: black;
}

.visually-hidden:focus + .btn,
.btn:hover {
z-index: 10;
border-color: #888888;
background: black;
}

.visually-hidden:checked + .btn {
font-weight: bold;
color: white;
background: #000042;
}

.visually-hidden:disabled + .btn {
color: black;
}

fieldset {
background-color: #222222;
}

select {
background-color: black;
color: white;
}

a.links-lighten {
color: #7A9CFF;
}

a.links-lighten:hover {
color: #C2D0FF;
}

a.links-lighten:visited {
color: #BC8BEA;
}

a.links-lighten:visited:hover {
color: #DACAF7;
}

input {
background-color: black;
color: white;
}

textarea {
background-color: black;
color: white;
}

.wrapper {
background-color: black;
color: white;
}

a.collapsible-link {
color: white;
}

.bs-btn {
background-color: #161616;
color: #B7B7B7;
}

.bs-btn:hover {
z-index: 10;
border-color: #888888;
background: black;
}

.popover-content {
background-color: #161616;
color: #B7B7B7;
}

.dataTables_info {
color: #B7B7B7 !important; /* I know, don't use !important, but w/e */
}

.search-label {
color: #B7B7B7;
}

tr.odd, tr.even {
background-color: rgb(0 0 0) !important;
}


td.sorting_1 {
background-color: rgb(25 25 25) !important;
}


label:not(.btn) {
color: white;
}
27 changes: 21 additions & 6 deletions src/honkalculate.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<link type="text/css" rel="stylesheet" href="https://cdn.datatables.net/colvis/1.1.1/css/dataTables.colVis.css" />
<link type="text/css" rel="stylesheet" href="./js/vendor/select2/select2.css" />
<link type="text/css" rel="stylesheet" href="./css/main.css?" />
<link type="text/css" rel="stylesheet" href="./css/dark-theme.css" id="dark-theme-styles">
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-26211653-3"></script>
<script>
Expand All @@ -23,9 +24,21 @@
return false;
};
</script>
<!-- Immediately loads the dark theme in order to reduce FOIT -->
<script>
/*
* localStorage will only store strings
* This means that if it has the value 'false',
* It will be truey and incorrectly cause the
* dark theme to load.
*/
if (localStorage.getItem('darkTheme') !== 'true') {
document.getElementById('dark-theme-styles').disabled = true;
}
</script>
</head>

<body>
<body class="dark-theme">

<div class="header"><div class="header-inner">
<ul class="nav">
Expand Down Expand Up @@ -85,7 +98,7 @@
<div class="panel-group" id="accordion">
<fieldset class="panel panel-default poke-info" id="p1">
<legend class="panel-heading panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">> Pokemon</a>
<a data-toggle="collapse" data-parent="#accordion" href="#collapseOne" class="collapsible-link">> Pokemon</a>
</legend>
<div id="collapseOne" class="panel-collapse collapse in">
<div class="panel-body">
Expand Down Expand Up @@ -586,7 +599,7 @@
</fieldset>
<fieldset class="panel panel-default field-info">
<legend class="panel-heading panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapseTwo">> Field</a>
<a data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" class="collapsible-link">> Field</a>
</legend>
<div id="collapseTwo" class="panel-collapse collapse">
<div class="panel-body">
Expand Down Expand Up @@ -906,9 +919,11 @@
<script type="text/javascript" src="./js/honkalculate_controls.js?"></script>

<div style="clear:both;padding:20px;text-align:left">Created by Honko, maintained by Austin and Kris
<ul><li><a href="https://github.com/smogon/damage-calc/contributors" target="_blank">Contributors</a></li>
<li><a href="https://www.smogon.com/forums/threads/pok%C3%A9mon-showdown-damage-calculator.3593546/" target="_blank">Bug Reports</a></li>
<li><a href="https://github.com/smogon/damage-calc" target="_blank">GitHub repository</a></li></ul>
<ul><li><a href="https://github.com/smogon/damage-calc/contributors" class="links-lighten" target="_blank">Contributors</a></li>
<li><a href="https://www.smogon.com/forums/threads/pok%C3%A9mon-showdown-damage-calculator.3593546/" class="links-lighten" target="_blank">Bug Reports</a></li>
<li><a href="https://github.com/smogon/damage-calc" class="links-lighten" target="_blank">GitHub repository</a></li></ul>
<button type="button" id="dark-theme-toggle"></button>
<script type="text/javascript" src="./js/dark-theme-toggle.js?"></script>
</div>

</body>
Expand Down
28 changes: 22 additions & 6 deletions src/index.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<link type="text/css" rel="stylesheet" href="./js/vendor/select2/select2.css" />
<link type="text/css" rel="stylesheet" href="./css/main.css?" />
<link type="text/css" rel="stylesheet" href="./css/vendor/bootstrap.css" />
<link type="text/css" rel="stylesheet" href="./css/dark-theme.css" id="dark-theme-styles">
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-26211653-3"></script>
<script>
Expand All @@ -21,9 +22,21 @@
return false;
};
</script>
<!-- Immediately loads the dark theme in order to reduce FOIT -->
<script>
/*
* localStorage will only store strings
* This means that if it has the value 'false',
* It will be truey and incorrectly cause the
* dark theme to load.
*/
if (localStorage.getItem('darkTheme') !== 'true') {
document.getElementById('dark-theme-styles').disabled = true;
}
</script>
</head>

<body>
<body class="dark-theme">

<nav><div class="header"><div class="header-inner">
<ul class="nav">
Expand Down Expand Up @@ -140,7 +153,7 @@
<label>Type</label>
<select aria-label="type1" class="type1 terrain-trigger calc-trigger"></select>
<select aria-label="type2" class="type2 terrain-trigger calc-trigger"></select>
<small class="right">(<a class="analysis" target="_blank" href="">Smogon&nbsp;analysis</a>)</small>
<small class="right">(<a class="analysis links-lighten" target="_blank" href="">Smogon&nbsp;analysis</a>)</small>
</div>
<div class="gen-specific g9">
<label>Tera Type</label>
Expand Down Expand Up @@ -1027,7 +1040,7 @@
<label>Type</label>
<select aria-label="Type 1" class="type1 terrain-trigger calc-trigger"></select>
<select aria-label="Type 2" class="type2 terrain-trigger calc-trigger"></select>
<small class="right">(<a class="analysis" target="_blank" href="">Smogon&nbsp;analysis</a>)</small>
<small class="right">(<a class="analysis links-lighten" target="_blank" href="">Smogon&nbsp;analysis</a>)</small>
</div>
<div class="gen-specific g9">
<label>Tera Type</label>
Expand Down Expand Up @@ -1595,9 +1608,12 @@
</div>

<div class="credits">Created by Honko, maintained by Austin and Kris
<ul><li><a href="https://github.com/smogon/damage-calc/contributors" target="_blank">Contributors</a></li>
<li><a href="https://www.smogon.com/forums/threads/pok%C3%A9mon-showdown-damage-calculator.3593546/" target="_blank">Bug Reports</a></li>
<li><a href="https://github.com/smogon/damage-calc" target="_blank">GitHub repository</a></li></ul>
<ul><li><a href="https://github.com/smogon/damage-calc/contributors" class="links-lighten" target="_blank">Contributors</a></li>
<li><a href="https://www.smogon.com/forums/threads/pok%C3%A9mon-showdown-damage-calculator.3593546/" class="links-lighten" target="_blank">Bug Reports</a></li>
<li><a href="https://github.com/smogon/damage-calc" class="links-lighten" target="_blank">GitHub repository</a></li></ul>

<button type="button" id="dark-theme-toggle"></button>
<script type="text/javascript" src="./js/dark-theme-toggle.js?"></script>
</div>

</body>
Expand Down
35 changes: 35 additions & 0 deletions src/js/dark-theme-toggle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Dark mode toggle
*
* In its current state, it will cause a minor FOIT.
* Basically, the background behind the panels will
* briefly flash white before turning dark. It's
* better than before, but not perfect.
*/

/*
* localStorage will only store strings
* This means that if it has the value 'false',
* It will be truey and incorrectly cause the
* dark theme to load.
*/
var prefersDarkTheme = localStorage.getItem('darkTheme') === 'true';

var darkThemeButton = document.getElementById('dark-theme-toggle');
darkThemeButton.innerText = prefersDarkTheme ? 'Click for Light Theme' : 'Click for Dark Theme';

/*
* Function that toggles light and dark mode
* Doesn't use jQuery, probably could with some modification
*/
function toggleTheme() {
prefersDarkTheme = !prefersDarkTheme;

var darkStyles = document.getElementById('dark-theme-styles');
darkStyles.disabled = !darkStyles.disabled;

localStorage.setItem('darkTheme', prefersDarkTheme);
darkThemeButton.innerText = prefersDarkTheme ? 'Click for Light Theme' : 'Click for Dark Theme';
}

darkThemeButton.addEventListener('click', toggleTheme);
43 changes: 29 additions & 14 deletions src/randoms.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<link type="text/css" rel="stylesheet" href="./js/vendor/select2/select2.css" />
<link type="text/css" rel="stylesheet" href="./css/main.css?" />
<link type="text/css" rel="stylesheet" href="./css/vendor/bootstrap.css" />
<link type="text/css" rel="stylesheet" href="./css/dark-theme.css" id="dark-theme-styles">
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-26211653-3"></script>
<script>
Expand All @@ -21,9 +22,21 @@
return false;
};
</script>
<!-- Immediately loads the dark theme in order to reduce FOIT -->
<script>
/*
* localStorage will only store strings
* This means that if it has the value 'false',
* It will be truey and incorrectly cause the
* dark theme to load.
*/
if (localStorage.getItem('darkTheme') !== 'true') {
document.getElementById('dark-theme-styles').disabled = true;
}
</script>
</head>

<body>
<body class="dark-theme">

<nav><div class="header"><div class="header-inner">
<ul class="nav">
Expand Down Expand Up @@ -1399,7 +1412,7 @@
<select class="move-selector calc-trigger small-select"></select>
<input class="move-bp calc-trigger" value="50" />
<select class="move-type calc-trigger"></select>
<select class="move-cat calc-trigger gen-specific g4 g5 g6 g7 g8 g9">
<select class="move-cat calc-trigger gen-specific g4 g5 g6 g7 g8 g9 dark-theme">
<option value="Physical">Physical</option>
<option value="Special">Special</option>
</select>
Expand Down Expand Up @@ -1431,9 +1444,9 @@
</div>
<div class="move2">
<select class="move-selector calc-trigger small-select"></select>
<input class="move-bp calc-trigger" value="0" />
<select class="move-type calc-trigger"></select>
<select class="move-cat calc-trigger gen-specific g4 g5 g6 g7 g8 g9">
<input class="move-bp calc-trigger dark-theme" value="0" />
<select class="move-type calc-trigger dark-theme"></select>
<select class="move-cat calc-trigger gen-specific g4 g5 g6 g7 g8 g9 dark-theme">
<option value="Physical">Physical</option>
<option value="Special">Special</option>
</select>
Expand Down Expand Up @@ -1465,9 +1478,9 @@
</div>
<div class="move3">
<select class="move-selector calc-trigger small-select"></select>
<input class="move-bp calc-trigger" value="0" />
<select class="move-type calc-trigger"></select>
<select class="move-cat calc-trigger gen-specific g4 g5 g6 g7 g8 g9">
<input class="move-bp calc-trigger dark-theme" value="0" />
<select class="move-type calc-trigger dark-theme"></select>
<select class="move-cat calc-trigger gen-specific g4 g5 g6 g7 g8 g9 dark-theme">
<option value="Physical">Physical</option>
<option value="Special">Special</option>
</select>
Expand Down Expand Up @@ -1499,9 +1512,9 @@
</div>
<div class="move4">
<select class="move-selector calc-trigger small-select"></select>
<input class="move-bp calc-trigger" value="0" />
<select class="move-type calc-trigger"></select>
<select class="move-cat calc-trigger gen-specific g4 g5 g6 g7 g8 g9">
<input class="move-bp calc-trigger dark-theme" value="0" />
<select class="move-type calc-trigger dark-theme"></select>
<select class="move-cat calc-trigger gen-specific g4 g5 g6 g7 g8 g9 dark-theme">
<option value="Physical">Physical</option>
<option value="Special">Special</option>
</select>
Expand Down Expand Up @@ -1590,9 +1603,11 @@
</div>

<div class="credits">Created by Honko, maintained by Austin and Kris
<ul><li><a href="https://github.com/smogon/damage-calc/contributors" target="_blank">Contributors</a></li>
<li><a href="https://www.smogon.com/forums/threads/pok%C3%A9mon-showdown-damage-calculator.3593546/" target="_blank">Bug Reports</a></li>
<li><a href="https://github.com/smogon/damage-calc" target="_blank">GitHub repository</a></li></ul>
<ul><li><a href="https://github.com/smogon/damage-calc/contributors" class="links-lighten" target="_blank">Contributors</a></li>
<li><a href="https://www.smogon.com/forums/threads/pok%C3%A9mon-showdown-damage-calculator.3593546/" class="links-lighten" target="_blank">Bug Reports</a></li>
<li><a href="https://github.com/smogon/damage-calc" class="links-lighten" target="_blank">GitHub repository</a></li></ul>
<button type="button" id="dark-theme-toggle"></button>
<script type="text/javascript" src="./js/dark-theme-toggle.js?"></script>
</div>

</body>
Expand Down

0 comments on commit c3af31f

Please sign in to comment.