mirror of
https://github.com/kognise/water.css.git
synced 2025-02-22 21:03:12 +01: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:
parent
aff527a791
commit
f8c095827b
@ -22,7 +22,10 @@ const table = {
|
||||
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`
|
||||
}
|
||||
|
||||
@ -39,6 +42,8 @@ const updateTheme = () => {
|
||||
table.fileName.innerText = fileName
|
||||
table.fileSize.innerText = `${fileSizes[theme].toFixed(2)} kb`
|
||||
|
||||
updateProductHunt()
|
||||
|
||||
if (theme === 'auto') {
|
||||
table.theme.innerHTML = `
|
||||
Defaults to light, but respects user-defined theme settings.<br>
|
||||
@ -51,17 +56,15 @@ const updateTheme = () => {
|
||||
} else {
|
||||
table.theme.innerText = `Theme is forced to ${theme}.`
|
||||
table.browserSupport.innerText = 'All browsers (including Internet Explorer)'
|
||||
updateProductHunt(theme)
|
||||
}
|
||||
}
|
||||
|
||||
themeForm.addEventListener('change', updateTheme)
|
||||
|
||||
const prefersColorScheme = window.matchMedia('(prefers-color-scheme: light)')
|
||||
updateProductHunt(prefersColorScheme.matches ? 'light' : 'dark')
|
||||
updateProductHunt()
|
||||
prefersColorScheme.addListener(() => {
|
||||
if (themeForm.theme.value !== 'auto') return
|
||||
updateProductHunt(prefersColorScheme.matches ? 'light' : 'dark')
|
||||
updateProductHunt()
|
||||
})
|
||||
|
||||
updateTheme()
|
||||
|
Loading…
x
Reference in New Issue
Block a user