emacs-detubifier

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 76244b511d78c7ba01023abedd06822548f165aa
parent 8dbe403874234664e08e38e2516fb72c5b517a9c
Author: Yuval Langer <yuval.langer@gmail.com>
Date:   Thu, 26 Sep 2024 21:06:11 +0300

Adding more commands and functions.  I am sorry.

Diffstat:
Mdetubifier.el | 67++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 60 insertions(+), 7 deletions(-)

diff --git a/detubifier.el b/detubifier.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2024 Yuval Langer ;; Author: Yuval Langer <yuval.langer@gmail.com> -;; Version: 0.0.0 +;; Version: 0.1.0 ;; Keywords: web, youtube ;; URL: https://codebarg.org/kakafarm/emacs-detubifier-mode/ @@ -40,13 +40,65 @@ ;;; Code: (defcustom detubifier-regexp-replacement-pairs - '(("www\\.youtube\\.com" . "invidious.jing.rocks") - ("youtube\\.com" . "invidious.jing.rocks") - ("youtu\\.be/" . "invidious.jing.rocks/watch?v=") - ("twitter.com" . "nitter.poast.org")) + `((,(rx "www.youtube.com") . "invidious.jing.rocks") + (,(rx "youtube.com") . "invidious.jing.rocks") + (,(rx "youtu.be") . "invidious.jing.rocks/watch?v=") + (,(rx "twitter.com") . "nitter.poast.org") + (,(rx "x.com") . "https://farside.link/")) "List of pairs, each with a regexp and its replacement." :type '(list (cons regexp string)) - :group 'detubifier) + :group 'detubifier + ) + +(defcustom detubifier-farside-url + "https://farside.link/" + "Base address to the farside service." + :type 'url + :group 'detubifier + ) + +(defcustom detubifier-detubifying-method + 'farside + "Method of detubifying." + :type '(radio farside custom) + :group 'detubifier + ) + +(defcustom detubifier-enshittified-urls + '( + "www.youtube.com" + "youtube.com" + "youtu.be" + "twitter.com" + "x.com" + ) + "URLs of enshittified services." + :type '(repeat string) + :group 'detubifier + ) + +(defun detubifier-farsidify-string (str) + "Replace enshittified URLs in string `STR' with nonenshittified farside.link." + (rx-let-eval `((urls () (group (or ,@detubifier-enshittified-urls)))) + (replace-regexp-in-string (rx-to-string '(urls)) + (concat detubifier-farside-url "\\1") + s)) + ) + +(defun detubifier-farsidify-region () + "Replace enshittified URLs with " + (interactive) + + (save-excursion + (save-restriction ;; Save narrowing setting and revert to it when finishing. + (narrow-to-region (mark) (point)) + (rx-let-eval `((urls () (group (or ,@detubifier-enshittified-urls)))) + (message (rx-to-string '(urls))) + (replace-regexp-in-region (rx-to-string '(urls)) + (concat detubifier-farside-url "\\1") + (mark) + (point))))) + ) (defun detubifier-browse-url (url &rest args) "Open using `browse-url', but with the usual suspects replaced as defined in `detubifier-regexp-replacement-pairs'." @@ -90,7 +142,8 @@ (goto-char (point-min)) (while (re-search-forward current-regexp nil t) (replace-match current-replacement nil nil))))) - (kill-region (point-min) (point-max))))) + (kill-region (point-min) (point-max)))) + ) (define-obsolete-function-alias 'detubifier-replace-contents