Add new user option eww-url-transformers
* doc/misc/eww.texi (Advanced): Document it. * lisp/net/eww.el (eww-url-transformers): New user option. (eww-remove-tracking): New default function. (eww--transform-url): Helper function. (eww-follow-link): Use it. (eww): Ditto.
This commit is contained in:
parent
9d54b1222c
commit
55fa6a2655
3 changed files with 38 additions and 2 deletions
|
@ -388,6 +388,15 @@ EWW buffers will be renamed after rendering a document. If this is
|
|||
can also be a user-defined function, which is called with no
|
||||
parameters in the EWW buffer, and should return a string.
|
||||
|
||||
@cindex utm
|
||||
@vindex eww-url-transformers
|
||||
EWW runs the URLs through @code{eww-url-transformers} before using
|
||||
them. This user option is a list of functions, where each function is
|
||||
called with the URL as the parameter, and should return the (possibly)
|
||||
transformed URL. By default, this variable contains
|
||||
@code{eww-remove-tracking}, which removes the common @samp{utm_}
|
||||
trackers from links.
|
||||
|
||||
@node Command Line
|
||||
@chapter Command Line Usage
|
||||
|
||||
|
|
7
etc/NEWS
7
etc/NEWS
|
@ -222,6 +222,13 @@ If non-nil, 'C-c C-a' will put attached files at the end of the message.
|
|||
---
|
||||
*** HTML Mode now supports text/html and image/* yanking.
|
||||
|
||||
** eww
|
||||
|
||||
+++
|
||||
*** New user option 'eww-url-transformers'.
|
||||
These are used to alter an URL before using it. By default it removes
|
||||
the common utm_ trackers from URLs.
|
||||
|
||||
** Gnus
|
||||
|
||||
+++
|
||||
|
|
|
@ -231,6 +231,13 @@ See also `eww-form-checkbox-selected-symbol'."
|
|||
(const "☐") ; Unicode BALLOT BOX
|
||||
string))
|
||||
|
||||
(defcustom eww-url-transformers '(eww-remove-tracking)
|
||||
"This is a list of transforming functions applied to an URL before usage.
|
||||
The functions will be called with the URL as the single
|
||||
parameter, and should return the (possibly) transformed URL."
|
||||
:type '(repeat function)
|
||||
:version "29.1")
|
||||
|
||||
(defface eww-form-submit
|
||||
'((((type x w32 ns) (class color)) ; Like default mode line
|
||||
:box (:line-width 2 :style released-button)
|
||||
|
@ -385,6 +392,7 @@ killed after rendering."
|
|||
(while (string-match "\\`/[.][.]/" (url-filename parsed))
|
||||
(setf (url-filename parsed) (substring (url-filename parsed) 3))))
|
||||
(setq url (url-recreate-url parsed)))
|
||||
(setq url (eww--transform-url url))
|
||||
(plist-put eww-data :url url)
|
||||
(plist-put eww-data :title "")
|
||||
(eww--after-page-change)
|
||||
|
@ -1831,6 +1839,17 @@ The browser to used is specified by the
|
|||
(funcall browse-url-secondary-browser-function
|
||||
(or url (plist-get eww-data :url))))
|
||||
|
||||
(defun eww-remove-tracking (url)
|
||||
"Remove the commong utm_ tracking cookies from URLs."
|
||||
(replace-regexp-in-string ".utm_.*" "" url))
|
||||
|
||||
(defun eww--transform-url (url)
|
||||
"Appy `eww-url-transformers'."
|
||||
(when url
|
||||
(dolist (func eww-url-transformers)
|
||||
(setq url (funcall func url)))
|
||||
url))
|
||||
|
||||
(defun eww-follow-link (&optional external mouse-event)
|
||||
"Browse the URL under point.
|
||||
If EXTERNAL is single prefix, browse the URL using
|
||||
|
@ -1841,7 +1860,8 @@ If EXTERNAL is double prefix, browse in new buffer."
|
|||
(list current-prefix-arg last-nonmenu-event)
|
||||
eww-mode)
|
||||
(mouse-set-point mouse-event)
|
||||
(let ((url (get-text-property (point) 'shr-url)))
|
||||
(let* ((orig-url (get-text-property (point) 'shr-url))
|
||||
(url (eww--transform-url orig-url)))
|
||||
(cond
|
||||
((not url)
|
||||
(message "No link under point"))
|
||||
|
@ -1860,7 +1880,7 @@ If EXTERNAL is double prefix, browse in new buffer."
|
|||
(plist-put eww-data :url url)
|
||||
(eww-display-html 'utf-8 url dom nil (current-buffer))))
|
||||
(t
|
||||
(eww-browse-url url external)))))
|
||||
(eww-browse-url orig-url external)))))
|
||||
|
||||
(defun eww-same-page-p (url1 url2)
|
||||
"Return non-nil if URL1 and URL2 represent the same page.
|
||||
|
|
Loading…
Add table
Reference in a new issue