Minimal dark mode styles for Hacker News

原始链接: https://antonz.org/hn-dark-mode/

一个 Hacker News 帖子讨论了适用于 HN 的极简深色模式样式表。评论者分享了无需改动网站即可启用深色模式的方法:浏览器内置功能、Firefox 的无障碍颜色设置、Safari/Ladybird 的功能、Dark Reader 或 Stylus 扩展、用户脚本、Hack 和 hcker.news 等自定义客户端,以及 uBlock Origin 过滤器。几位用户发布了 CSS 片段,其中包括一条跟随系统深色模式的简单 invert/hue-rotate 规则。另一些人则主张 HN 应通过媒体查询或页脚开关加入原生深色模式,理由是可读性、一致性、弱光环境使用以及医疗需求。反对者更青睐 HN 克制、仅浅色的设计,并表示用户可以自行实现。争论还涉及深色模式疲劳、阅读视图,以及微小的界面改动是否会威胁 HN 的简洁性。
相关文章

原文

For some incomprehensible reason, the Hacker News admins won't add a dark mode. The usual workaround is to apply custom CSS with tools like Stylus (Chromium, Firefox) or Userscripts (Safari, including iOS).

There are also several custom HN web frontends, but they're often slow, and authentication doesn't work. You can use server-side proxying and inject the styles, but that's more involved, and HN can rate-limit or ban server IPs. So, using custom CSS is probably the best option until HN reconsiders.

There are plenty of dark HN themes online, but I want to share the simplest one. It works just fine for me:

@media (prefers-color-scheme: dark) {
    html {
        filter: invert(1) hue-rotate(180deg);
        background: #fff;
    }
}

invert(1) flips every color channel: light becomes dark, dark becomes light, and each color turns into its complement. hue-rotate(180deg) then rotates the hues halfway around the color wheel, approximately restoring the original colors. So light and dark are reversed, but the colors stay about the same. background: #fff gives the page a white base, which the filter changes to black.

This technique works on any site, but the more complex the original styling is, the worse the results will be. It also inverts images. HN's styles are pretty basic, so the results are fine.

While we're at it, I also like to zoom the page on wider screens to compensate for the fixed layout and tiny font size:

@media (min-width: 992px) {
    html {
        zoom: 1.25; /* or even 1.5 */
    }
}

That's it!

★ Subscribe to keep up with new posts.

联系我们 contact @ memedata.com