Skip to content

Commit e5c8d16

Browse files
committed
Make adding user styles & scripts easier and implement simple dark mode
1 parent 56d6313 commit e5c8d16

9 files changed

+95
-49
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
webkitgtk-module.so
1+
*.so

README.org

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ about this).
216216

217217
;; Globally use a proxy
218218
(add-hook 'webkit-new-hook (lambda () (webkit-set-proxy "socks://localhost:8000")))
219+
220+
;; Globally use the simple dark mode
221+
(setq webkit-dark-mode t)
219222
#+end_src
220223

221224
I personally use evil so I've included ~evil-collection~ bindings which I hope
@@ -229,7 +232,6 @@ to upstream at some point when things stabilize.
229232
#+end_src
230233

231234
* TODO Roadmap (roughly in order of my priorities)
232-
- Dark mode
233235
- bookmarks.el
234236
- Ad block
235237
- Edit text areas in temp emacs buffer

dark-mode.css

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
*,div,pre,textarea,body,input,td,tr,p {
2+
background-color: #292b2e !important;
3+
/*background-image: none !important;*/
4+
color: #b2b2b2 !important;
5+
}
6+
h1,h2,h3,h4 {
7+
background-color: #303030 !important;
8+
color: #b8ddea !important;
9+
}
10+
a {
11+
color: #2aa1ae !important;
12+
}
13+
a:hover,a:focus {
14+
color: #7070e0 !important;
15+
}
16+
a:visited {
17+
color: #4f97d7 !important;
18+
}
19+
20+
/* for wikipedia's equations */
21+
img.mwe-math-fallback-image-inline {
22+
filter: invert(100%) !important;
23+
background-color: transparent !important;
24+
}
25+
26+
*[webkitviewhint^='hint']
27+
{
28+
all: initial !important;
29+
z-index: 2147483647;
30+
position:fixed !important;
31+
opacity: 0.7;
32+
border: 1px solid #2d2d2d !important;
33+
color: #2d2d2d !important;
34+
background-color: #f2f0ec !important;
35+
font: bold 20px monospace;
36+
margin: 0;
37+
padding: 0px 1px;
38+
}
39+
::selection {
40+
background: red;
41+
}

evil-collection-webkit.el

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ document.addEventListener('keydown', WKViewEvilKeyDown);
8787
"gg" 'webkit-scroll-top
8888
"G" 'webkit-scroll-bottom
8989
"y" 'webkit-copy-selection
90-
"Y" 'webkit-copy-url)
90+
"Y" 'webkit-copy-url
91+
"zd" 'webkit-dark-toggle)
9192

9293
(when evil-want-C-d-scroll
9394
(evil-collection-define-key 'normal 'webkit-mode-map

hints.css

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
*[webkitviewhint^='hint']
22
{
3-
all: initial;
3+
all: initial !important;
44
z-index: 2147483647;
55
position:fixed !important;
66
opacity: 0.7;
77
border:1px solid #444;
88
color: red;
99
background-color: yellow;
10-
/*
11-
font-family: monospace !important;
12-
font-size: 2em !important;
13-
*/
14-
font: bold 20px monospace !important;
10+
font: bold 20px monospace;
1511
margin: 0;
1612
padding: 0px 1px;
1713
}

script.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

style.css

Whitespace-only changes.

webkit-ace.el

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,20 @@
2727

2828
(require 'webkit)
2929

30+
(declare-function webkit-add-style "webkit")
31+
(declare-function webkit-add-script "webkit")
3032
(declare-function webkit--file-to-string "webkit")
3133
(declare-function webkit--execute-js "webkit-module")
3234
(declare-function webkit--focus "webkit-module")
33-
(declare-function webkit--add-user-script "webkit-module")
34-
(declare-function webkit--add-user-style "webkit-module")
3535

3636
(defconst webkit--base (file-name-directory load-file-name))
3737

3838
(defvar webkit--id)
3939

40-
(defvar webkit--hints-script
41-
(webkit--file-to-string
42-
(expand-file-name "hints.js" webkit--base)))
43-
(defvar webkit--hints-style
44-
(webkit--file-to-string
45-
(expand-file-name "hints.css" webkit--base)))
40+
(defvar webkit--hints-script (webkit--file-to-string
41+
(expand-file-name "hints.js" webkit--base)))
42+
(defvar webkit--hints-style (webkit--file-to-string
43+
(expand-file-name "hints.css" webkit--base)))
4644

4745
(defcustom webkit-ace-chars "asdfghjklweio"
4846
"Link hint characters."
@@ -66,9 +64,8 @@
6664
"webkit-ace--callback"))
6765

6866
(defun webkit-ace-init ()
69-
(webkit--add-user-script webkit--id webkit--hints-script)
70-
(webkit--add-user-style webkit--id webkit--hints-style)
71-
)
67+
(webkit-add-style webkit--hints-style)
68+
(webkit-add-script webkit--hints-script))
7269

7370
(add-hook 'webkit-new-hook #'webkit-ace-init)
7471
(define-key webkit-mode-map "o" 'webkit-ace)

webkit.el

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464

6565
(declare-function webkit-history-completing-read prompt "webkit-history")
6666

67-
(defconst webkit--base (file-name-directory load-file-name))
6867
(defconst webkit--user-dir (locate-user-emacs-file "webkit/"))
6968
(make-directory webkit--user-dir t)
7069

@@ -78,8 +77,8 @@
7877

7978
(defvar webkit--id)
8079
(defvar webkit--buffers)
81-
(defvar webkit--script)
82-
(defvar webkit--style)
80+
(defvar webkit--scripts)
81+
(defvar webkit--styles)
8382

8483
(defgroup webkit nil
8584
"The dynamic module webkit browser."
@@ -342,6 +341,40 @@ Seach is case sensitive if CASE is not nil."
342341
(interactive)
343342
(webkit--start-web-inspector (or webkit-id webkit--id)))
344343

344+
(defun webkit-set-styles (styles webkit-id)
345+
"Add all the strings of css scripts in the list STYLES to
346+
WEBKIT-ID while removing any previous styles."
347+
(webkit--remove-all-user-styles webkit-id)
348+
(dolist (style styles)
349+
(webkit--add-user-style webkit-id style)))
350+
351+
(defun webkit-set-scripts (scripts webkit-id)
352+
"Add all the strings of js scripts in the list SCRIPTS to
353+
WEBKIT-ID while removing any previous scripts."
354+
(webkit--remove-all-user-scripts webkit-id)
355+
(dolist (script scripts)
356+
(webkit--add-user-script webkit-id script)))
357+
358+
(defun webkit-add-style (style &optional webkit-id)
359+
"Add user css STYLE to webkit view."
360+
(push style webkit--styles)
361+
(webkit-set-styles webkit--styles (or webkit-id webkit--id)))
362+
363+
(defun webkit-add-script (script &optional webkit-id)
364+
"Add user js SCRIPT to webkit view."
365+
(push script webkit--scripts)
366+
(webkit-set-scripts webkit--scripts (or webkit-id webkit--id)))
367+
368+
(defun webkit-remove-style (style &optional webkit-id)
369+
"Remove user css STYLE frome webkit view."
370+
(setq webkit--styles (delq style webkit--styles))
371+
(webkit-set-styles webkit--styles (or webkit-id webkit--id)))
372+
373+
(defun webkit-remove-script (script &optional webkit-id)
374+
"Remove user js SCRIPT frome webkit view."
375+
(setq webkit--scripts (delq script webkit--scripts))
376+
(webkit-set-scripts webkit--scripts (or webkit-id webkit--id)))
377+
345378
(defun webkit-enable-javascript (&optional enable webkit-id)
346379
"Enable external javascript execution if ENABLE is not nil and
347380
disable it otherwise."
@@ -637,12 +670,10 @@ the default webkit buffer."
637670
;;`webkit-own-window' must be set to desired value before this is called."
638671

639672
(make-variable-buffer-local 'webkit--id)
673+
(make-variable-buffer-local 'webkit--scripts)
674+
(make-variable-buffer-local 'webkit--styles)
640675
(setq webkit--buffers nil)
641676

642-
(setq webkit--script (webkit--file-to-string
643-
(expand-file-name "script.js" webkit--base)))
644-
(setq webkit--style (webkit--file-to-string
645-
(expand-file-name "style.css" webkit--base)))
646677
(unless webkit-own-window
647678
(add-hook 'window-size-change-functions #'webkit--adjust-size)
648679
(add-hook 'delete-frame-functions #'webkit--delete-frame))

0 commit comments

Comments
 (0)