├── COPYING ├── README.org ├── nx-dark-reader.asd ├── nx-dark-reader.lisp └── package.lisp /COPYING: -------------------------------------------------------------------------------- 1 | BSD 2-Clause License 2 | 3 | Copyright (c) 2022, Artyom Bologov 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /README.org: -------------------------------------------------------------------------------- 1 | #+TITLE:Dark Reader in Nyxt! 2 | 3 | This integrates the code behind the [[https://github.com/darkreader/darkreader][Dark Reader]] Chrome/Firefox extension with Nyxt. 4 | 5 | * Getting Started 6 | BEWARE: it doesn't work on Nyxt 2.*, as the APIs used belong to the 3.0 release and are only available on current master. 7 | 8 | First, clone this repository: 9 | #+begin_src sh 10 | # ~/.local/share/nyxt/extensions/nx-dark-reader is the extensions path. 11 | # Change if you set it to a different value. 12 | git clone https://github.com/aartaka/nx-dark-reader.git ~/.local/share/nyxt/extensions/nx-dark-reader 13 | #+end_src 14 | 15 | Then load it in your init file: 16 | 17 | #+begin_src lisp 18 | ;;; ~/.config/nyxt/config.lisp 19 | (define-nyxt-user-system-and-load "nyxt-user/dark-reader" 20 | ;; Remove this line if you don't need the file. 21 | :components ("dark-reader.lisp") 22 | :depends-on (:nx-dark-reader)) 23 | #+end_src 24 | 25 | Optionally, configure it and add it to your =default-modes= in =dark-reader.lisp= (create the file if necessary). 26 | 27 | #+begin_src lisp 28 | ;;; ~/.config/nyxt/dark-reader.lisp 29 | (define-configuration nx-dark-reader:dark-reader-mode 30 | ;; Note the nxdr: short package prefix. It's for your convenience :) 31 | ((nxdr:brightness 80) 32 | (nxdr:contrast 60) 33 | (nxdr:text-color "white"))) 34 | 35 | ;; Add dark-reader to default modes 36 | (define-configuration web-buffer 37 | ((default-modes `(nxdr:dark-reader-mode ,@%slot-value%)))) 38 | #+end_src 39 | 40 | And you're all set! Enjoy your Dark Reader theme :) 41 | -------------------------------------------------------------------------------- /nx-dark-reader.asd: -------------------------------------------------------------------------------- 1 | ;;;; nx-dark-reader.asd 2 | 3 | (asdf:defsystem #:nx-dark-reader 4 | :description "DarkReader integration for Nyxt 3.0." 5 | :author "Artyom Bologov" 6 | :license "BSD 2-Clause" 7 | :version "0.0.1" 8 | :serial t 9 | :depends-on (#:nyxt) 10 | :components ((:file "package") 11 | (:file "nx-dark-reader"))) 12 | -------------------------------------------------------------------------------- /nx-dark-reader.lisp: -------------------------------------------------------------------------------- 1 | ;;;; nx-dark-reader.lisp 2 | 3 | (in-package #:nx-dark-reader) 4 | 5 | (nyxt::define-mode dark-reader-mode () 6 | "A mode to load Dark Reader script and run it on the page. 7 | 8 | For the explanation of `brightness', `contrast', `grayscale', `sepia', `background-color', 9 | `text-color', `selection-color', `use-font', `font-family', `text-stroke', `stylesheet' 10 | see Dark Reader docs and examples. The default values are mostly sensible, though." 11 | ((glyph "Δ") 12 | (script nil) 13 | (brightness 14 | 100 15 | :type integer) 16 | (contrast 17 | 100 18 | :type integer) 19 | (grayscale 20 | 0 21 | :type integer) 22 | (sepia 23 | 0 24 | :type integer) 25 | (background-color 26 | nil 27 | :type (or null string)) 28 | (text-color 29 | nil 30 | :type (or null string)) 31 | (selection-color 32 | nil 33 | :type (or null string)) 34 | (use-font 35 | nil 36 | :type boolean) 37 | (font-family 38 | nil 39 | :type (or null string)) 40 | (text-stroke 41 | nil 42 | :type (or null integer)) 43 | (stylesheet 44 | nil 45 | :type (or null string)))) 46 | 47 | (defmethod enable ((mode dark-reader-mode) &key) 48 | (let ((dark-reader 49 | (make-instance 50 | 'nyxt/mode/user-script:user-script 51 | :code (with-slots (brightness contrast grayscale sepia 52 | background-color text-color selection-color 53 | use-font font-family text-stroke 54 | stylesheet) 55 | mode 56 | (format nil "// ==UserScript== 57 | // @name Dark Reader (Unofficial) 58 | // @icon https://darkreader.org/images/darkreader-icon-256x256.png 59 | // @namespace DarkReader 60 | // @description Inverts the brightness of pages to reduce eye strain 61 | // @version 4.7.15 62 | // @author https://github.com/darkreader/darkreader#contributors 63 | // @homepageURL https://darkreader.org/ | https://github.com/darkreader/darkreader 64 | // @run-at document-end 65 | // @include http://*/* 66 | // @include https://*/* 67 | // @grant none 68 | // @require https://cdn.jsdelivr.net/npm/darkreader/darkreader.min.js 69 | // @noframes 70 | // ==/UserScript== 71 | 72 | DarkReader.setFetchMethod(window.fetch); 73 | DarkReader.enable({ 74 | brightness: ~d, 75 | contrast: ~d, 76 | grayscale: ~d, 77 | sepia: ~d, 78 | ~:[~;darkSchemeBackgroundColor: ~s,~] 79 | ~:[~;darkSchemeTextColor: ~s,~] 80 | ~:[~;selectionColor: ~s,~] 81 | ~:[~*~;useFont: true, fontFamily: ~s,~] 82 | ~:[~;textStroke: ~d,~] 83 | ~:[~;stylesheet: ~s,~] 84 | });" brightness contrast grayscale sepia 85 | background-color background-color 86 | text-color text-color 87 | selection-color selection-color 88 | use-font font-family 89 | text-stroke text-stroke 90 | stylesheet stylesheet))))) 91 | (ffi-buffer-add-user-script (buffer mode) (setf (script mode) dark-reader)))) 92 | 93 | (defmethod disable ((mode dark-reader-mode) &key) 94 | (ffi-buffer-remove-user-script (buffer mode) (script mode))) 95 | -------------------------------------------------------------------------------- /package.lisp: -------------------------------------------------------------------------------- 1 | ;;;; package.lisp 2 | 3 | (nyxt:define-package #:nx-dark-reader 4 | (:nicknames #:nxdr) 5 | (:use #:cl #:nyxt)) 6 | --------------------------------------------------------------------------------