aboutsummaryrefslogtreecommitdiff
path: root/emacs/.emacs.d
diff options
context:
space:
mode:
authorYuchen Pei <id@ypei.org>2025-01-16 09:50:31 +1100
committerYuchen Pei <id@ypei.org>2025-01-16 09:50:31 +1100
commite7d07c825a29621cd1be7d787d5e1565bc3d3513 (patch)
treeddd1170ee525ed9a93ed067e08e1b72a860076fb /emacs/.emacs.d
parentd2c0eedeab4dc191eeb502af9edf589feb6633f3 (diff)
[emacs] web related
- fix browse-url-handlers - generalise fetch-and-browse flows
Diffstat (limited to 'emacs/.emacs.d')
-rw-r--r--emacs/.emacs.d/init/ycp-web.el4
-rw-r--r--emacs/.emacs.d/lisp/my/my-buffer.el2
-rw-r--r--emacs/.emacs.d/lisp/my/my-emms.el4
-rw-r--r--emacs/.emacs.d/lisp/my/my-net.el21
-rw-r--r--emacs/.emacs.d/lisp/my/my-web.el35
5 files changed, 44 insertions, 22 deletions
diff --git a/emacs/.emacs.d/init/ycp-web.el b/emacs/.emacs.d/init/ycp-web.el
index 9b0bf0d..f72c609 100644
--- a/emacs/.emacs.d/init/ycp-web.el
+++ b/emacs/.emacs.d/init/ycp-web.el
@@ -34,6 +34,8 @@
(ignore-errors (cancel-timer url-cookie-timer))
(setq shr-cookie-policy nil)
+(setq browse-url-handlers
+ '((stringp . browse-url-firefox)))
(my-package luwak
(:delay 10)
@@ -332,7 +334,7 @@
. ,(lambda (url &rest _) (my-open-newscorp-au url))))
(add-to-list 'browse-url-handlers
`("^https?://www.spectator.com.au\\>" .
- ,(lambda (url &rest args) (my-open-spectator-au url))))
+ ,(lambda (url &rest _) (my-fetch-browse-as-googlebot url))))
)
(add-to-list 'load-path (locate-user-emacs-file "lisp/servall/lisp"))
diff --git a/emacs/.emacs.d/lisp/my/my-buffer.el b/emacs/.emacs.d/lisp/my/my-buffer.el
index f2da7f5..a8683de 100644
--- a/emacs/.emacs.d/lisp/my/my-buffer.el
+++ b/emacs/.emacs.d/lisp/my/my-buffer.el
@@ -264,8 +264,6 @@ Focus write: make the current window the only one centered with
width 80. If in org-mode, also narrow to current subtree. Make
buffers on both sides empty read-only buffers."
(interactive)
- ;; Only one window in the current frame indicates we are in focus
- ;; write mode.
(if (and (equal
(buffer-name
(window-buffer (window-left (get-buffer-window))))
diff --git a/emacs/.emacs.d/lisp/my/my-emms.el b/emacs/.emacs.d/lisp/my/my-emms.el
index fd3c73d..6e8cf2a 100644
--- a/emacs/.emacs.d/lisp/my/my-emms.el
+++ b/emacs/.emacs.d/lisp/my/my-emms.el
@@ -509,7 +509,9 @@ character."
If the last command is `emms-playlist-mode-play-smart', then set
`my-emms-score-delta' to 2."
(when (eq last-command 'emms-playlist-mode-play-smart)
- (setq my-emms-score-delta 2)))
+ (setq my-emms-score-delta 2)
+ (setq last-command nil))
+ )
(defun my-emms-wrapped ()
"Print top 5 scored tracks."
diff --git a/emacs/.emacs.d/lisp/my/my-net.el b/emacs/.emacs.d/lisp/my/my-net.el
index 2574789..6212b50 100644
--- a/emacs/.emacs.d/lisp/my/my-net.el
+++ b/emacs/.emacs.d/lisp/my/my-net.el
@@ -30,11 +30,22 @@
;;; net utilities
(defvar my-download-dir "~/Downloads")
-(defun my-make-file-name-from-url (url)
- (file-name-nondirectory
- (directory-file-name
- (car (url-path-and-query (url-generic-parse-url
- (url-unhex-string url)))))))
+(defmacro my-url-as-googlebot (&rest body)
+ "Run BODY while spoofing as googlebot"
+ `(let ((url-request-extra-headers '(("X-Forwarded-For" . "66.249.66.1")))
+ (url-user-agent
+ "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"))
+ ,@body))
+
+(def-edebug-spec my-url-as-googlebot t)
+
+(defun my-make-file-name-from-url (url &optional extension)
+ (format "%s%s"
+ (file-name-nondirectory
+ (directory-file-name
+ (car (url-path-and-query (url-generic-parse-url
+ (url-unhex-string url))))))
+ (if extension (concat "." extension) "")))
;; stolen from `eww-make-unique-file-name'
(defun my-make-unique-file-name (file directory)
diff --git a/emacs/.emacs.d/lisp/my/my-web.el b/emacs/.emacs.d/lisp/my/my-web.el
index f2e48ba..472cab6 100644
--- a/emacs/.emacs.d/lisp/my/my-web.el
+++ b/emacs/.emacs.d/lisp/my/my-web.el
@@ -137,20 +137,29 @@
;;; webgetter
(require 'my-net)
-(defun my-open-spectator-au (url &optional no-overwrite)
- (interactive "sspectator.com.au link: ")
- (let ((url-request-extra-headers '(("X-Forwarded-For" . "66.249.66.1")))
- (url-user-agent "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"))
- (let ((file-name
- (if no-overwrite
- (my-make-unique-file-name
- (my-make-file-name-from-url url)
- my-download-dir)
- (expand-file-name
+(defun my-fetch-browse (url &optional no-overwrite)
+ "Fetch URL to a local file then browse it with firefox.
+
+Useful for bypassing \"Enable JavaScript and cookies to continue\"."
+ (interactive "sUrl to fetch and browse: ")
+ (let ((file-name
+ (if no-overwrite
+ (my-make-unique-file-name
(my-make-file-name-from-url url)
- my-download-dir))))
- (url-copy-file url file-name (not no-overwrite))
- (browse-url-firefox (format "file://%s" file-name)))))
+ my-download-dir)
+ (expand-file-name
+ (my-make-file-name-from-url url "html")
+ my-download-dir))))
+ (url-copy-file url file-name (not no-overwrite))
+ (browse-url-firefox (format "file://%s" file-name))))
+
+(defun my-fetch-browse-as-googlebot (url &optional no-overwrite)
+ "Same as `my-fetch-browse', but spoofing googlebot.
+
+Useful for bypassing some paywalls."
+ (interactive "sUrl to fetch and browse as googlebot: ")
+ (my-url-as-googlebot
+ (my-fetch-browse url no-overwrite)))
(defun my-mastodon-url-p (url)
"Guess if a url is a mastodon post.