This repository has been archived by the owner on May 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tackle .night_mode class in Overview and DeckBrowser #50
- Loading branch information
1 parent
7860895
commit c7bdbf6
Showing
3 changed files
with
40 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
def inject_css_class(state: bool, html: str): | ||
if state: | ||
javascript = """ | ||
function add_night_mode_class(){ | ||
current_classes = document.body.className; | ||
if(current_classes.indexOf("night_mode") == -1) | ||
{ | ||
document.body.className += " night_mode"; | ||
} | ||
} | ||
// explanation of setTimeout use: | ||
// callback defined in _showQuestion of reviewer.js would otherwise overwrite | ||
// the newly set body class; in order to prevent that the function execution | ||
// is being placed on the end of execution queue (hence time = 0) | ||
setTimeout(add_night_mode_class, 0) | ||
""" | ||
else: | ||
javascript = """ | ||
function remove_night_mode_class(){ | ||
current_classes = document.body.className; | ||
if(current_classes.indexOf("night_mode") != -1) | ||
{ | ||
document.body.className = current_classes.replace("night_mode",""); | ||
} | ||
} | ||
setTimeout(remove_night_mode_class, 0) | ||
""" | ||
# script on the beginning of the HTML so it will always be | ||
# before any user-defined, potentially malformed HTML | ||
html = f"<script>{javascript}</script>" + html | ||
return html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters