aboutsummaryrefslogtreecommitdiff
path: root/emacs/.emacs.d/init/ycp-web.el
blob: b1e546c907d8d74c19d99b3c8bde2e1d37e53cff (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
;;; ycp-web.el -- My config for web related -*- lexical-binding: t -*-

;; Copyright (C) 2023 Free Software Foundation.

;; Author: Yuchen Pei <id@ypei.org>
;; Package-Requires: ((emacs "28.2"))

;; This file is part of dotfiles.

;; dotfiles is free software: you can redistribute it and/or modify it under
;; the terms of the GNU Affero General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; dotfiles is distributed in the hope that it will be useful, but WITHOUT
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
;; or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General
;; Public License for more details.

;; You should have received a copy of the GNU Affero General Public
;; License along with dotfiles.  If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:

;; My config for web related. Covers cookies, web browsing, clients to
;; web services like osm and openlibrary

;;; Code:



;; disable cookies
(setq url-cookie-untrusted-urls ".*")
(ignore-errors (cancel-timer url-cookie-timer))

(setq shr-cookie-policy nil)

(my-package luwak
  (:delay 10)
  (:install t)
  (require 'luwak-org)
  (require 'my-utils)
  (setq luwak-url-rewrite-function 'url-rw)
  (setq luwak-tor-switch t)
  )

;;; openlibrary
(my-package my-openlibrary
  (:delay 15))

(my-package osm
  (:install t)
  (:delay 30)
  (require 'my-osm)
  (my-keybind osm-mode-map
    "C-<left>" nil
    "C-<right>" nil
    "C-<up>" nil
    "C-<down>" nil
    "c" #'my-osm-show-center)
  )

(my-package bom
  (:delay 30))

(my-package url-rewrite
  (setq my-nitter-hosts
        '("nitter.net"
          "nitter.nixnet.services"
          "nitter.unixfox.eu"
          "nitter.mint.lgbt"
          "nitter.esmailelbob.xyz"
          "nitter.poast.org"
          "nitter.cz"
          "nitter.privacydev.net"
          "nitter.projectsegfau.lt"
          "nitter.eu.projectsegfau.lt"
          "nitter.in.projectsegfau.lt"
          "nitter.us.projectsegfau.lt"
          "nitter.soopy.moe"
          "nitter.rawbit.ninja"
          "nitter.d420.de"
          "bird.habedieeh.re"
          "nitter.x86-64-unknown-linux-gnu.zip"
          "nitter.woodland.cafe"
          "nitter.dafriser.be"
          "nitter.catsarch.com"
          "nitter.perennialte.ch"
          "nitter.salastil.com"
          "n.populas.no"
          "nt.ggtyler.dev"
          "nitter.uni-sonia.com"
          "n.opnxng.com"
          "nitter.ktachibana.party"
          "nitter.tinfoil-hat.net"))
  (setq my-invidious-hosts
        '("yewtu.be"
          "invidious.io.lol"
          "invidious.slipfox.xyz"
          "invidious.drgns.space"
          "invidious.protokolla.fi"
          "invidious.flokinet.to"
          "iv.ggtyler.dev"
          "yt.drgnz.club"
          "invidious.lunar.icu"
          "invidious.private.coffee"
          "invidious.fdn.fr"
          "vid.puffyan.us"
          "invidious.asir.dev"
          "onion.tube"
          "iv.melmac.space"
          "invidious.projectsegfau.lt"
          "inv.in.projectsegfau.lt"
          "invidious.privacydev.net"
          "iv.datura.network"
          "inv.tux.pizza"
          "iv.nboeck.de"
          "invidious.perennialte.ch"
          "yt.oelrichsgarcia.de"
          "inv.citw.lgbt"
          "inv.zzls.xyz"
          "invidious.einfachzocken.eu"
          "yt.cdaut.de"
          "yt.artemislena.eu"
          "vid.priv.au"
          "anontube.lvkaszus.pl"
          "invidious.no-logs.com"))
  (setq url-rw-rules
        '((:name ddg-result
                 :description "duckduckgo result transform."
                 :match (concat url-rw-www-re (rx "duckduckgo.com/l/?uddg="))
                 :actions ((replace-by-redirect "uddg")))
          (:name google-docs-odt
                 :description "Download Google docs document as odt."
                 :match (concat url-rw-www-re (rx "docs.google.com/document/d/"))
                 :actions ((replace-path-regexp "\\(/document/d/.*?\\)/.*"
                                                "\\1/export")
                           (put-query "format" "odt")))
          (:name google-slides-odp
                 :description "Download Google slides as odp."
                 :match (concat url-rw-www-re
                                (rx "docs.google.com/presentation/d/"))
                 :actions ((replace-path-regexp "\\(/document/d/.*?\\)/.*"
                                                "\\1/export")
                           (put-query "format" "odp")))
          (:name google-to-ddg
                 :description "Google search to duckduckgo html."
                 :match (concat url-rw-www-re (rx "google.com/search?q="))
                 :actions ((replace-host "html.duckduckgo.com")
                           (replace-path "/html")))
          (:name reddit-to-old
                 :description "Reddit to old Reddit"
                 :match (concat url-rw-www-re (rx "reddit.com"))
                 :actions ((replace-host "old.reddit.com")))
          (:name strip-utm
                 :description "Strip utm_* queries."
                 :match "\\<utm_[a-z_]+="
                 :actions ((remove-query "utm_.*")))
          (:name strip-fbclid
                 :description "Strip utm_* queries."
                 :match "\\<fbclid="
                 :actions ((remove-query "fbclid")))
          (:name twitter-to-nitter
                 :description "Xitter to a random nitter instance."
                 :match (concat url-rw-www-re (rx "twitter.com"))
                 :actions ((replace-random-host my-nitter-hosts)))
          (:name twitter-to-nitter
                 :description "Xitter to a random nitter instance."
                 :match (concat url-rw-www-re (rx "x.com"))
                 :actions ((replace-random-host my-nitter-hosts)))
          (:name youtube-to-invidious
                 :description "YouTube to a random invidious instance."
                 :match (concat url-rw-www-re (rx (or "youtube.com"
                                                      "youtu.be"
                                                      "m.youtube.com")))
                 :actions ((replace-random-host my-invidious-hosts)))))
  (setq url-rw-extra-rewriters '(url-rewrite-example-zoom-to-dial))
  (url-rw-refresh)
  )

(my-package hnreader
  (:delay 30)
  (require 'my-hnreader)
  (my-override hnreader--print-frontpage)
  (my-override hnreader--print-frontpage-item)
  (my-override hnreader--print-comments)
  (my-override hnreader--get-title))

(add-to-list 'load-path (locate-user-emacs-file "lisp/lem.el/lisp"))
(my-package lem-org
  (:delay 30))

(my-package buildbot
  (:delay 30)
  (setq buildbot-default-host "https://buildbot.mariadb.org")
  (setq buildbot-api-changes-direct-filter t)
  )

(my-package org-jira
  (:delay 30)
  (my-setq-from-local jiralib-url
                      org-jira-priority-to-org-priority-alist
                      org-jira-jira-status-to-org-keyword-alist
                      org-jira-project-filename-alist
                      org-jira-custom-jqls)
  (require 'my-org-jira)
  (my-override org-jira--render-issue)
  (my-override org-jira-update-worklogs-from-org-clocks)
  (my-keybind org-jira-entry-mode-map "C-c ig" 'org-jira-get-issue)
  ;; `org-jira-mode' displays many whitespace-only lines in comments
  ;; it pulls.
  (add-hook 'org-jira-mode-hook
            (lambda () (setq show-trailing-whitespace nil)))
  (add-hook 'org-jira-mode-hook
            'turn-off-auto-fill)
  (add-hook 'org-jira-mode-hook
            'turn-off-flyspell)
  )

(my-package eww
  (:delay 60)
  (advice-add 'eww-browse-url :filter-args #'my-rewrite-url-advice)
  (advice-add 'eww :filter-args #'my-rewrite-url-advice)
  (setq eww-restore-desktop t)
  (require 'my-utils)
  (setq eww-download-directory my-incoming-dir)
  (setq eww-bookmarks-directory (locate-user-emacs-file "eww-bookmarks"))
  (setq eww-history-limit 150)
  (setq eww-use-external-browser-for-content-type
        "\\`\\(video/\\|audio\\)") ; On GNU/Linux check your mimeapps.list
  (setq eww-browse-url-new-window-is-tab nil)
  (my-keybind eww-link-keymap "v" nil) ; stop overriding `eww-view-source'
  (my-keybind eww-mode-map
    "L" #'eww-list-bookmarks
    "o" #'eww)
  (my-keybind eww-bookmark-mode-map "d" #'eww-bookmark-kill)
  )

(my-package my-web
  (:delay 60)
  (my-keybind eww-mode-map
    "N" #'my-eww-next-path
    "P" #'my-eww-prev-path
    "U" #'my-eww-up-path
    "T" #'my-eww-top-path
    "b" #'my-eww-switch-by-title)
  (my-keybind global-map "\C-c\C-o" #'my-browse-url-at-point)
  (my-override browse-url)
  )

(my-package my-semantic-scholar
  (:delay 60))

(my-package rt-liberation
  (:delay 60)
  (:install t)
  (my-setq-from-local rt-liber-username rt-liber-rest-url
                      rt-liber-base-url)
  (require 'my-rtliber)
  (my-override rt-liber-viewer-visit-in-browser)
)

(my-package rt-liberation-org
  (:delay 60))

(my-package rt-liberation-gnus
  (:delay 60)
  (my-setq-from-local rt-liber-gnus-address
                      rt-liber-gnus-comment-address
                      rt-liber-gnus-subject-name)
  (require 'my-rtliber)
  (my-keybind global-map
    "C-c t m" #'my-rt-liber-my-open-tickets
    "C-c t M" #'my-rt-liber-my-tickets
    "C-c t b" #'my-rt-liber-backlog
    "C-c t i" #'my-rt-liber-get-ticket-by-id
    "C-c t q" #'my-rt-liber-query-by-subject)
  )

;; sx: a stack exchange client
(my-package sx
  (:delay 60)
  (require 'sx-load))

;; mastodon.el
(add-to-list 'load-path (locate-user-emacs-file "lisp/mastodon.el/lisp"))
(my-package mastodon
  (my-setq-from-local mastodon-active-user mastodon-instance-url)
  ;; auto fill is a bit glitchy when composing a toot
  (add-hook 'mastodon-toot-mode-hook (lambda () (turn-off-auto-fill)))
  (mastodon))

(my-package mastorg
  (:delay 60))

(add-to-list 'load-path (locate-user-emacs-file "lisp/servall/lisp"))
(my-package servall-wikipedia
  (:delay 60)
  (require 'servall-ytdl)
  (my-setq-from-local servall-endpoint)
  (require 'my-servall)
  (my-keybind servall-wikipedia-view-mode-map "C-'" 'my-servall-wikipedia-grok)
)

(my-package my-libgen
  (:delay 60)
  (require 'my-utils)
  (my-setq-from-local my-libgen-hosts my-libgen-alt-hosts
                      my-libgen-library-hosts my-libgen-onion-host
                      )
  (setq my-libgen-download-dir my-document-incoming-dir)
  (my-libgen-set-random-hosts))

(my-package my-scihub
  (:delay 60)
  (my-setq-from-local my-scihub-host))

(my-package w3m
  (:delay 60)
  (my-keybind w3m-mode-map
    "o" #'w3m-browse-url
    "n" #'scroll-up-line
    "p" #'scroll-down-line
    "w" #'w3m-print-this-url
    "l" #'w3m-view-previous-page
    "r" #'w3m-view-next-page
    "g" #'w3m-reload-this-page
    )
  (require 'w3m-load))

(my-package exitter
  (:delay 60)
  (my-setq-from-local
   exitter-oauth-consumer-key exitter-oauth-consumer-secret
   exitter-access-token exitter-username exitter-password exitter-email
   exitter-oauth-token exitter-oauth-token-secret exitter-oauth-token-ctime)
  (setq exitter-debug t)
  )

(provide 'ycp-web)