Skip to content

Commit

Permalink
Merge pull request #70 from JohannesNE/query-theme
Browse files Browse the repository at this point in the history
Allow user query to force theme
  • Loading branch information
JohannesNE authored Feb 24, 2024
2 parents 82f5ebe + 3bb5065 commit 575212a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# literature-clock
Clock using time quotes from the literature, based on work and idea by
[Jaap Meijers](http://www.eerlijkemedia.nl/) ([E-reader clock](https://www.instructables.com/id/Literary-Clock-Made-From-E-reader/)).


Force light or dark theme with the `theme` query parameter. E.g. https://literature-clock.jenevoldsen.com?theme=dark

The working site is in the docs/ folder, and can be visited at http://literature-clock.jenevoldsen.com/. To run it locally you may need to serve docs/ with an HTTP server (e.g. `python3 -m http.server`) ... or just open index.html in Firefox (thanks [@gbear605](https://github.com/gbear605)).

> ℹ️ NB: Some quotes are potentially NSFW. See issue [#11](https://github.com/JohannesNE/literature-clock/issues/11).
Expand Down
13 changes: 11 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,25 @@

function init() {
// This code runs only at page load
var queries = new URLSearchParams(window.location.search);


if (queries.has('theme')) {
var query_theme = queries.get('theme').toLowerCase();
if (query_theme === 'dark') {
dark_theme();
} else {
light_theme();
}
}
// Try to guess theme preference
if (localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
else if (localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
dark_theme();
} else {
light_theme();
}

// Check if sfw query parameter passed
var queries = new URLSearchParams(window.location.search);
var sfw = queries.has('sfw') && ['yes', 'true', '1'].includes(queries.get('sfw').toLowerCase());

if (sfw) {
Expand Down

0 comments on commit 575212a

Please sign in to comment.