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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added 'theme' GET parameter to PlayUI + theme selection according to OS fixes #35068

Merged
merged 1 commit into from Mar 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 15 additions & 12 deletions programs/server/play.html
Expand Up @@ -549,7 +549,7 @@

document.getElementById('logo-container').style.display = 'block';
}

function formatReadable(number = 0, decimals = 2, units = []) {
const k = 1000;
const i = number ? Math.floor(Math.log(number) / Math.log(k)) : 0;
Expand Down Expand Up @@ -759,20 +759,25 @@
svg.style.height = graph.graph().height;
}

function setColorTheme(theme)
{
function setColorTheme(theme) {
window.localStorage.setItem('theme', theme);
document.documentElement.setAttribute('data-theme', theme);
}

/// The choice of color theme is saved in browser.
let theme = window.localStorage.getItem('theme');
/**
* First we check if theme is set via the 'theme' GET parameter, if not, we check localStorage,
* otherwise we check OS preference
*/
let theme = current_url.searchParams.get('theme');
if (['dark', 'light'].indexOf(theme) === -1) {
theme = window.localStorage.getItem('theme');
}

if (theme) {
setColorTheme(theme);
document.documentElement.setAttribute('data-theme', theme);
} else {
/// Obtain system-level user preference
let media_query_list = window.matchMedia('prefers-color-scheme: dark')

const media_query_list = window.matchMedia('(prefers-color-scheme: dark)');
if (media_query_list.matches) {
/// Set without saving to localstorage
document.documentElement.setAttribute('data-theme', 'dark');
Expand All @@ -788,13 +793,11 @@
});
}

document.getElementById('toggle-light').onclick = function()
{
document.getElementById('toggle-light').onclick = function() {
setColorTheme('light');
}

document.getElementById('toggle-dark').onclick = function()
{
document.getElementById('toggle-dark').onclick = function() {
setColorTheme('dark');
}
</script>
Expand Down