AIFeed

Hacker News 极简深色模式样式

Translation(model translation, not the source's own text)

文章标题:Hacker News 的极简深色模式样式

正文: 出于某些令人费解的原因,Hacker News 的管理员不愿添加深色模式。常见的变通方法是使用 Stylus(Chromium、Firefox)或 Userscripts(Safari,包括 iOS)之类的工具应用自定义 CSS。

也有一些第三方的 HN 网页前端,但它们往往很慢,而且登录认证无法使用。你可以使用服务端代理并注入样式,但这更复杂,而且 HN 可能会对服务器 IP 限流或封禁。所以,在 HN 重新考虑之前,使用自定义 CSS 大概是最好的选择。

网上有很多深色 HN 主题,但我想分享最简单的一个。它对我来说完全够用:


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

invert(1) 会翻转每个颜色通道:亮变暗、暗变亮,每种颜色都变成其补色。接着 hue-rotate(180deg) 把色相在色轮上旋转半圈,大致还原出原来的颜色。于是明暗被反转,但颜色基本保持不变。background: #fff 给页面一个白色基底,滤镜再把它变成黑色。

Hacker News 深色模式
Hacker News 深色模式

这个技巧适用于任何网站,但原始样式越复杂,效果就越差。它还会把图片也反转。HN 的样式相当基础,所以效果不错。

顺便说一句,我还喜欢在较宽的屏幕上放大页面,以弥补固定布局和过小的字号:


        @media (min-width: 992px) {
    html {
        zoom: 1.25; /* 甚至可以是 1.5 */
    }
}
      

★ 订阅以跟进新文章。

The translation is machine-generated and individual terms may be off. Nothing is rewritten or cut; the original is authoritative.

Published by Hacker News
This site only summarises and aggregates; copyright stays with the original author. Headlines and summaries follow the source — where they differ, the original wins.
Read the original ↗