From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 82D0320305 for ; Sun, 21 Apr 2019 21:24:23 +0000 (UTC) From: Eric Wong To: yahns-public@yhbt.net Subject: [PATCH] extras/autoindex: use dark colors by default Date: Sun, 21 Apr 2019 21:24:23 +0000 Message-Id: <20190421212423.11453-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Some browsers (e.g. Firefox 67.0a1 via "ui.systemUsesDarkTheme") are adding support for the "prefers-color-scheme" @media query. So this allows pages to respect user choice when it comes to dark or light schemes. OLED and CRT displays measure significant power savings when using dark schemes. Dark themes work better with less ambient light, so favoring darkness can lead to overall power savings even with CCFL and LED-lit displays. --- extras/autoindex.rb | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/extras/autoindex.rb b/extras/autoindex.rb index 45b80cf..9060c6c 100644 --- a/extras/autoindex.rb +++ b/extras/autoindex.rb @@ -14,6 +14,21 @@ class Autoindex FN = %{%s} TFMT = "%Y-%m-%d %H:%M" + # default to a dark, web-safe (216 color) palette for power-savings. + # Color-capable browsers can respect the prefers-color-scheme:light + # @media query (browser support a work-in-progress) + STYLE = <<''.gsub(/^\s*/m, '').delete!("\n") +@media screen { + *{background:#000;color:#ccc} + a{color:#69f;text-decoration:none} + a:visited{color:#96f} +} +@media screen AND (prefers-color-scheme:light) { + *{background:#fff;color:#333} + a{color:#00f;text-decoration:none} + a:visited{color:#808} +} + def initialize(app, *args) app.respond_to?(:root) or raise ArgumentError, "wrapped app #{app.inspect} does not respond to #root" @@ -139,8 +154,9 @@ def call(env) path_info_html = path_info_ue.split(%r{/}, -1).map! do |part| Rack::Utils.escape_html(part) end.join("/") - body = "Index of #{path_info_html}" \ - "

Index of #{path_info_html}


\n" \
+      body = "Index of #{path_info_html}" \
+             "" \
+             "

Index of #{path_info_html}


\n" \
              "#{dirs.concat(files).join("\n")}" \
              "

\n" h = { "Content-Type" => "text/html", "Content-Length" => body.size.to_s } -- EW