Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dark mode #82

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
1 change: 1 addition & 0 deletions mokuro/overlay_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ def option_color(id_, text_content, value):
option_toggle('menuEditableText', 'editable text ')
option_select('menuFontSize', 'font size: ',
['auto', 9, 10, 11, 12, 14, 16, 18, 20, 24, 32, 40, 48, 60])
option_toggle('menuDarkMode', 'dark mode')
option_toggle('menuEInkMode', 'e-ink mode ')
option_toggle('menuToggleOCRTextBoxes', 'toggle OCR text boxes on click')
option_color('menuBackgroundColor', 'background color', '#C4C3D0')
Expand Down
18 changes: 16 additions & 2 deletions mokuro/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ let defaultState = {
defaultZoomMode: "fit to screen",
toggleOCRTextBoxes: false,
backgroundColor: '#C4C3D0',
darkMode: false
};

let state = JSON.parse(JSON.stringify(defaultState));
let state = { ...defaultState };

function saveState() {
localStorage.setItem(storageKey, JSON.stringify(state));
Expand All @@ -50,6 +51,7 @@ function updateUI() {
document.getElementById("menuDisplayOCR").checked = state.displayOCR;
document.getElementById('menuFontSize').value = state.fontSize;
document.getElementById('menuEInkMode').checked = state.eInkMode;
document.getElementById('menuDarkMode').checked = state.darkMode;
document.getElementById('menuDefaultZoom').value = state.defaultZoomMode;
document.getElementById('menuToggleOCRTextBoxes').checked = state.toggleOCRTextBoxes;
document.getElementById('menuBackgroundColor').value = state.backgroundColor;
Expand Down Expand Up @@ -170,6 +172,12 @@ function updateProperties() {
if (state.backgroundColor) {
r.style.setProperty('--colorBackground', state.backgroundColor)
}

if (state.darkMode) {
pc.style.setProperty('filter', 'invert(1)');
} else {
pc.style.setProperty('filter', 'invert(0)');
}
}

document.getElementById('menuR2l').addEventListener('click', function () {
Expand Down Expand Up @@ -228,6 +236,12 @@ document.getElementById('menuToggleOCRTextBoxes').addEventListener('click', func
updateProperties();
}, false);

document.getElementById('menuDarkMode').addEventListener('click', function () {
state.darkMode = document.getElementById('menuDarkMode').checked;
saveState();
updateProperties();
});

document.getElementById('menuBackgroundColor').addEventListener(
'input',
function (event) {
Expand Down Expand Up @@ -555,4 +569,4 @@ function eInkRefresh() {
pc.classList.remove("inverted");
document.body.style.backgroundColor = r.style.getPropertyValue("--colorBackground");
}, 300);
}
}