diff --git a/user/qutebrowser/colors.nix b/user/qutebrowser/colors.nix index 71afa4f..3a90888 100644 --- a/user/qutebrowser/colors.nix +++ b/user/qutebrowser/colors.nix @@ -158,75 +158,20 @@ in # Dark theme ######################################################## - webpage = lib.mkIf (color.type == "dark") { - bg = color.bg; - preferred_color_scheme = "dark"; - darkmode = { - enabled = false; - threshold = { - text = 150; - background = 205; - }; - }; - }; + # webpage = lib.mkIf (color.type == "dark") { + # bg = color.bg; + # preferred_color_scheme = "dark"; + # darkmode = { + # enabled = false; + # threshold = { + # text = 150; + # background = 205; + # }; + # }; + # }; }; }; home.file = { - # For some stupid reason qutebrowser crashes if this dir does not exist - ".config/qutebrowser/greasemonkey/darkreader.js".text = '' - // ==UserScript== - // @name Dark Reader (Unofficial) - // @icon https://darkreader.org/images/darkreader-icon-256x256.png - // @namespace DarkReader - // @description Inverts the brightness of pages to reduce eye strain - // @version 4.7.15 - // @author https://github.com/darkreader/darkreader#contributors - // @homepageURL https://darkreader.org/ | https://github.com/darkreader/darkreader - // @run-at document-end - // @grant none - // @include http* - // @require https://cdn.jsdelivr.net/npm/darkreader/darkreader.min.js - // @noframes - // ==/UserScript== - - DarkReader.setFetchMethod(window.fetch) - - if ("${color.type}" != "dark") { - DarkReader.disable(); - return; - } - - const ignore_list = [ - "askubuntu.com", - "mathoverflow.com", - "mathoverflow.net", - "serverfault.com", - "stackapps.com", - "stackexchange.com", - "stackoverflow.com", - "superuser.com", - "hub.docker.com", - ]; - - for (let item of ignore_list) { - if (window.location.origin.indexOf(item) >= 0) { - console.log("URL matched dark-mode ignore list"); - return; - } - } - - DarkReader.enable({ - brightness: 100, - contrast: 100, - sepia: 0, - - darkSchemeBackgroundColor: "${color.bg}", - darkSchemeTextColor: "${color.txt}", - - lightSchemeBackgroundColor: "${color.bg}", - lightSchemeTextColor: "${color.txt}", - }); - ''; ".config/qutebrowser/style.css".text = '' ${lib.optionalString (color.type == "dark") '' button, diff --git a/user/qutebrowser/dark-theme.nix b/user/qutebrowser/dark-theme.nix new file mode 100644 index 0000000..a596251 --- /dev/null +++ b/user/qutebrowser/dark-theme.nix @@ -0,0 +1,90 @@ +{ config, pkgs, lib, font, ... }: +let + inherit (pkgs.uservars) theme; + inherit (theme) color; + + # ".config/qutebrowser/greasemonkey/darkreader.js".text = + darkThemeUserscript = enabled: pkgs.writeText "darkreader.js" '' + // ==UserScript== + // @name Dark Reader (Unofficial) + // @icon https://darkreader.org/images/darkreader-icon-256x256.png + // @namespace DarkReader + // @description Inverts the brightness of pages to reduce eye strain + // @version 4.7.15 + // @author https://github.com/darkreader/darkreader#contributors + // @homepageURL https://darkreader.org/ | https://github.com/darkreader/darkreader + // @run-at document-end + // @grant none + // @include http* + // @require https://cdn.jsdelivr.net/npm/darkreader/darkreader.min.js + // @noframes + // ==/UserScript== + + DarkReader.setFetchMethod(window.fetch) + + if (${if enabled then "false" else "true"}) { + DarkReader.disable(); + return; + } + + const ignore_list = [ + "askubuntu.com", + "mathoverflow.com", + "mathoverflow.net", + "serverfault.com", + "stackapps.com", + "stackexchange.com", + "stackoverflow.com", + "superuser.com", + "hub.docker.com", + ]; + + for (let item of ignore_list) { + if (window.location.origin.indexOf(item) >= 0) { + console.log("URL matched dark-mode ignore list"); + return; + } + } + + DarkReader.enable({ + brightness: 100, + contrast: 100, + sepia: 0, + + darkSchemeBackgroundColor: "${color.bg}", + darkSchemeTextColor: "${color.txt}", + + lightSchemeBackgroundColor: "${color.bg}", + lightSchemeTextColor: "${color.txt}", + }); + ''; +in +{ + programs.qutebrowser.keyBindings = { + normal = { + "K" = "spawn --userscript toggle-dark-theme"; + }; + }; + home.file = { + ".local/share/qutebrowser/userscripts/toggle-dark-theme".executable = true; + ".local/share/qutebrowser/userscripts/toggle-dark-theme".text = '' + #!/bin/sh + DARK_READER_SCRIPT="$HOME/.config/qutebrowser/greasemonkey/darkreader.js" + MARKER="$HOME/.config/qutebrowser/is-dark-mode" + if test -f "$MARKER" + then + rm -f "$MARKER" + cp -f ${darkThemeUserscript false} "$DARK_READER_SCRIPT" + echo "jseval --world main DarkReader.disable()" >> "$QUTE_FIFO" + else + touch "$MARKER" + cp -f ${darkThemeUserscript true} "$DARK_READER_SCRIPT" + echo "jseval --world main DarkReader.enable()" >> "$QUTE_FIFO" + fi + if test -n "$QUTE_FIFO"; then + echo "greasemonkey-reload --quiet" >> "$QUTE_FIFO" + fi + ''; + }; +} + diff --git a/user/qutebrowser/default.nix b/user/qutebrowser/default.nix index 00f73be..467340b 100644 --- a/user/qutebrowser/default.nix +++ b/user/qutebrowser/default.nix @@ -1,10 +1,11 @@ { config, pkgs, lib, font, ... }: let - inherit (pkgs.uservars) key font browser editor; + inherit (pkgs.uservars) key browser editor; in { imports = [ ./colors.nix + ./dark-theme.nix ./fonts.nix ]; @@ -43,7 +44,7 @@ in "co" = "tab-only --pinned keep"; - "K" = "jseval --world main if (DarkReader.isEnabled()) {DarkReader.disable()} else {DarkReader.enable()}"; + # "K" = "jseval --world main if (DarkReader.isEnabled()) {DarkReader.disable()} else {DarkReader.enable()}"; }; insert = { # quit insert mode diff --git a/user/qutebrowser/fonts.nix b/user/qutebrowser/fonts.nix index 4e95517..e6eee6b 100644 --- a/user/qutebrowser/fonts.nix +++ b/user/qutebrowser/fonts.nix @@ -23,9 +23,9 @@ in category = BIG_INTER; }; messages = { - error = BIG_INTER; - info = BIG_INTER; - warning = BIG_INTER; + error = DEF_INTER; + info = DEF_INTER; + warning = DEF_INTER; }; tabs = { selected = BIG_INTER;