1
0
mirror of https://github.com/kognise/water.css.git synced 2025-08-16 10:04:41 +02:00

fix: always update product hunt on theme change

If the selected (forced) theme was different from the system preference
and then switches back to auto, need to reset the product hunt theme too
This commit is contained in:
Jonas Kuske
2020-05-30 03:00:15 +02:00
parent aff527a791
commit f8c095827b

View File

@@ -22,7 +22,10 @@ const table = {
browserSupport: document.getElementById('table-browser-support') browserSupport: document.getElementById('table-browser-support')
} }
const updateProductHunt = (theme) => { const prefersColorScheme = window.matchMedia('(prefers-color-scheme: light)')
const updateProductHunt = () => {
const theme = prefersColorScheme.matches ? 'light' : 'dark'
productHunt.src = `https://api.producthunt.com/widgets/embed-image/v1/top-post-badge.svg?post_id=150490&theme=${theme}&period=daily` productHunt.src = `https://api.producthunt.com/widgets/embed-image/v1/top-post-badge.svg?post_id=150490&theme=${theme}&period=daily`
} }
@@ -39,6 +42,8 @@ const updateTheme = () => {
table.fileName.innerText = fileName table.fileName.innerText = fileName
table.fileSize.innerText = `${fileSizes[theme].toFixed(2)} kb` table.fileSize.innerText = `${fileSizes[theme].toFixed(2)} kb`
updateProductHunt()
if (theme === 'auto') { if (theme === 'auto') {
table.theme.innerHTML = ` table.theme.innerHTML = `
Defaults to light, but respects user-defined theme settings.<br> Defaults to light, but respects user-defined theme settings.<br>
@@ -51,17 +56,15 @@ const updateTheme = () => {
} else { } else {
table.theme.innerText = `Theme is forced to ${theme}.` table.theme.innerText = `Theme is forced to ${theme}.`
table.browserSupport.innerText = 'All browsers (including Internet Explorer)' table.browserSupport.innerText = 'All browsers (including Internet Explorer)'
updateProductHunt(theme)
} }
} }
themeForm.addEventListener('change', updateTheme) themeForm.addEventListener('change', updateTheme)
const prefersColorScheme = window.matchMedia('(prefers-color-scheme: light)') updateProductHunt()
updateProductHunt(prefersColorScheme.matches ? 'light' : 'dark')
prefersColorScheme.addListener(() => { prefersColorScheme.addListener(() => {
if (themeForm.theme.value !== 'auto') return if (themeForm.theme.value !== 'auto') return
updateProductHunt(prefersColorScheme.matches ? 'light' : 'dark') updateProductHunt()
}) })
updateTheme() updateTheme()