From afe8880a0f8e2e85c6b13ce9ab7f972067dc1c1d Mon Sep 17 00:00:00 2001 From: Felix Date: Thu, 28 May 2020 14:54:07 -0500 Subject: [PATCH] Update product hunt badge --- docs/index.html | 2 +- docs/script.js | 15 ++++++++++++++- docs/style.css | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/docs/index.html b/docs/index.html index 9710379..487450d 100644 --- a/docs/index.html +++ b/docs/index.html @@ -100,7 +100,7 @@ target="_blank" > Water.css - Make your tiny website just a little nicer | Product Hunt Embed { + productHunt.src = `https://api.producthunt.com/widgets/embed-image/v1/top-post-badge.svg?post_id=150490&theme=${theme}&period=daily` +} + const updateTheme = () => { const theme = themeForm.theme.value const fileName = `${theme === 'auto' ? 'water' : theme}.min.css` @@ -40,11 +45,19 @@ const updateTheme = () => { } else { table.theme.innerText = `Theme is forced to ${theme}` table.browserSupport.innerText = 'All browsers (including Internet Explorer)' + updateProductHunt(theme) } } themeForm.addEventListener('input', updateTheme) +const prefersColorScheme = window.matchMedia('(prefers-color-scheme: light)') +updateProductHunt(prefersColorScheme.matches ? 'light' : 'dark') +prefersColorScheme.addEventListener('change', () => { + if (themeForm.theme.value !== 'auto') return + updateProductHunt(prefersColorScheme.matches ? 'light' : 'dark') +}) + updateTheme() startupStylesheet.remove() @@ -129,7 +142,7 @@ startupStylesheet.remove() // /** Handles elements external to the version picker that still need to be kept // * up to date with the current version, e.g. switching images from dark to light. */ // const externalElements = { -// _productHunt: /** @type {HTMLImageElement} */ (document.querySelector('#js-producthunt')), +// _productHunt: /** @type {HTMLImageElement} */ (document.querySelector('#product-hunt')), // _stylesheet: /** @type {HTMLLinkElement} */ (document.querySelector('#js-stylesheet')), // _removeStartupStylesheet: () => { // const startupStylesheet = document.head.querySelector('#js-startup-stylesheet') diff --git a/docs/style.css b/docs/style.css index 0e652bc..34b20f8 100755 --- a/docs/style.css +++ b/docs/style.css @@ -2,7 +2,7 @@ html { scroll-behavior: smooth; } -#js-producthunt { +#product-hunt { margin-top: 1rem; }